Bug 843313: Make the icon a compound drawable for the menu-item's text. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 20 Feb 2013 23:07:05 -0800
changeset 122516 4afe5b64b2320a4f2b59dc30defe28b984d17490
parent 122515 0a9618b1dd2ae8a707a41dd174d1b60bd2ab6295
child 122517 7047fe1649c72b608c2cb8dece8cba66d246e01a
push id24342
push userryanvm@gmail.com
push dateThu, 21 Feb 2013 13:05:06 +0000
treeherdermozilla-central@702d2814efbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs843313
milestone22.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 843313: Make the icon a compound drawable for the menu-item's text. [r=mfinkle]
mobile/android/base/MenuItemDefault.java
mobile/android/base/resources/layout/menu_item.xml
mobile/android/base/resources/values/dimens.xml
--- a/mobile/android/base/MenuItemDefault.java
+++ b/mobile/android/base/MenuItemDefault.java
@@ -1,92 +1,101 @@
 /* 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;
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.AbsListView;
 import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class MenuItemDefault extends LinearLayout
                              implements GeckoMenuItem.Layout {
     private static final String LOGTAG = "GeckoMenuItemDefault";
+    private static Rect sIconBounds;
 
-    private ImageView mIcon;
     private TextView mTitle;
     private CheckBox mCheck;
     private ImageView mMore;
 
+    private Drawable mIcon;
     private boolean mCheckable;
     private boolean mChecked;
     private boolean mHasSubMenu;
 
     public MenuItemDefault(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         Resources res = context.getResources();
         setLayoutParams(new AbsListView.LayoutParams((int) (res.getDimension(R.dimen.menu_item_row_width)),
                                                      (int) (res.getDimension(R.dimen.menu_item_row_height))));
 
         inflate(context, R.layout.menu_item, this);
-        mIcon = (ImageView) findViewById(R.id.icon);
         mTitle = (TextView) findViewById(R.id.title);
         mCheck = (CheckBox) findViewById(R.id.check);
         mMore = (ImageView) findViewById(R.id.more);
 
         mCheckable = false;
         mChecked = false;
         mHasSubMenu = false;
+
+        if (sIconBounds == null) {
+            int iconSize = res.getDimensionPixelSize(R.dimen.menu_item_icon);
+            sIconBounds = new Rect(0, 0, iconSize, iconSize);
+        }
     }
 
     @Override
     public View getLayout() {
         return this;
     }
 
     @Override
     public void setIcon(Drawable icon) {
-        if (icon != null) {
-            mIcon.setImageDrawable(icon);
-            mIcon.setVisibility(VISIBLE);
-        } else {
-            mIcon.setVisibility(GONE);
-        }
+        mIcon = icon;
+
+        if (mIcon != null)
+            mIcon.setBounds(sIconBounds);
+
+        mTitle.setCompoundDrawables(mIcon, null, null, null);
     }
 
     @Override
     public void setIcon(int icon) {
-        if (icon != 0) {
-            mIcon.setImageResource(icon);
-            mIcon.setVisibility(VISIBLE);
-        } else {
-            mIcon.setVisibility(GONE);
-        }
+        Drawable drawable = null;
+
+        if (icon != 0)
+            drawable = getContext().getResources().getDrawable(icon);
+         
+        setIcon(drawable);
     }
 
     @Override
     public void setTitle(CharSequence title) {
         mTitle.setText(title);
     }
 
     @Override
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
         mTitle.setEnabled(enabled);
+
+        if (mIcon != null)
+            mIcon.setAlpha(enabled ? 255 : 99);
+
         mCheck.setEnabled(enabled);
-        mIcon.setColorFilter(enabled ? 0 : 0xFF999999);
         mMore.setColorFilter(enabled ? 0 : 0xFF999999);
     }
 
     @Override
     public void setCheckable(boolean checkable) {
         mCheckable = checkable;
         mCheck.setVisibility(mCheckable && !mHasSubMenu ? VISIBLE : GONE);
     }
--- a/mobile/android/base/resources/layout/menu_item.xml
+++ b/mobile/android/base/resources/layout/menu_item.xml
@@ -1,35 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
 
-     <View android:layout_width="10dp"
-           android:layout_height="fill_parent"
-           android:layout_gravity="center_vertical"/>
-
-     <ImageView android:id="@+id/icon"
-                android:layout_width="27dp"
-                android:layout_height="21dp"
-                android:paddingRight="6dp"
-                android:layout_gravity="center_vertical"
-                android:visibility="gone"/>
-
      <TextView android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
+               android:layout_marginLeft="10dp"
                android:textSize="16sp"
                android:textColor="@color/menu_item_title"
                android:singleLine="true"
                android:ellipsize="middle"
-               android:layout_gravity="center_vertical"/>
+               android:layout_gravity="center_vertical"
+               android:drawablePadding="6dp"/>
 
      <FrameLayout android:layout_width="18dp"
                   android:layout_height="18dp"
                   android:layout_marginBottom="2dp"
+                  android:layout_marginRight="10dp"
                   android:layout_gravity="center_vertical">
 
          <CheckBox android:id="@+id/check"
                    android:layout_width="18dp"
                    android:layout_height="18dp"
                    android:button="@drawable/menu_item_checkmark"
                    android:focusable="false"
                    android:clickable="false"
@@ -38,13 +30,9 @@
          <ImageView android:id="@+id/more"
                    android:layout_width="18dp"
                    android:layout_height="18dp"
                    android:src="@drawable/menu_item_more"
                    android:visibility="gone"/>
 
      </FrameLayout>
 
-     <View android:layout_width="10dp"
-           android:layout_height="fill_parent"
-           android:layout_gravity="center_vertical"/>
-
 </merge>
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -24,16 +24,17 @@
     <dimen name="awesomebar_tab_transparency_height">38dp</dimen>
     <dimen name="browser_toolbar_height">48dp</dimen>
     <dimen name="browser_toolbar_button_padding">12dp</dimen>
     <dimen name="browser_toolbar_icon_width">36dp</dimen>
     <dimen name="browser_toolbar_lock_width">20dp</dimen>
     <dimen name="browser_toolbar_favicon_size">29.33dip</dimen>
     <dimen name="doorhanger_arrow_width">44dp</dimen>
     <dimen name="flow_layout_spacing">6dp</dimen>
+    <dimen name="menu_item_icon">21dp</dimen>
     <dimen name="menu_item_row_height">44dp</dimen>
     <dimen name="menu_item_row_width">240dp</dimen>
     <dimen name="menu_popup_arrow_margin">5dip</dimen>
     <dimen name="menu_popup_arrow_width">40dip</dimen>
     <dimen name="menu_popup_offset">8dp</dimen>
     <dimen name="menu_popup_width">256dp</dimen>
     <dimen name="nav_button_border_width">0.75dp</dimen>
     <dimen name="prompt_service_group_padding_size">32dp</dimen>