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..525290e2a262cd99397bd64c2034e42b73bb2ec2 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,56 @@ 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. |
pasko
2016/03/01 14:28:28
is this a TODO? Why is it OK to decode bitmaps in
andreban
2016/03/01 15:03:03
Done.
|
- String shareLabel = getString(R.string.label_action_share); |
+ 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. |
+ 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 +160,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); |
} |
} |