Bug 1179479 - Tint color of easy-to-do tablet toolbar icons. r=mhaigh, a=sledru
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 23 Jul 2015 15:18:23 -0700
changeset 277183 d393cac4e944316a0cb757a4bdac23a971536631
parent 277182 d4cbcd9fff58d07dfc454d28cb56f0601ba22031
child 277184 677cba8fd20b956f7878f61a3bc87a8a8e0564ad
push id8326
push userryanvm@gmail.com
push dateTue, 18 Aug 2015 21:38:05 +0000
treeherdermozilla-aurora@4345fbf90ea4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhaigh, sledru
bugs1179479
milestone42.0a2
Bug 1179479 - Tint color of easy-to-do tablet toolbar icons. r=mhaigh, a=sledru This first patch is intentionally simple and incomplete. Still TODO: * Bookmarks icon (on xlarge tablets) * Magnifying glass in the browser toolbar * Hit areas
mobile/android/base/resources/color-large-v11/tabs_counter_text_color.xml
mobile/android/base/resources/layout-large-v11/new_tablet_tabs_counter.xml
mobile/android/base/toolbar/BrowserToolbarTabletBase.java
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/color-large-v11/tabs_counter_text_color.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:gecko="http://schemas.android.com/apk/res-auto">
+
+    <item gecko:state_private="true"
+          android:color="@color/tabs_tray_grey_pressed"/>
+
+    <item android:color="@color/toolbar_grey"/>
+
+</selector>
\ No newline at end of file
--- a/mobile/android/base/resources/layout-large-v11/new_tablet_tabs_counter.xml
+++ b/mobile/android/base/resources/layout-large-v11/new_tablet_tabs_counter.xml
@@ -5,12 +5,12 @@
 
 <org.mozilla.gecko.widget.ThemedTextView xmlns:android="http://schemas.android.com/apk/res/android"
                                          android:layout_width="24dip"
                                          android:layout_height="24dip"
                                          android:paddingTop="3dip"
                                          android:paddingLeft="4dip"
                                          android:background="@drawable/new_tablet_tabs_count_foreground"
                                          android:textAppearance="@style/TextAppearance.Micro"
-                                         android:textColor="@color/toolbar_grey"
+                                         android:textColor="@color/tabs_counter_text_color"
                                          android:textStyle="bold"
                                          android:duplicateParentState="true"
                                          android:gravity="center"/>
--- a/mobile/android/base/toolbar/BrowserToolbarTabletBase.java
+++ b/mobile/android/base/toolbar/BrowserToolbarTabletBase.java
@@ -7,18 +7,21 @@ package org.mozilla.gecko.toolbar;
 
 import java.util.Arrays;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.tabs.TabHistoryController;
 import org.mozilla.gecko.menu.MenuItemActionBar;
+import org.mozilla.gecko.widget.ThemedTextView;
 
 import android.content.Context;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
 
 /**
@@ -32,16 +35,18 @@ abstract class BrowserToolbarTabletBase 
         HIDE
     }
 
     protected final LinearLayout actionItemBar;
 
     protected final BackButton backButton;
     protected final ForwardButton forwardButton;
 
+    private final PorterDuffColorFilter privateBrowsingTabletMenuItemColorFilter;
+
     protected abstract void animateForwardButton(ForwardButtonAnimation animation);
 
     public BrowserToolbarTabletBase(final Context context, final AttributeSet attrs) {
         super(context, attrs);
 
         actionItemBar = (LinearLayout) findViewById(R.id.menu_items);
 
         backButton = (BackButton) findViewById(R.id.back);
@@ -50,16 +55,19 @@ abstract class BrowserToolbarTabletBase 
         setButtonEnabled(forwardButton, false);
         initButtonListeners();
 
         focusOrder.addAll(Arrays.asList(tabsButton, (View) backButton, (View) forwardButton, this));
         focusOrder.addAll(urlDisplayLayout.getFocusOrder());
         focusOrder.addAll(Arrays.asList(actionItemBar, menuButton));
 
         urlDisplayLayout.updateSiteIdentityAnchor(backButton);
+
+        privateBrowsingTabletMenuItemColorFilter = new PorterDuffColorFilter(
+                getResources().getColor(R.color.tabs_tray_icon_grey), PorterDuff.Mode.SRC_IN);
     }
 
     private void initButtonListeners() {
         backButton.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Tabs.getInstance().getSelectedTab().doBack();
             }
@@ -116,24 +124,50 @@ abstract class BrowserToolbarTabletBase 
         backButton.setNextFocusDownId(nextId);
         forwardButton.setNextFocusDownId(nextId);
     }
 
     @Override
     public void setPrivateMode(final boolean isPrivate) {
         super.setPrivateMode(isPrivate);
 
+        // Better done with android:tint but it doesn't take a ColorStateList:
+        //   https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=18220
+        // Nor can we use DrawableCompat because the drawables (as opposed
+        // to the Views) don't receive gecko:state_private.
+        final PorterDuffColorFilter colorFilter =
+                isPrivate ? privateBrowsingTabletMenuItemColorFilter : null;
+        backButton.setColorFilter(colorFilter);
+        forwardButton.setColorFilter(colorFilter);
+        setTabsCounterPrivateMode(isPrivate, colorFilter);
+        menuIcon.setColorFilter(colorFilter);
+
         backButton.setPrivateMode(isPrivate);
         forwardButton.setPrivateMode(isPrivate);
         for (int i = 0; i < actionItemBar.getChildCount(); ++i) {
             final MenuItemActionBar child = (MenuItemActionBar) actionItemBar.getChildAt(i);
             child.setPrivateMode(isPrivate);
+            child.setColorFilter(colorFilter);
         }
     }
 
+    private void setTabsCounterPrivateMode(final boolean isPrivate, final PorterDuffColorFilter colorFilter) {
+        // The TabsCounter is a TextSwitcher which cycles two views
+        // to provide animations, hence looping over these two children.
+        for (int i = 0; i < 2; ++i) {
+            final ThemedTextView view = (ThemedTextView) tabsCounter.getChildAt(i);
+            view.setPrivateMode(isPrivate);
+            view.getBackground().mutate().setColorFilter(colorFilter);
+        }
+
+        // To prevent animation of the background,
+        // it is set to a different Drawable.
+        tabsCounter.getBackground().mutate().setColorFilter(colorFilter);
+    }
+
     @Override
     public View getDoorHangerAnchor() {
         return backButton;
     }
 
     protected boolean canDoBack(final Tab tab) {
         return (tab.canDoBack() && !isEditing());
     }