Bug 822421: Lightweight theme based text colors on about:home. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Mon, 17 Dec 2012 12:31:52 -0800
changeset 125659 65b79c7b41050b2340eac68844eb77b8586c47bf
parent 125658 bafbc8d9c6b8bd686e0e36d40aa6f9ee600e1ba7
child 125660 7ecc2913a1e6d8475bfd2ebb6681a65eeac47246
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs822421
milestone20.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 822421: Lightweight theme based text colors on about:home. [r=mfinkle]
mobile/android/base/AboutHomeContent.java
mobile/android/base/AboutHomeSection.java
mobile/android/base/GeckoView.java.frag
mobile/android/base/LightweightTheme.java
mobile/android/base/Makefile.in
mobile/android/base/resources/color/abouthome_section_more_text.xml.in
mobile/android/base/resources/color/abouthome_section_subtitle.xml.in
mobile/android/base/resources/color/abouthome_section_title.xml.in
mobile/android/base/resources/layout-xlarge-land-v11/abouthome_content.xml.in
mobile/android/base/resources/layout/abouthome_addon_row.xml
mobile/android/base/resources/layout/abouthome_content.xml.in
mobile/android/base/resources/layout/abouthome_last_tabs_row.xml
mobile/android/base/resources/layout/abouthome_remote_tab_row.xml
mobile/android/base/resources/layout/abouthome_section.xml
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -684,21 +684,37 @@ public class AboutHomeContent extends Sc
     @Override
     public void onLightweightThemeChanged() {
         LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this);
         if (drawable == null)
             return;
 
          drawable.setAlpha(255, 0);
          setBackgroundDrawable(drawable);
+
+         boolean isLight = mActivity.getLightweightTheme().isLightTheme();
+
+         if (mAddons != null) {
+             mAddons.setTheme(isLight);
+             mLastTabs.setTheme(isLight);
+             mRemoteTabs.setTheme(isLight);
+             ((GeckoTextView) findViewById(R.id.top_sites_title)).setTheme(isLight);
+         }
     }
 
     @Override
     public void onLightweightThemeReset() {
         setBackgroundResource(R.drawable.abouthome_bg_repeat);
+
+        if (mAddons != null) {
+            mAddons.resetTheme();
+            mLastTabs.resetTheme();
+            mRemoteTabs.resetTheme();
+            ((GeckoTextView) findViewById(R.id.top_sites_title)).resetTheme();
+        }
     }
 
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         super.onLayout(changed, left, top, right, bottom);
         onLightweightThemeChanged();
     }
 
--- a/mobile/android/base/AboutHomeSection.java
+++ b/mobile/android/base/AboutHomeSection.java
@@ -8,17 +8,17 @@ import android.content.Context;
 import android.content.res.TypedArray;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
-public class AboutHomeSection extends LinearLayout {
+public class AboutHomeSection extends GeckoLinearLayout {
     private static final String LOGTAG = "GeckoAboutHomeSection";
 
     private TextView mTitle;
     private TextView mSubtitle;
     private LinearLayout mItemsContainer;
     private LinkTextView mMoreText;
 
     public AboutHomeSection(Context context, AttributeSet attrs) {
--- a/mobile/android/base/GeckoView.java.frag
+++ b/mobile/android/base/GeckoView.java.frag
@@ -5,36 +5,68 @@
 package org.mozilla.gecko;
 
 import android.content.Context;
 import android.util.AttributeSet;
 import android.widget.@VIEWTYPE@;
 
 public class Gecko@VIEWTYPE@ extends @VIEWTYPE@ {
     private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
+    private static final int[] STATE_LIGHT = { R.attr.state_light };
+    private static final int[] STATE_DARK = { R.attr.state_dark };
 
     private boolean mIsPrivate = false;
+    private boolean mIsLight = false;
+    private boolean mIsDark = false;
 
     public Gecko@VIEWTYPE@(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
 
     @Override
     public int[] onCreateDrawableState(int extraSpace) {
         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
 
         if (mIsPrivate)
             mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
+        else if (mIsLight)
+            mergeDrawableStates(drawableState, STATE_LIGHT);
+        else if (mIsDark)
+            mergeDrawableStates(drawableState, STATE_DARK);
 
         return drawableState;
     }
 
     public boolean isPrivateMode() {
         return mIsPrivate;
     }
 
     public void setPrivateMode(boolean isPrivate) {
         if (mIsPrivate != isPrivate) {
             mIsPrivate = isPrivate;
             refreshDrawableState();
         }
-   }
+    }
+
+    public void setTheme(boolean isLight) {
+        // Set the theme only if it is different from existing theme.
+        if ((isLight && mIsLight != isLight) ||
+            (!isLight && mIsDark == isLight)) {
+            if (isLight) {
+                mIsLight = true;
+                mIsDark = false;
+            } else {
+                mIsLight = false;
+                mIsDark = true;
+            }
+
+            refreshDrawableState();
+        }
+    }
+
+    public void resetTheme() {
+        if (mIsLight || mIsDark) {
+            mIsLight = false;
+            mIsDark = false;
+            refreshDrawableState();
+        }
+    } 
 }
--- a/mobile/android/base/LightweightTheme.java
+++ b/mobile/android/base/LightweightTheme.java
@@ -37,16 +37,17 @@ import java.util.ArrayList;
 import android.util.Log;
 
 public class LightweightTheme implements GeckoEventListener {
     private static final String LOGTAG = "GeckoLightweightTheme";
 
     private Application mApplication;
     private Bitmap mBitmap;
     private int mColor;
+    private boolean mIsLight;
 
     public static interface OnChangeListener {
         // This is the View's default post.
         // This is required to post the change/rest on UI thread.
         public boolean post(Runnable action);
 
         // The View should change its background/text color. 
         public void onLightweightThemeChanged();
@@ -93,16 +94,21 @@ public class LightweightTheme implements
             DisplayMetrics dm = mApplication.getResources().getDisplayMetrics();
             int maxWidth = Math.max(dm.widthPixels, dm.heightPixels);
             int height = (int) (mBitmap.getHeight() * 0.25);
             Bitmap cropped = Bitmap.createBitmap(mBitmap, mBitmap.getWidth() - maxWidth,
                                                           mBitmap.getHeight() - height, 
                                                           maxWidth, height);
             mColor = BitmapUtils.getDominantColor(cropped, false);
 
+            double luminance = (0.2125 * ((mColor & 0x00FF0000) >> 16)) + 
+                               (0.7154 * ((mColor & 0x0000FF00) >> 8)) + 
+                               (0.0721 * (mColor &0x000000FF));
+            mIsLight = (luminance > 110) ? true : false;
+
             notifyListeners();
         } catch(java.net.MalformedURLException e) {
             mBitmap = null;
         } catch(java.io.IOException e) {
             mBitmap = null;
         }
     }
 
@@ -151,16 +157,20 @@ public class LightweightTheme implements
             } else if (event.equals("LightweightTheme:Disable")) {
                 resetLightweightTheme();
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
         }
     }
 
+    public boolean isLightTheme() {
+        return mIsLight;
+    }
+
     /**
      * Crop the image based on the position of the view on the window.
      * Either the View or one of its ancestors might have scrolled or translated.
      * This value should be taken into account while mapping the View to the Bitmap.
      *
      * @param view The view requesting a cropped bitmap.
      */
     private Bitmap getCroppedBitmap(View view) {
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -222,16 +222,19 @@ FENNEC_PP_JAVA_FILES = \
   db/FormHistoryProvider.java \
   db/TabsProvider.java \
   db/GeckoProvider.java \
   SmsManager.java \
   UpdateServiceHelper.java \
   $(NULL)
 
 FENNEC_PP_XML_FILES = \
+  res/color/abouthome_section_more_text.xml \
+  res/color/abouthome_section_subtitle.xml \
+  res/color/abouthome_section_title.xml \
   res/color/awesome_bar_title.xml \
   res/color/awesome_bar_title_hint.xml \
   res/drawable/address_bar_bg.xml \
   res/drawable/address_bar_nav_button.xml \
   res/drawable/address_bar_url.xml \
   res/drawable/awesomebar_tabs_bg.xml \
   res/drawable/menu_level.xml \
   res/layout/abouthome_content.xml \
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/color/abouthome_section_more_text.xml.in
@@ -0,0 +1,19 @@
+#filter substitution
+<?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/@ANDROID_PACKAGE_NAME@">
+
+    <!-- dark theme -->
+    <item gecko:state_dark="true" android:color="#80FFFFFF" />
+
+    <!-- light theme -->
+    <item gecko:state_light="true" android:color="#80222222" />
+
+    <!-- default -->
+    <item android:color="#FF22629E"/>
+
+</selector>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/color/abouthome_section_subtitle.xml.in
@@ -0,0 +1,19 @@
+#filter substitution
+<?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/@ANDROID_PACKAGE_NAME@">
+
+    <!-- dark theme -->
+    <item gecko:state_dark="true" android:color="#CCFFFFFF" />
+
+    <!-- light theme -->
+    <item gecko:state_light="true" android:color="#CC222222" />
+
+    <!-- default -->
+    <item android:color="#FF666666"/>
+
+</selector>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/color/abouthome_section_title.xml.in
@@ -0,0 +1,19 @@
+#filter substitution
+<?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/@ANDROID_PACKAGE_NAME@">
+
+    <!-- dark theme -->
+    <item gecko:state_dark="true" android:color="#FFFFFFFF" />
+
+    <!-- light theme -->
+    <item gecko:state_light="true" android:color="#FF222222" />
+
+    <!-- default -->
+    <item android:color="#FF000000"/>
+
+</selector>
--- a/mobile/android/base/resources/layout-xlarge-land-v11/abouthome_content.xml.in
+++ b/mobile/android/base/resources/layout-xlarge-land-v11/abouthome_content.xml.in
@@ -20,26 +20,26 @@
 
             <ImageView android:src="@drawable/abouthome_logo"
                        android:layout_width="wrap_content"
                        android:layout_height="24dip"
                        android:layout_marginTop="16dip"
                        android:layout_marginBottom="10dip"
                        android:layout_marginLeft="12dip"/>
 
-            <TextView android:id="@+id/top_sites_title"
-                      android:text="@string/abouthome_top_sites_title"
-                      android:layout_width="fill_parent"
-                      android:layout_height="26dip"
-                      android:background="#34FFFFFF"
-                      android:paddingLeft="12dip"
-                      android:textSize="12sp"
-                      android:textColor="#000000"
-                      android:textStyle="bold"
-                      android:gravity="left|center_vertical"/>
+            <Gecko.TextView android:id="@+id/top_sites_title"
+                            android:text="@string/abouthome_top_sites_title"
+                            android:layout_width="fill_parent"
+                            android:layout_height="26dip"
+                            android:background="#34FFFFFF"
+                            android:paddingLeft="12dip"
+                            android:textSize="12sp"
+                            android:textColor="@color/abouthome_section_title"
+                            android:textStyle="bold"
+                            android:gravity="left|center_vertical"/>
 
             <view class="org.mozilla.gecko.AboutHomeContent$TopSitesGridView"
                   android:id="@+id/top_sites_grid"
                   style="@style/AboutHome.Thumbnail.Grid"/>
 
             <org.mozilla.gecko.AboutHomePromoBox android:id="@+id/promo_box"
                                                  android:orientation="horizontal"
                                                  android:background="@drawable/abouthome_promo_box"
--- a/mobile/android/base/resources/layout/abouthome_addon_row.xml
+++ b/mobile/android/base/resources/layout/abouthome_addon_row.xml
@@ -2,42 +2,45 @@
 <!-- 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/. -->
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="fill_parent"
                 android:layout_height="47dip"
                 android:gravity="left|center_vertical"
-                android:background="@drawable/action_bar_button">
+                android:background="@drawable/action_bar_button"
+                android:duplicateParentState="true">
 
     <ImageView android:id="@+id/addon_icon"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dip"
                android:src="@drawable/ic_addons_empty"/>
 
     <TextView android:id="@+id/addon_title"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_toRightOf="@id/addon_icon"
               android:layout_marginLeft="12dip"
               android:gravity="center_vertical"
               android:textSize="15sp"
-              android:textColor="#222222"/>
+              android:textColor="@color/abouthome_section_title"
+              android:duplicateParentState="true"/>
 
     <TextView android:id="@+id/addon_version"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_toRightOf="@id/addon_title"
               android:layout_alignBottom="@id/addon_title"
               android:layout_marginLeft="5dip"
               android:gravity="center_vertical"
               android:textSize="12sp"
-              android:textColor="#666666"/>
+              android:textColor="@color/abouthome_section_subtitle"
+              android:duplicateParentState="true"/>
 
     <View android:layout_width="fill_parent"
           android:layout_height="1dp"
           android:background="@drawable/abouthome_divider"
           android:layout_alignParentBottom="true"/>
 
 </RelativeLayout>
--- a/mobile/android/base/resources/layout/abouthome_content.xml.in
+++ b/mobile/android/base/resources/layout/abouthome_content.xml.in
@@ -17,27 +17,27 @@
                    android:layout_width="wrap_content"
                    android:layout_height="24dip"
                    android:layout_marginTop="16dip"
                    android:layout_marginBottom="10dip"
                    android:layout_marginLeft="12dip"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"/>
 
-        <TextView android:id="@+id/top_sites_title"
-                  android:text="@string/abouthome_top_sites_title"
-                  android:layout_width="fill_parent"
-                  android:layout_height="26dip"
-                  android:background="#34FFFFFF"
-                  android:paddingLeft="12dip"
-                  android:textSize="12sp"
-                  android:textColor="#000000"
-                  android:textStyle="bold"
-                  android:gravity="left|center_vertical"
-                  android:layout_below="@id/abouthome_logo"/>
+        <Gecko.TextView android:id="@+id/top_sites_title"
+                        android:text="@string/abouthome_top_sites_title"
+                        android:layout_width="fill_parent"
+                        android:layout_height="26dip"
+                        android:background="#34FFFFFF"
+                        android:paddingLeft="12dip"
+                        android:textSize="12sp"
+                        android:textColor="@color/abouthome_section_title"
+                        android:textStyle="bold"
+                        android:gravity="left|center_vertical"
+                        android:layout_below="@id/abouthome_logo"/>
 
         <ImageView android:src="@drawable/abouthome_icon"
                    android:layout_width="180dp"
                    android:layout_height="153dp"
                    android:layout_marginTop="4dp"
                    android:layout_marginRight="@dimen/abouthome_icon_crop"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentRight="true"/>
--- a/mobile/android/base/resources/layout/abouthome_last_tabs_row.xml
+++ b/mobile/android/base/resources/layout/abouthome_last_tabs_row.xml
@@ -3,17 +3,18 @@
    - 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/. -->
 
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="fill_parent"
                 android:layout_height="47dip"
                 android:gravity="left|center_vertical"
-                android:background="@drawable/action_bar_button">
+                android:background="@drawable/action_bar_button"
+                android:duplicateParentState="true">
 
     <ImageView android:id="@+id/last_tab_favicon"
                android:layout_width="32dip"
                android:layout_height="32dip"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dip"
                android:src="@drawable/favicon"/>
 
@@ -21,27 +22,29 @@
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_toRightOf="@id/last_tab_favicon"
               android:layout_marginTop="2dip"
               android:layout_marginLeft="12dip"
               android:layout_marginRight="12dip"
               android:textSize="15sp"
               android:singleLine="true"
-              android:textColor="#222222"/>
+              android:textColor="@color/abouthome_section_title"
+              android:duplicateParentState="true"/>
 
     <TextView android:id="@+id/last_tab_url"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="12dip"
               android:layout_marginRight="12dip"
               android:layout_toRightOf="@id/last_tab_favicon"
               android:layout_below="@id/last_tab_title"
               android:textSize="12sp"
               android:singleLine="true"
-              android:textColor="#666666"/>
+              android:textColor="@color/abouthome_section_subtitle"
+              android:duplicateParentState="true"/>
 
     <View android:layout_width="fill_parent"
           android:layout_height="1dp"
           android:background="@drawable/abouthome_divider"
           android:layout_alignParentBottom="true"/>
 
 </RelativeLayout>
--- a/mobile/android/base/resources/layout/abouthome_remote_tab_row.xml
+++ b/mobile/android/base/resources/layout/abouthome_remote_tab_row.xml
@@ -2,27 +2,29 @@
 <!-- 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/. -->
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="fill_parent"
                 android:layout_height="47dip"
                 android:orientation="vertical"
-                android:background="@drawable/action_bar_button">
+                android:background="@drawable/action_bar_button"
+                android:duplicateParentState="true">
 
     <TextView android:id="@+id/remote_tab_title"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:paddingLeft="12dip"
               android:paddingRight="12dip"
               android:gravity="center_vertical"
               android:textSize="15sp"
-              android:textColor="#222222"
               android:singleLine="true"
-              android:ellipsize="middle"/>
+              android:ellipsize="middle"
+              android:textColor="@color/abouthome_section_title"
+              android:duplicateParentState="true"/>
 
     <View android:layout_width="fill_parent"
           android:layout_height="1dp"
           android:background="@drawable/abouthome_divider"
           android:layout_alignParentBottom="true"/>
 
 </RelativeLayout>
--- a/mobile/android/base/resources/layout/abouthome_section.xml
+++ b/mobile/android/base/resources/layout/abouthome_section.xml
@@ -6,36 +6,40 @@
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
 
     <TextView android:id="@+id/title"
               android:layout_width="fill_parent"
               android:layout_height="26dip"
               android:background="#34FFFFFF"
               android:paddingLeft="12dip"
               android:textSize="12sp"
-              android:textColor="#000000"
+              android:textColor="@color/abouthome_section_title"
               android:textStyle="bold"
-              android:gravity="left|center_vertical"/>
+              android:gravity="left|center_vertical"
+              android:duplicateParentState="true"/>
 
     <TextView android:id="@+id/subtitle"
               android:layout_width="fill_parent"
               android:layout_height="26dip"
               android:layout_marginTop="1dip"
               android:background="#34FFFFFF"
               android:paddingLeft="12dip"
               android:textSize="12sp"
-              android:textColor="#666666"
-              android:gravity="left|center_vertical"/>
+              android:textColor="@color/abouthome_section_subtitle"
+              android:gravity="left|center_vertical"
+              android:duplicateParentState="true"/>
 
     <LinearLayout android:id="@+id/items_container"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:orientation="vertical"
-                  android:isScrollContainer="false"/>
+                  android:isScrollContainer="false"
+                  android:duplicateParentState="true"/>
 
     <org.mozilla.gecko.LinkTextView android:id="@+id/more_text"
                                     android:layout_width="fill_parent"
                                     android:layout_height="47dip"
-                                    android:textColor="#22629e"
+                                    android:textColor="@color/abouthome_section_more_text"
                                     android:textSize="12sp"
-                                    android:gravity="center"/>
+                                    android:gravity="center"
+                                    android:duplicateParentState="true"/>
 
 </merge>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -56,10 +56,15 @@
             <flag name="end" value="0x03" />
         </attr>
     </declare-styleable>
 
     <declare-styleable name="PrivateBrowsing">
         <attr name="state_private" format="boolean"/>
     </declare-styleable>
 
+    <declare-styleable name="LightweightTheme">
+        <attr name="state_light" format="boolean"/>
+        <attr name="state_dark" format="boolean"/>
+    </declare-styleable>
+
 </resources>