Bug 1336373 - CustomTabsActivity supports tint in Action Button draft
authorJulian_Chu <walkingice0204@gmail.com>
Mon, 20 Mar 2017 13:59:43 +0800
changeset 502162 529593652eff1ce3e03e7acb8724753648013ddb
parent 502161 ca4ae502156eaea6fffb296bb9c3b3930af8ab58
child 550086 f28de773b39919bfa32913a35142a389fef71345
push id50205
push userbmo:walkingice0204@gmail.com
push dateTue, 21 Mar 2017 10:45:39 +0000
bugs1336373
milestone55.0a1
Bug 1336373 - CustomTabsActivity supports tint in Action Button If 3-rd party app specify to use tint for Action Button, use primary text color as the tint color for Action Button. MozReview-Commit-ID: 3sX0MH8P0dM
mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
@@ -120,16 +120,26 @@ public class ActionBarPresenter {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                 window.setStatusBarColor(ColorUtil.darken(color, 0.25));
             }
         }
     }
 
     /**
+     * To get primary color of Title of ActionBar
+     *
+     * @return color code of primary color
+     */
+    @ColorInt
+    public int getTextPrimaryColor() {
+        return mTextPrimaryColor;
+    }
+
+    /**
      * To update appearance of CustomView of ActionBar, includes its icon, title and url text.
      *
      * @param identity SiteIdentity for current website. Could be null if don't want to show icon.
      * @param title    Title for current website. Could be null if don't want to show title.
      * @param url      URL for current website. At least Custom will show this url.
      */
     @UiThread
     private void updateCustomView(@Nullable SiteIdentity identity,
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -7,22 +7,24 @@ package org.mozilla.gecko.customtabs;
 
 import android.app.PendingIntent;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.annotation.StyleRes;
 import android.support.annotation.VisibleForTesting;
+import android.support.v4.graphics.drawable.DrawableCompat;
 import android.support.v4.util.SparseArrayCompat;
 import android.support.v4.view.MenuItemCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.Toolbar;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -249,23 +251,26 @@ public class CustomTabsActivity extends 
      * @return the MenuItem which be created and inserted into menu. Otherwise, null.
      */
     @VisibleForTesting
     MenuItem insertActionButton(Menu menu, Intent intent) {
         if (!IntentUtil.hasActionButton(intent)) {
             return null;
         }
 
-        // TODO: Bug 1336373 - Action button icon should support tint
         MenuItem item = menu.add(Menu.NONE,
                 R.id.action_button,
                 Menu.NONE,
                 IntentUtil.getActionButtonDescription(intent));
         Bitmap bitmap = IntentUtil.getActionButtonIcon(intent);
-        item.setIcon(new BitmapDrawable(getResources(), bitmap));
+        final Drawable icon = new BitmapDrawable(getResources(), bitmap);
+        if (IntentUtil.isActionButtonTinted(getIntent())) {
+            DrawableCompat.setTint(icon, actionBarPresenter.getTextPrimaryColor());
+        }
+        item.setIcon(icon);
         MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
 
         return item;
     }
 
     private void bindNavigationCallback(@NonNull final Toolbar toolbar) {
         toolbar.setNavigationOnClickListener(new View.OnClickListener() {
             @Override