Bug 843313: Make the checkbox/more icon to be a compound drawable of the menu item's text. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 20 Feb 2013 23:07:06 -0800
changeset 122516 7047fe1649c72b608c2cb8dece8cba66d246e01a
parent 122515 4afe5b64b2320a4f2b59dc30defe28b984d17490
child 122517 88b94a88ea029810d171611871b67196a7ee3fab
push id23342
push usersramasubramanian@mozilla.com
push dateThu, 21 Feb 2013 07:07:50 +0000
treeherdermozilla-inbound@393bed39e9ab [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 checkbox/more icon to be a compound drawable of 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
@@ -13,63 +13,75 @@ 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 static Drawable sChecked;
+    private static Drawable sUnChecked;
+    private static Drawable sMore;
 
     private TextView mTitle;
-    private CheckBox mCheck;
-    private ImageView mMore;
 
     private Drawable mIcon;
+    private Drawable mState;
+
     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);
         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);
+
+            int stateIconSize = res.getDimensionPixelSize(R.dimen.menu_item_state_icon);
+            Rect stateIconBounds = new Rect(0, 0, stateIconSize, stateIconSize);
+
+            sChecked = res.getDrawable(R.drawable.menu_item_check);
+            sChecked.setBounds(stateIconBounds);
+
+            sUnChecked = res.getDrawable(R.drawable.menu_item_uncheck);
+            sUnChecked.setBounds(stateIconBounds);
+
+            sMore = res.getDrawable(R.drawable.menu_item_more);
+            sMore.setBounds(stateIconBounds);
         }
     }
 
     @Override
     public View getLayout() {
         return this;
     }
 
     @Override
     public void setIcon(Drawable icon) {
         mIcon = icon;
 
         if (mIcon != null)
             mIcon.setBounds(sIconBounds);
 
-        mTitle.setCompoundDrawables(mIcon, null, null, null);
+        mTitle.setCompoundDrawables(mIcon, null, mState, null);
     }
 
     @Override
     public void setIcon(int icon) {
         Drawable drawable = null;
 
         if (icon != 0)
             drawable = getContext().getResources().getDrawable(icon);
@@ -85,31 +97,44 @@ public class MenuItemDefault extends Lin
     @Override
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
         mTitle.setEnabled(enabled);
 
         if (mIcon != null)
             mIcon.setAlpha(enabled ? 255 : 99);
 
-        mCheck.setEnabled(enabled);
-        mMore.setColorFilter(enabled ? 0 : 0xFF999999);
+        if (mState != null)
+            mState.setAlpha(enabled ? 255 : 99);
     }
 
     @Override
     public void setCheckable(boolean checkable) {
         mCheckable = checkable;
-        mCheck.setVisibility(mCheckable && !mHasSubMenu ? VISIBLE : GONE);
+        refreshState();
+    }
+
+    private void refreshState() {
+        if (mHasSubMenu)
+            mState = sMore;
+        else if (mCheckable && mChecked)
+            mState = sChecked;
+        else if (mCheckable && !mChecked)
+            mState = sUnChecked;
+        else
+            mState = null;
+
+        mTitle.setCompoundDrawables(mIcon, null, mState, null);
     }
 
     @Override
     public void setChecked(boolean checked) {
         mChecked = checked;
-        mCheck.setChecked(mChecked);
+        refreshState();
     }
 
     @Override
     public void setSubMenuIndicator(boolean hasSubMenu) {
         mHasSubMenu = hasSubMenu;
-        mMore.setVisibility(mHasSubMenu ? VISIBLE : GONE);
-        mCheck.setVisibility(mCheckable && !mHasSubMenu ? VISIBLE : GONE);
+        mState = sMore;
+        refreshState();
     }
 }
--- a/mobile/android/base/resources/layout/menu_item.xml
+++ b/mobile/android/base/resources/layout/menu_item.xml
@@ -1,38 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
 
      <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:layout_marginRight="10dp"
                android:textSize="16sp"
                android:textColor="@color/menu_item_title"
                android:singleLine="true"
                android:ellipsize="middle"
                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"
-                   android:visibility="gone"/>
-
-         <ImageView android:id="@+id/more"
-                   android:layout_width="18dp"
-                   android:layout_height="18dp"
-                   android:src="@drawable/menu_item_more"
-                   android:visibility="gone"/>
-
-     </FrameLayout>
-
 </merge>
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -25,16 +25,17 @@
     <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_state_icon">18dp</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>