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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java

Issue 1557803002: [Custom Tabs] Implement Bottombar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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: 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..c085a79332e241ec9317b31db7057c15d6549b52 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:";
@@ -93,6 +62,8 @@ public class CustomTabIntentDataProvider {
private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
private Bundle mAnimationBundle;
private boolean mShowShareItem;
+ private int mBottomBarColor;
+ private List<BottombarItemParams> mBottomItems;
// OnFinished listener for PendingIntents. Used for testing only.
private PendingIntent.OnFinished mOnFinished;
@@ -107,16 +78,10 @@ public class CustomTabIntentDataProvider {
mEnableUrlBarHiding = IntentUtils.safeGetBooleanExtra(
intent, CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, true);
mKeepAliveServiceIntent = IntentUtils.safeGetParcelableExtra(intent, EXTRA_KEEP_ALIVE);
+ mActionButtonParams = ActionButtonParams.fromIntent(context, intent);
- 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,10 +109,13 @@ 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);
+
+ retrieveBottombarColor(intent, context);
+ mBottomItems = BottombarItemParams.fromIntent(context, intent);
}
/**
@@ -159,13 +127,30 @@ 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;
+ /**
+ * Processes the color passed from the client app and updates {@link #mBottomBarColor}.
+ */
+ private void retrieveBottombarColor(Intent intent, Context context) {
+ int color = IntentUtils.safeGetIntExtra(intent, CustomTabsIntent.EXTRA_BOTTOM_BAR_COLOR,
+ ApiCompatibilityUtils.getColor(context.getResources(),
+ R.color.default_primary_color));
+ int defaultColor = ApiCompatibilityUtils.getColor(context.getResources(),
+ R.color.default_primary_color);
+ mBottomBarColor = removeTransparencyFromColor(color, defaultColor);
+ }
+ /**
+ * 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) {
// Ignore any transparency value.
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;
@@ -230,9 +215,9 @@ public class CustomTabIntentDataProvider {
}
/**
- * Gets the {@link ActionButtonParams} representing the action button.
+ * Gets the {@link ButtonParams} representing the action button.
*/
- ActionButtonParams getActionButtonParams() {
+ ButtonParams getActionButtonParams() {
return mActionButtonParams;
}
@@ -314,6 +299,27 @@ public class CustomTabIntentDataProvider {
}
}
+ /**
+ * @return Whether the bottom bar should be shown.
+ */
+ public boolean shouldShowBottomBar() {
+ return mBottomItems != null && !mBottomItems.isEmpty();
+ }
+
+ /**
+ * @return The color of the bottom bar. If not specified, returns the default primary color.
+ */
+ public int getBottomBarColor() {
+ return mBottomBarColor;
+ }
+
+ /**
+ * @return The list of {@link BottombarItemParams} specified by the client.
+ */
+ public List<BottombarItemParams> getBottomBarItems() {
+ return mBottomItems;
+ }
+
private boolean checkCloseButtonSize(Context context, Bitmap bitmap) {
int size = context.getResources().getDimensionPixelSize(R.dimen.toolbar_icon_height);
if (bitmap.getHeight() == size && bitmap.getWidth() == size) return true;

Powered by Google App Engine
This is Rietveld 408576698