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

Unified Diff: demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.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: Fix comment on decoding Bitmpa on UI thread 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/CustomUIActivity.java
diff --git a/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java b/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
index 5ce437c407c8c7f7cc1dccbd8e92ccbbb986b2dc..6a7844b702d74f0e38a6c94b612f1f7b5637a2b8 100644
--- a/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
+++ b/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
@@ -32,14 +32,18 @@ import android.widget.EditText;
*/
public class CustomUIActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "CustChromeTabActivity";
+ private static final int TOOLBAR_ITEM_ID = 1;
private EditText mUrlEditText;
private EditText mCustomTabColorEditText;
+ private EditText mCustomTabSecondaryColorEditText;
private CheckBox mShowActionButtonCheckbox;
private CheckBox mAddMenusCheckbox;
private CheckBox mShowTitleCheckBox;
private CheckBox mCustomBackButtonCheckBox;
private CheckBox mAutoHideAppBarCheckbox;
+ private CheckBox mAddDefaultShareCheckbox;
+ private CheckBox mToolbarItemCheckbox;
private CustomTabActivityHelper mCustomTabActivityHelper;
@Override
@@ -52,11 +56,15 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
mUrlEditText = (EditText) findViewById(R.id.url);
mCustomTabColorEditText = (EditText) findViewById(R.id.custom_toolbar_color);
+ mCustomTabSecondaryColorEditText =
+ (EditText) findViewById(R.id.custom_toolbar_secondary_color);
mShowActionButtonCheckbox = (CheckBox) findViewById(R.id.custom_show_action_button);
mAddMenusCheckbox = (CheckBox) findViewById(R.id.custom_add_menus);
mShowTitleCheckBox = (CheckBox) findViewById(R.id.show_title);
mCustomBackButtonCheckBox = (CheckBox) findViewById(R.id.custom_back_button);
mAutoHideAppBarCheckbox = (CheckBox) findViewById(R.id.auto_hide_checkbox);
+ mAddDefaultShareCheckbox = (CheckBox) findViewById(R.id.add_default_share);
+ mToolbarItemCheckbox = (CheckBox) findViewById(R.id.add_toolbar_item);
}
@Override
@@ -83,34 +91,58 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
}
}
- private void openCustomTab() {
- String url = mUrlEditText.getText().toString();
-
- int color = Color.BLUE;
+ private int getColor(EditText editText) {
try {
- color = Color.parseColor(mCustomTabColorEditText.getText().toString());
+ return Color.parseColor(editText.getText().toString());
} catch (NumberFormatException ex) {
- Log.i(TAG, "Unable to parse Color: " + mCustomTabColorEditText.getText());
+ Log.i(TAG, "Unable to parse Color: " + editText.getText());
+ return Color.LTGRAY;
}
+ }
+
+ private void openCustomTab() {
+ String url = mUrlEditText.getText().toString();
+
+ int color = getColor(mCustomTabColorEditText);
+ int secondaryColor = getColor(mCustomTabSecondaryColorEditText);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(color);
+ intentBuilder.setSecondaryToolbarColor(secondaryColor);
if (mShowActionButtonCheckbox.isChecked()) {
- //Generally you do not want to decode bitmaps in the UI thread.
- String shareLabel = getString(R.string.label_action_share);
+ //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the
+ //UI thread to keep the example short.
+ String actionLabel = getString(R.string.label_action);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
android.R.drawable.ic_menu_share);
- PendingIntent pendingIntent = createPendingIntent();
- intentBuilder.setActionButton(icon, shareLabel, pendingIntent);
+ PendingIntent pendingIntent =
+ createPendingIntent(ActionBroadcastReceiver.ACTION_ACTION_BUTTON);
+ intentBuilder.setActionButton(icon, actionLabel, pendingIntent);
}
if (mAddMenusCheckbox.isChecked()) {
String menuItemTitle = getString(R.string.menu_item_title);
- PendingIntent menuItemPendingIntent = createPendingIntent();
+ PendingIntent menuItemPendingIntent =
+ createPendingIntent(ActionBroadcastReceiver.ACTION_MENU_ITEM);
intentBuilder.addMenuItem(menuItemTitle, menuItemPendingIntent);
}
+ if (mAddDefaultShareCheckbox.isChecked()) {
+ intentBuilder.addDefaultShareMenuItem();
+ }
+
+ if (mToolbarItemCheckbox.isChecked()) {
+ //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the
+ //UI thread to keep the example short.
+ String actionLabel = getString(R.string.label_action);
+ Bitmap icon = BitmapFactory.decodeResource(getResources(),
+ android.R.drawable.ic_menu_share);
+ PendingIntent pendingIntent =
+ createPendingIntent(ActionBroadcastReceiver.ACTION_TOOLBAR);
+ intentBuilder.addToolbarItem(TOOLBAR_ITEM_ID, icon, actionLabel, pendingIntent);
+ }
+
intentBuilder.setShowTitle(mShowTitleCheckBox.isChecked());
if (mAutoHideAppBarCheckbox.isChecked()) {
@@ -130,9 +162,11 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
this, intentBuilder.build(), Uri.parse(url), new WebviewFallback());
}
- private PendingIntent createPendingIntent() {
+ private PendingIntent createPendingIntent(int actionSourceId) {
Intent actionIntent = new Intent(
- this.getApplicationContext(), ShareBroadcastReceiver.class);
- return PendingIntent.getBroadcast(getApplicationContext(), 0, actionIntent, 0);
+ this.getApplicationContext(), ActionBroadcastReceiver.class);
+ actionIntent.putExtra(ActionBroadcastReceiver.KEY_ACTION_SOURCE, actionSourceId);
+ return PendingIntent.getBroadcast(
+ getApplicationContext(), actionSourceId, actionIntent, 0);
}
}

Powered by Google App Engine
This is Rietveld 408576698