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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/ActionButtonParams.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/ActionButtonParams.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ActionButtonParams.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ActionButtonParams.java
index 9c959b26699ac70725974b8190411bdb876f964e..4a42fa3009b821331ceb458c89f2ceba862f8436 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ActionButtonParams.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/ActionButtonParams.java
@@ -6,44 +6,28 @@ package org.chromium.chrome.browser.customtabs;
import android.app.PendingIntent;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.text.TextUtils;
-import org.chromium.base.Log;
-import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.widget.TintedDrawable;
/**
- * Container for all parameters related to creating a custom action button.
+ * Container for all parameters related to customizing an action button on Custom Tab's toolbar.
*/
-/* package */ class ActionButtonParams {
- private static final String TAG = "CustomTabs";
+public class ActionButtonParams extends ButtonParams {
Ian Wen 2016/01/02 14:20:39 Some common attributes of ActionButtonParams are a
- private Bitmap mIcon;
- private String mDescription;
- private final PendingIntent mPendingIntent;
private boolean mShouldTint;
- private ActionButtonParams(@NonNull Bitmap icon, @NonNull String description,
- @NonNull PendingIntent pendingIntent) {
- mIcon = icon;
- mDescription = description;
- mPendingIntent = pendingIntent;
- }
-
- /**
- * Replaces the current icon and description with new ones.
- */
- void update(@NonNull Bitmap icon, @NonNull String description) {
- mIcon = icon;
- mDescription = description;
+ private ActionButtonParams(Bitmap icon, String description, PendingIntent pendingIntent,
+ boolean shouldTint) {
+ super(icon, description, pendingIntent);
+ setTinted(shouldTint);
}
/**
@@ -57,37 +41,22 @@ import org.chromium.chrome.browser.widget.TintedDrawable;
* @return The drawable for the action button. Will be a {@link TintedDrawable} if in the VIEW
* intent the client required to tint it.
*/
+ @Override
Drawable getIcon(Resources res) {
- Drawable drawable = null;
- if (mShouldTint) {
- drawable = TintedDrawable.constructTintedDrawable(res, mIcon);
- } else {
- drawable = new BitmapDrawable(res, mIcon);
- }
- return drawable;
+ if (mShouldTint) return TintedDrawable.constructTintedDrawable(res, mIcon);
+ else return super.getIcon(res);
}
/**
- * @return The content description for the custom action button.
+ * Parses a {@link ButtonParams} from an action button bundle sent by clients.
+ * @param intent The intent sent by the client.
+ * @return The parsed {@link ButtonParams}. Return null if input is invalid.
*/
- String getDescription() {
- return mDescription;
- }
-
- /**
- * @return The {@link PendingIntent} that will be sent when the user clicks the action button.
- */
- PendingIntent getPendingIntent() {
- return mPendingIntent;
- }
+ static ActionButtonParams fromIntent(Context context, Intent intent) {
+ if (intent == null) return null;
- /**
- * Parses an {@link ActionButtonParams} from an action button bundle sent by clients.
- * @param bundle The action button bundle specified by
- * {@link CustomTabsIntent#EXTRA_ACTION_BUTTON_BUNDLE}
- * @return The parsed {@link ActionButtonParams}. Return null if input is invalid.
- */
- static ActionButtonParams fromBundle(Context context, Bundle bundle) {
+ Bundle bundle = IntentUtils.safeGetBundleExtra(intent,
+ CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
if (bundle == null) return null;
Bitmap bitmap = tryParseBitmapFromBundle(context, bundle);
@@ -99,45 +68,12 @@ import org.chromium.chrome.browser.widget.TintedDrawable;
return null;
}
+ boolean tinted = IntentUtils.safeGetBooleanExtra(intent,
+ CustomTabsIntent.EXTRA_TINT_ACTION_BUTTON, false);
+
PendingIntent pi = IntentUtils.safeGetParcelable(bundle,
CustomTabsIntent.KEY_PENDING_INTENT);
if (pi == null) return null;
- return new ActionButtonParams(bitmap, description, pi);
- }
-
- /**
- * @return The bitmap contained in the given {@link Bundle}. Will return null if input is
- * invalid.
- */
- static Bitmap tryParseBitmapFromBundle(Context context, Bundle bundle) {
- if (bundle == null) return null;
- Bitmap bitmap = IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.KEY_ICON);
- if (bitmap == null) return null;
- if (!checkCustomButtonIconWithinBounds(context, bitmap)) {
- Log.w(TAG, "Action button's icon size not acceptable. Please refer to "
- + "https://developer.android.com/reference/android/support/customtabs/"
- + "CustomTabsIntent.html#KEY_ICON");
- bitmap.recycle();
- return null;
- }
- return bitmap;
- }
-
- /**
- * @return The content description contained in the given {@link Bundle}. Will return null if
- * input is invalid.
- */
- static String tryParseDescriptionFromBundle(Bundle bundle) {
- String description = IntentUtils.safeGetString(bundle, CustomTabsIntent.KEY_DESCRIPTION);
- if (TextUtils.isEmpty(description)) return null;
- return description;
- }
-
- private static 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;
+ return new ActionButtonParams(bitmap, description, pi, tinted);
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698