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

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

Issue 1305253006: [Custom Tabs]Add API for updating action button as ContentProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 ee99a093ffefff274fccb4fd45b70436d90b5e1c..e2189958b1725e8f65e3951e074f3d0d3aea1f84 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
@@ -80,9 +80,7 @@ public class CustomTabIntentDataProvider {
private final int mTitleVisibilityState;
private int mToolbarColor;
private boolean mEnableUrlBarHiding;
- private Drawable mCustomButtonIcon;
- private String mCustomButtonDescription;
- private PendingIntent mCustomButtonPendingIntent;
+ private ActionButtonParams mActionButtonParams;
private Drawable mCloseButtonIcon;
private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
private Bundle mAnimationBundle;
@@ -103,27 +101,9 @@ public class CustomTabIntentDataProvider {
Bundle actionButtonBundle =
IntentUtils.safeGetBundleExtra(intent, CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
- if (actionButtonBundle != null) {
- Bitmap bitmap = IntentUtils.safeGetParcelable(actionButtonBundle,
- CustomTabsIntent.KEY_ICON);
- if (bitmap != null && !checkCustomButtonIconWithinBounds(context, bitmap)) {
- bitmap.recycle();
- bitmap = null;
- } else if (bitmap != null) {
- mCustomButtonPendingIntent = IntentUtils.safeGetParcelable(
- actionButtonBundle, CustomTabsIntent.KEY_PENDING_INTENT);
- boolean shouldTint = IntentUtils.safeGetBooleanExtra(intent,
- EXTRA_TINT_ACTION_BUTTON, false);
- if (shouldTint) {
- mCustomButtonIcon = TintedDrawable
- .constructTintedDrawable(context.getResources(), bitmap);
- } else {
- mCustomButtonIcon = new BitmapDrawable(context.getResources(), bitmap);
- }
- mCustomButtonDescription = IntentUtils.safeGetString(actionButtonBundle,
- CustomTabsIntent.KEY_DESCRIPTION);
- }
- }
+ mActionButtonParams = ActionButtonParams.fromBundle(context, actionButtonBundle);
+ boolean tinted = IntentUtils.safeGetBooleanExtra(intent, EXTRA_TINT_ACTION_BUTTON, false);
+ mActionButtonParams.setTinted(tinted);
Bitmap bitmap = IntentUtils.safeGetParcelableExtra(intent, EXTRA_CLOSE_BUTTON_ICON);
if (bitmap != null && !checkCloseButtonSize(context, bitmap)) {
@@ -223,31 +203,14 @@ public class CustomTabIntentDataProvider {
* action button.
*/
public boolean shouldShowActionButton() {
- return mCustomButtonIcon != null && mCustomButtonPendingIntent != null
- && !TextUtils.isEmpty(mCustomButtonDescription);
+ return mActionButtonParams != null;
}
/**
- * @return The icon used for the action button. Will be null if not set in the intent.
+ * Gets the {@link ActionButtonParams} representing the action button.
*/
- public Drawable getActionButtonIcon() {
- return mCustomButtonIcon;
- }
-
- /**
- * @return The content description for the custom action button.
- */
- public String getActionButtonDescription() {
- return mCustomButtonDescription;
- }
-
- /**
- * @return The {@link PendingIntent} that will be sent when the user clicks the action button.
- * For testing only.
- */
- @VisibleForTesting
- public PendingIntent getActionButtonPendingIntentForTest() {
- return mCustomButtonPendingIntent;
+ ActionButtonParams getActionButtonParams() {
+ return mActionButtonParams;
}
/**
@@ -318,24 +281,16 @@ public class CustomTabIntentDataProvider {
* @param url The url to attach as additional data to the {@link PendingIntent}.
*/
public void sendButtonPendingIntentWithUrl(Context context, String url) {
- assert mCustomButtonPendingIntent != null;
+ assert shouldShowActionButton();
Intent addedIntent = new Intent();
addedIntent.setData(Uri.parse(url));
try {
- mCustomButtonPendingIntent.send(context, 0, addedIntent, mOnFinished, null);
+ mActionButtonParams.getPendingIntent().send(context, 0, addedIntent, mOnFinished, null);
} catch (CanceledException e) {
Log.e(TAG, "CanceledException while sending pending intent in custom tab");
}
}
- private boolean checkCustomButtonIconWithinBounds(Context context, Bitmap bitmap) {
- int height = context.getResources().getDimensionPixelSize(R.dimen.toolbar_icon_height);
- if (bitmap.getHeight() < height) return false;
- int scaledWidth = bitmap.getWidth() / bitmap.getHeight() * height;
- if (scaledWidth > 2 * height) return false;
- return true;
- }
-
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