Bug 1332546 - Apply default actionbar color r=sebastian
authorJulian_Chu <walkingice0204@gmail.com>
Wed, 08 Mar 2017 11:43:24 +0800
changeset 348314 4796c44dda66b89f59c9a40a85534061d7aed578
parent 348313 b296196d185933d6fc4b893c9b9054a6883ea0e3
child 348315 540020bee3a69181f00d1ab059d6588f3c9a2cd8
push id88187
push userarchaeopteryx@coole-files.de
push dateSat, 18 Mar 2017 15:27:00 +0000
treeherdermozilla-inbound@0b1d3324cffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1332546
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1332546 - Apply default actionbar color r=sebastian 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