Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java

Issue 1750963002: Update demo with features from support lib 23.2.0 (Closed) Base URL: https://chromium.googlesource.com/external/github.com/GoogleChrome/custom-tabs-client@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java
diff --git a/demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java b/demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java
new file mode 100644
index 0000000000000000000000000000000000000000..d5cbb3f5704adb588458b96a5dc5a2d0d6ba52b5
--- /dev/null
+++ b/demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java
@@ -0,0 +1,53 @@
+// Copyright 2015 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.chromium.customtabsdemos;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+/**
+ * A BroadcastReceiver that handles the Action Intent from the Custom Tab and shows the Url
+ * in a Toast.
+ */
+public class ActionBroadcastReceiver extends BroadcastReceiver {
+ public static final String KEY_ACTION_SOURCE = "org.chromium.customtabsdemos.ACTION_SOURCE";
+ public static final int ACTION_ACTION_BUTTON = 1;
+ public static final int ACTION_MENU_ITEM = 2;
+ public static final int ACTION_TOOLBAR = 3;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String url = intent.getDataString();
+ if (url != null) {
+ String toastText = getToastText(context, intent.getIntExtra(KEY_ACTION_SOURCE, -1), url);
pasko 2016/03/01 14:28:28 nit: line longer than 100 chars
andreban 2016/03/01 15:03:03 Done.
+ Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private String getToastText(Context context, int actionId, String url) {
+ switch (actionId) {
+ case ACTION_ACTION_BUTTON:
+ return context.getString(R.string.action_button_toast_text, url);
+ case ACTION_MENU_ITEM:
+ return context.getString(R.string.menu_item_toast_text, url);
+ case ACTION_TOOLBAR:
+ return context.getString(R.string.toolbar_toast_text, url);
+ default:
+ return context.getString(R.string.unknown_toast_text, url);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698