Bug 1332546 - Apply default actionbar color draft
authorJulian_Chu <walkingice0204@gmail.com>
Wed, 08 Mar 2017 11:43:24 +0800
changeset 499671 7a6da2e3632c70d8c3027ed1b2a1584e614af2cd
parent 499670 e49e29f0d0dc6dc4ef59656066f2e184113ed25b
child 499672 0ce0337be2119d448b8f8a234c8255eb59b5c095
push id49471
push userbmo:walkingice0204@gmail.com
push dateThu, 16 Mar 2017 02:41:34 +0000
bugs1332546
milestone55.0a1
Bug 1332546 - Apply default actionbar color Designer provides a color code as default background color for ActionBar. Also get rid of `NO_COLOR`: -1 equals 0xFFFFFFFF, so it always ignores white color. MozReview-Commit-ID: 6YJDxsSOhkZ
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -9,16 +9,17 @@ 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.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.util.SparseArrayCompat;
 import android.support.v4.view.MenuItemCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.Toolbar;
 import android.text.TextUtils;
@@ -43,35 +44,40 @@ import org.mozilla.gecko.widget.GeckoPop
 import java.util.List;
 
 import static android.support.customtabs.CustomTabsIntent.EXTRA_TOOLBAR_COLOR;
 
 public class CustomTabsActivity extends GeckoApp implements Tabs.OnTabsChangedListener {
     private static final String LOGTAG = "CustomTabsActivity";
     private static final String SAVED_TOOLBAR_COLOR = "SavedToolbarColor";
     private static final String SAVED_TOOLBAR_TITLE = "SavedToolbarTitle";
-    private static final int NO_COLOR = -1;
+
+    @ColorInt
+    private static final int DEFAULT_ACTION_BAR_COLOR = 0xFF363b40; // default color to match design
+
     private final SparseArrayCompat<PendingIntent> menuItemsIntent = new SparseArrayCompat<>();
     private GeckoPopupMenu popupMenu;
     private int tabId = -1;
     private ActionBarPresenter actionBarPresenter;
-    private int toolbarColor;
     private String toolbarTitle;
     // A state to indicate whether this activity is finishing with customize animation
     private boolean usingCustomAnimation = false;
 
+    @ColorInt
+    private int toolbarColor = DEFAULT_ACTION_BAR_COLOR;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         if (savedInstanceState != null) {
-            toolbarColor = savedInstanceState.getInt(SAVED_TOOLBAR_COLOR, NO_COLOR);
+            toolbarColor = savedInstanceState.getInt(SAVED_TOOLBAR_COLOR, DEFAULT_ACTION_BAR_COLOR);
             toolbarTitle = savedInstanceState.getString(SAVED_TOOLBAR_TITLE, AppConstants.MOZ_APP_BASENAME);
         } else {
-            toolbarColor = getIntent().getIntExtra(EXTRA_TOOLBAR_COLOR, NO_COLOR);
+            toolbarColor = getIntent().getIntExtra(EXTRA_TOOLBAR_COLOR, DEFAULT_ACTION_BAR_COLOR);
             toolbarTitle = AppConstants.MOZ_APP_BASENAME;
         }
 
         // Translucent color does not make sense for toolbar color. Ensure it is 0xFF.
         toolbarColor = 0xFF000000 | toolbarColor;
 
         setThemeFromToolbarColor();
 
@@ -84,24 +90,20 @@ public class CustomTabsActivity extends 
         actionBarPresenter = new ActionBarPresenter(actionBar, toolbar);
         actionBarPresenter.setBackgroundColor(toolbarColor, getWindow());
         actionBarPresenter.update(toolbarTitle);
 
         Tabs.registerOnTabsChangedListener(this);
     }
 
     private void setThemeFromToolbarColor() {
-        // default theme, regardless AndroidManifest.
-        @StyleRes int styleRes = R.style.GeckoCustomTabs;
-
-        if (toolbarColor != NO_COLOR) {
-            styleRes = (ColorUtil.getReadableTextColor(toolbarColor) == Color.BLACK)
-                    ? R.style.GeckoCustomTabs_Light
-                    : R.style.GeckoCustomTabs;
-        }
+        @StyleRes
+        int styleRes = (ColorUtil.getReadableTextColor(toolbarColor) == Color.BLACK)
+                ? R.style.GeckoCustomTabs_Light
+                : R.style.GeckoCustomTabs;
 
         setTheme(styleRes);
     }
 
     // Bug 1329145: 3rd party app could specify customized exit-animation to this activity.
     // Activity.overridePendingTransition will invoke getPackageName to retrieve that animation resource.
     // In that case, to return different package name to get customized animation resource.
     @Override