| Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| index d459ccc1d953758a39a6c0e7950d4a4c301520d7..7fd0d7d4ccb9a5344e9fd0290496ddf1dea67af8 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| @@ -44,37 +44,6 @@ public class CustomTabIntentDataProvider {
|
| */
|
| public static final String EXTRA_KEEP_ALIVE = "android.support.customtabs.extra.KEEP_ALIVE";
|
|
|
| - /**
|
| - * Extra bitmap that specifies the icon of the back button on the toolbar. If the client chooses
|
| - * not to customize it, a default close button will be used.
|
| - */
|
| - public static final String EXTRA_CLOSE_BUTTON_ICON =
|
| - "android.support.customtabs.extra.CLOSE_BUTTON_ICON";
|
| -
|
| - /**
|
| - * Extra int that specifies state for showing the page title. Default is showing only the domain
|
| - * and no information about the title.
|
| - */
|
| - public static final String EXTRA_TITLE_VISIBILITY_STATE =
|
| - "android.support.customtabs.extra.TITLE_VISIBILITY";
|
| -
|
| - /**
|
| - * Don't show any title. Shows only the domain.
|
| - */
|
| - public static final int NO_TITLE = 0;
|
| -
|
| - /**
|
| - * Shows the page title and the domain.
|
| - */
|
| - public static final int SHOW_PAGE_TITLE = 1;
|
| -
|
| - /**
|
| - * Extra boolean that specifies whether the custom action button should be tinted. Default is
|
| - * false and the action button will not be tinted.
|
| - */
|
| - public static final String EXTRA_TINT_ACTION_BUTTON =
|
| - "android.support.customtabs.extra.TINT_ACTION_BUTTON";
|
| -
|
| private static final int MAX_CUSTOM_MENU_ITEMS = 5;
|
| private static final String ANIMATION_BUNDLE_PREFIX =
|
| Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? "android:activity." : "android:";
|
| @@ -88,11 +57,13 @@ public class CustomTabIntentDataProvider {
|
| private final int mTitleVisibilityState;
|
| private int mToolbarColor;
|
| private boolean mEnableUrlBarHiding;
|
| - private ActionButtonParams mActionButtonParams;
|
| + private List<CustomButtonParams> mCustomButtonParams;
|
| private Drawable mCloseButtonIcon;
|
| private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
|
| private Bundle mAnimationBundle;
|
| private boolean mShowShareItem;
|
| + private CustomButtonParams mToolbarButton;
|
| + private List<CustomButtonParams> mBottombarButtons = new ArrayList<>(2);
|
| // OnFinished listener for PendingIntents. Used for testing only.
|
| private PendingIntent.OnFinished mOnFinished;
|
|
|
| @@ -101,22 +72,15 @@ public class CustomTabIntentDataProvider {
|
| */
|
| public CustomTabIntentDataProvider(Intent intent, Context context) {
|
| if (intent == null) assert false;
|
| -
|
| mSession = IntentUtils.safeGetBinderExtra(intent, CustomTabsIntent.EXTRA_SESSION);
|
| + retrieveCustomButtons(intent, context);
|
| retrieveToolbarColor(intent, context);
|
| mEnableUrlBarHiding = IntentUtils.safeGetBooleanExtra(
|
| intent, CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, true);
|
| mKeepAliveServiceIntent = IntentUtils.safeGetParcelableExtra(intent, EXTRA_KEEP_ALIVE);
|
|
|
| - Bundle actionButtonBundle =
|
| - IntentUtils.safeGetBundleExtra(intent, CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
|
| - mActionButtonParams = ActionButtonParams.fromBundle(context, actionButtonBundle);
|
| - if (mActionButtonParams != null) {
|
| - mActionButtonParams.setTinted(
|
| - IntentUtils.safeGetBooleanExtra(intent, EXTRA_TINT_ACTION_BUTTON, false));
|
| - }
|
| -
|
| - Bitmap bitmap = IntentUtils.safeGetParcelableExtra(intent, EXTRA_CLOSE_BUTTON_ICON);
|
| + Bitmap bitmap = IntentUtils.safeGetParcelableExtra(intent,
|
| + CustomTabsIntent.EXTRA_CLOSE_BUTTON_ICON);
|
| if (bitmap != null && !checkCloseButtonSize(context, bitmap)) {
|
| bitmap.recycle();
|
| bitmap = null;
|
| @@ -144,13 +108,30 @@ public class CustomTabIntentDataProvider {
|
|
|
| mAnimationBundle = IntentUtils.safeGetBundleExtra(
|
| intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE);
|
| - mTitleVisibilityState =
|
| - IntentUtils.safeGetIntExtra(intent, EXTRA_TITLE_VISIBILITY_STATE, NO_TITLE);
|
| + mTitleVisibilityState = IntentUtils.safeGetIntExtra(intent,
|
| + CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
|
| mShowShareItem = IntentUtils.safeGetBooleanExtra(intent,
|
| CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false);
|
| }
|
|
|
| /**
|
| + * Gets custom buttons from the intent and updates {@link #mCustomButtonParams},
|
| + * {@link #mBottombarButtons} and {@link #mToolbarButton}.
|
| + */
|
| + private void retrieveCustomButtons(Intent intent, Context context) {
|
| + mCustomButtonParams = CustomButtonParams.fromIntent(context, intent);
|
| + if (mCustomButtonParams != null) {
|
| + for (CustomButtonParams params : mCustomButtonParams) {
|
| + if (params.showOnToolbar()) {
|
| + mToolbarButton = params;
|
| + } else {
|
| + mBottombarButtons.add(params);
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Processes the color passed from the client app and updates {@link #mToolbarColor}.
|
| */
|
| private void retrieveToolbarColor(Intent intent, Context context) {
|
| @@ -159,13 +140,17 @@ public class CustomTabIntentDataProvider {
|
| R.color.default_primary_color));
|
| int defaultColor = ApiCompatibilityUtils.getColor(context.getResources(),
|
| R.color.default_primary_color);
|
| + mToolbarColor = removeTransparencyFromColor(color, defaultColor);
|
| + }
|
|
|
| - if (color == Color.TRANSPARENT) color = defaultColor;
|
| -
|
| - // Ignore any transparency value.
|
| + /**
|
| + * Removes the alpha channel of the given color and returns the processed value. If the result
|
| + * is blank, returns the fallback value.
|
| + */
|
| + private int removeTransparencyFromColor(int color, int fallbackColor) {
|
| color |= 0xFF000000;
|
| -
|
| - mToolbarColor = color;
|
| + if (color == Color.TRANSPARENT) color = fallbackColor;
|
| + return color;
|
| }
|
|
|
| /**
|
| @@ -208,7 +193,7 @@ public class CustomTabIntentDataProvider {
|
|
|
| /**
|
| * @return The title visibility state for the toolbar.
|
| - * Default is {@link CustomTabIntentDataProvider#NO_TITLE}.
|
| + * Default is {@link CustomTabsIntent#NO_TITLE}.
|
| */
|
| public int getTitleVisibilityState() {
|
| return mTitleVisibilityState;
|
| @@ -222,18 +207,33 @@ public class CustomTabIntentDataProvider {
|
| }
|
|
|
| /**
|
| - * @return Whether the client app has provided sufficient info for the toolbar to show the
|
| - * action button.
|
| + * @return The params for the custom button that shows on the toolbar. If there is no applicable
|
| + * buttons, returns null.
|
| + */
|
| + public CustomButtonParams getCustomButtonOnToolbar() {
|
| + return mToolbarButton;
|
| + }
|
| +
|
| + /**
|
| + * @return The list of params representing the buttons on the bottombar.
|
| + */
|
| + public List<CustomButtonParams> getCustomButtonsOnBottombar() {
|
| + return mBottombarButtons;
|
| + }
|
| +
|
| + /**
|
| + * @return Whether the bottom bar should be shown.
|
| */
|
| - public boolean shouldShowActionButton() {
|
| - return mActionButtonParams != null;
|
| + public boolean shouldShowBottomBar() {
|
| + return !mBottombarButtons.isEmpty();
|
| }
|
|
|
| /**
|
| - * Gets the {@link ActionButtonParams} representing the action button.
|
| + * Gets params for all custom buttons, which is the combination of
|
| + * {@link #getCustomButtonsOnBottombar()} and {@link #getCustomButtonOnToolbar()}.
|
| */
|
| - ActionButtonParams getActionButtonParams() {
|
| - return mActionButtonParams;
|
| + public List<CustomButtonParams> getAllCustomButtons() {
|
| + return mCustomButtonParams;
|
| }
|
|
|
| /**
|
| @@ -299,16 +299,16 @@ public class CustomTabIntentDataProvider {
|
| }
|
|
|
| /**
|
| - * Send the pending intent for the current action button with the given url as data.
|
| + * Sends the pending intent for the custom button on toolbar with the given url as data.
|
| * @param context The context to use for sending the {@link PendingIntent}.
|
| * @param url The url to attach as additional data to the {@link PendingIntent}.
|
| */
|
| public void sendButtonPendingIntentWithUrl(Context context, String url) {
|
| - assert shouldShowActionButton();
|
| Intent addedIntent = new Intent();
|
| addedIntent.setData(Uri.parse(url));
|
| try {
|
| - mActionButtonParams.getPendingIntent().send(context, 0, addedIntent, mOnFinished, null);
|
| + getCustomButtonOnToolbar().getPendingIntent().send(context, 0, addedIntent, mOnFinished,
|
| + null);
|
| } catch (CanceledException e) {
|
| Log.e(TAG, "CanceledException while sending pending intent in custom tab");
|
| }
|
|
|