Bug 1185002 - Add custom active/inactive colors. r=sebastian, a=lizzard
authorChenxia Liu <liuche@mozilla.com>
Tue, 29 Sep 2015 17:10:32 -0400
changeset 296515 fe4f5ad3215f341701cade5251b51fbcd5225bbb
parent 296514 58436ea9519016e87630a77fbf35cf0e8b9a906a
child 296516 3b5587971ba2d9805c5062c1f9eb24b8aa8c256a
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1185002
milestone43.0a2
Bug 1185002 - Add custom active/inactive colors. r=sebastian, a=lizzard
mobile/android/base/home/TabMenuStripLayout.java
mobile/android/base/resources/layout/firstrun_pane.xml
mobile/android/base/resources/layout/home_pager.xml
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/home/TabMenuStripLayout.java
+++ b/mobile/android/base/home/TabMenuStripLayout.java
@@ -1,28 +1,29 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * 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/. */
 
 package org.mozilla.gecko.home;
 
+import android.widget.LinearLayout;
+
+import android.content.res.ColorStateList;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.util.ColorUtils;
 
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewTreeObserver;
 import android.view.accessibility.AccessibilityEvent;
-import android.widget.LinearLayout;
 import android.widget.TextView;
 
 /**
  * {@code TabMenuStripLayout} is the view that draws the {@code HomePager}
  * tabs that are displayed in {@code TabMenuStrip}.
  */
 class TabMenuStripLayout extends LinearLayout
                          implements View.OnFocusChangeListener {
@@ -36,56 +37,60 @@ class TabMenuStripLayout extends LinearL
     private View fromTab;
     private int fromPosition;
     private int toPosition;
     private float progress;
 
     // This variable is used to predict the direction of scroll.
     private float prevProgress;
     private int tabContentStart;
+    private int activeTextColor;
+    private ColorStateList inactiveTextColor;
 
     TabMenuStripLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabMenuStrip);
         final int stripResId = a.getResourceId(R.styleable.TabMenuStrip_strip, -1);
         tabContentStart = a.getDimensionPixelSize(R.styleable.TabMenuStrip_tabContentStart, 0);
+        activeTextColor = a.getColor(R.styleable.TabMenuStrip_activeTextColor, R.color.text_and_tabs_tray_grey);
+        inactiveTextColor = a.getColorStateList(R.styleable.TabMenuStrip_inactiveTextColor);
         a.recycle();
 
         if (stripResId != -1) {
             strip = getResources().getDrawable(stripResId);
         }
 
         setWillNotDraw(false);
     }
 
     void onAddPagerView(String title) {
         final TextView button = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.tab_menu_strip, this, false);
         button.setText(title.toUpperCase());
-        button.setTextColor(getResources().getColorStateList(R.color.tab_text_color));
+        button.setTextColor(inactiveTextColor);
 
         if (getChildCount() == 0) {
             button.setPadding(button.getPaddingLeft() + tabContentStart,
                               button.getPaddingTop(),
                               button.getPaddingRight(),
                               button.getPaddingBottom());
         }
 
         addView(button);
         button.setOnClickListener(new ViewClickListener(getChildCount() - 1));
         button.setOnFocusChangeListener(this);
     }
 
     void onPageSelected(final int position) {
         if (selectedView != null) {
-            selectedView.setTextColor(getResources().getColorStateList(R.color.tab_text_color));
+            selectedView.setTextColor(inactiveTextColor);
         }
 
         selectedView = (TextView) getChildAt(position);
-        selectedView.setTextColor(ColorUtils.getColor(getContext(), R.color.placeholder_grey));
+        selectedView.setTextColor(activeTextColor);
 
         // Callback to measure and draw the strip after the view is visible.
         ViewTreeObserver vto = selectedView.getViewTreeObserver();
         if (vto.isAlive()) {
             vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                 @Override
                 public void onGlobalLayout() {
                     selectedView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
--- a/mobile/android/base/resources/layout/firstrun_pane.xml
+++ b/mobile/android/base/resources/layout/firstrun_pane.xml
@@ -16,12 +16,14 @@
                     android:layout_height="match_parent"
                     android:background="@color/firstrun_pager_background">
 
         <org.mozilla.gecko.home.TabMenuStrip android:layout_width="match_parent"
                                              android:layout_height="@dimen/tabs_strip_height"
                                              android:background="@color/firstrun_tabstrip"
                                              android:visibility="visible"
                                              android:layout_gravity="top"
-                                             gecko:strip="@drawable/home_tab_menu_strip"/>
+                                             gecko:strip="@drawable/home_tab_menu_strip"
+                                             gecko:activeTextColor="@android:color/white"
+                                             gecko:inactiveTextColor="@color/divider_light" />
 
     </org.mozilla.gecko.firstrun.FirstrunPager>
 </org.mozilla.gecko.firstrun.FirstrunPane>
--- a/mobile/android/base/resources/layout/home_pager.xml
+++ b/mobile/android/base/resources/layout/home_pager.xml
@@ -13,11 +13,13 @@
                                   android:layout_height="match_parent"
                                   android:background="@android:color/white">
 
     <org.mozilla.gecko.home.TabMenuStrip android:layout_width="match_parent"
                                          android:layout_height="@dimen/tabs_strip_height"
                                          android:background="@color/about_page_header_grey"
                                          android:layout_gravity="top"
                                          gecko:strip="@drawable/home_tab_menu_strip"
+                                         gecko:activeTextColor="@color/placeholder_grey"
+                                         gecko:inactiveTextColor="@color/tab_text_color"
                                          gecko:tabContentStart="@dimen/tab_strip_content_start" />
 
 </org.mozilla.gecko.home.HomePager>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -162,16 +162,18 @@
     <declare-styleable name="TopSitesGridView">
         <attr name="android:horizontalSpacing"/>
         <attr name="android:verticalSpacing"/>
     </declare-styleable>
 
     <declare-styleable name="TabMenuStrip">
         <attr name="strip" format="reference"/>
         <attr name="tabContentStart" format="dimension" />
+        <attr name="activeTextColor" format="color" />
+        <attr name="inactiveTextColor" format="color" />
     </declare-styleable>
 
     <declare-styleable name="TabPanelBackButton">
         <attr name="rightDivider" format="reference"/>
         <attr name="dividerVerticalPadding" format="dimension"/>
     </declare-styleable>
 
     <declare-styleable name="EllipsisTextView">