Chromium Code Reviews| 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..d5a0541384cc7a2afda213fc9da9e42bc40ed66a 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 |
| @@ -9,6 +9,7 @@ import android.app.PendingIntent; |
| import android.app.PendingIntent.CanceledException; |
| import android.content.Context; |
| import android.content.Intent; |
| +import android.content.res.Resources; |
| import android.graphics.Bitmap; |
| import android.graphics.Color; |
| import android.graphics.drawable.BitmapDrawable; |
| @@ -80,9 +81,8 @@ 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 boolean mShouldTintActionButton; |
| private Drawable mCloseButtonIcon; |
| private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); |
| private Bundle mAnimationBundle; |
| @@ -103,27 +103,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); |
| - } |
| - } |
| + mShouldTintActionButton = IntentUtils.safeGetBooleanExtra(intent, EXTRA_TINT_ACTION_BUTTON, |
| + false); |
| + mActionButtonParams = ActionButtonParams.fromBundle(context, actionButtonBundle); |
| Bitmap bitmap = IntentUtils.safeGetParcelableExtra(intent, EXTRA_CLOSE_BUTTON_ICON); |
| if (bitmap != null && !checkCloseButtonSize(context, bitmap)) { |
| @@ -223,31 +205,41 @@ public class CustomTabIntentDataProvider { |
| * action button. |
| */ |
| public boolean shouldShowActionButton() { |
| - return mCustomButtonIcon != null && mCustomButtonPendingIntent != null |
| - && !TextUtils.isEmpty(mCustomButtonDescription); |
| + return mActionButtonParams != null; |
| + } |
| + |
| + /** |
| + * Sets the {@link ActionButtonParams} representing the action button. |
| + */ |
| + public void setActionButtonParams(ActionButtonParams params) { |
| + mActionButtonParams = params; |
| } |
| /** |
| * @return The icon used for the action button. Will be null if not set in the intent. |
| */ |
| - public Drawable getActionButtonIcon() { |
| - return mCustomButtonIcon; |
| + public Drawable getActionButtonIcon(Resources res) { |
|
Yusuf
2015/08/21 00:07:36
have a getter for action button params instead. TH
Ian Wen
2015/08/21 17:01:24
Done.
|
| + Drawable drawable = null; |
| + if (mShouldTintActionButton) { |
|
Yusuf
2015/08/21 00:07:36
move this to action button params
Ian Wen
2015/08/21 17:01:24
Done.
|
| + drawable = TintedDrawable.constructTintedDrawable(res, mActionButtonParams.mIcon); |
|
Yusuf
2015/08/21 00:07:36
move this to ActionButtonParams
Ian Wen
2015/08/21 17:01:24
Done.
|
| + } else { |
| + drawable = new BitmapDrawable(res, mActionButtonParams.mIcon); |
| + } |
| + return drawable; |
| } |
| /** |
| * @return The content description for the custom action button. |
| */ |
| public String getActionButtonDescription() { |
| - return mCustomButtonDescription; |
| + return mActionButtonParams.mDescription; |
| } |
| /** |
| * @return The {@link PendingIntent} that will be sent when the user clicks the action button. |
| - * For testing only. |
| */ |
| - @VisibleForTesting |
| - public PendingIntent getActionButtonPendingIntentForTest() { |
| - return mCustomButtonPendingIntent; |
| + public PendingIntent getActionButtonPendingIntent() { |
| + return mActionButtonParams.mPendingIntent; |
| } |
| /** |
| @@ -318,24 +310,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.mPendingIntent.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; |