Bug 940997: Remove icons from main menu. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 18 Dec 2013 18:49:53 -0800
changeset 161211 90699ba761fb5291698f2b5664dc7bf042d8e53c
parent 161210 63cac76f5f7fcc5be0f993d7f623b68cb017bde0
child 161212 7ef525f0c865ce6a0fe0d417681ae4e6bdff5467
push id25871
push usercbook@mozilla.com
push dateThu, 19 Dec 2013 09:34:02 +0000
treeherdermozilla-central@5c7fa2bfea8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs940997
milestone29.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 940997: Remove icons from main menu. [r=mfinkle]
mobile/android/base/menu/GeckoMenu.java
mobile/android/base/menu/GeckoMenuItem.java
mobile/android/base/menu/MenuItemActionBar.java
mobile/android/base/menu/MenuItemActionView.java
mobile/android/base/menu/MenuItemDefault.java
--- a/mobile/android/base/menu/GeckoMenu.java
+++ b/mobile/android/base/menu/GeckoMenu.java
@@ -94,16 +94,19 @@ public class GeckoMenu extends ListView
     private ActionItemBarPresenter mPrimaryActionItemBar;
 
     // Reference to "ifRoom" action-items bar in action-bar.
     private final ActionItemBarPresenter mSecondaryActionItemBar;
 
     // Adapter to hold the list of menu items.
     private MenuItemsAdapter mAdapter;
 
+    // Show/hide icons in the list.
+    private boolean mShowIcons;
+
     public GeckoMenu(Context context) {
         this(context, null);
     }
 
     public GeckoMenu(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.geckoMenuListViewStyle);
     }
 
@@ -113,16 +116,17 @@ public class GeckoMenu extends ListView
         setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                          LayoutParams.FILL_PARENT));
 
         // Attach an adapter.
         mAdapter = new MenuItemsAdapter();
         setAdapter(mAdapter);
         setOnItemClickListener(this);
 
+        mShowIcons = false;
         mItems = new ArrayList<GeckoMenuItem>();
         mPrimaryActionItems = new HashMap<GeckoMenuItem, View>();
         mSecondaryActionItems = new HashMap<GeckoMenuItem, View>();
 
         mPrimaryActionItemBar = (DefaultActionItemBar) LayoutInflater.from(context).inflate(R.layout.menu_action_bar, null);
         mSecondaryActionItemBar = (DefaultActionItemBar) LayoutInflater.from(context).inflate(R.layout.menu_secondary_action_bar, null);
     }
 
@@ -517,16 +521,17 @@ public class GeckoMenu extends ListView
 
         if (item.invoke()) {
             close();
         } else if (item.hasSubMenu()) {
             // Refresh the submenu for the provider.
             ActionProvider provider = item.getActionProvider();
             if (provider != null) {
                 GeckoSubMenu subMenu = new GeckoSubMenu(getContext());
+                subMenu.setShowIcons(true);
                 provider.onPrepareSubMenu(subMenu);
                 item.setSubMenu(subMenu);
             }
 
             // Show the submenu.
             GeckoSubMenu subMenu = (GeckoSubMenu) item.getSubMenu();
             showMenu(subMenu);
         } else {
@@ -566,16 +571,23 @@ public class GeckoMenu extends ListView
             }
         }
     }
 
     public void setActionItemBarPresenter(ActionItemBarPresenter presenter) {
         mPrimaryActionItemBar = presenter;
     }
 
+    public void setShowIcons(boolean show) {
+        if (mShowIcons != show) {
+            mShowIcons = show;
+            mAdapter.notifyDataSetChanged();
+        }
+    }
+
     // Action Items are added to the header view by default.
     // URL bar can register itself as a presenter, in case it has a different place to show them.
     public static class DefaultActionItemBar extends LinearLayout
                                              implements ActionItemBarPresenter {
         private final int mRowHeight;
         private float mWeightSum;
 
         public DefaultActionItemBar(Context context) {
@@ -695,16 +707,17 @@ public class GeckoMenu extends ListView
                     public void onClick(View v) {
                         GeckoMenu listView = GeckoMenu.this;
                         listView.performItemClick(actionView, pos + listView.getHeaderViewsCount(), id);
                     }
                 });
             }
 
             // Initialize the view.
+            view.setShowIcon(mShowIcons);
             view.initialize(item);
             return (View) view; 
         }
 
         @Override
         public int getItemViewType(int position) {
             return getItem(position).getActionProvider() == null ? VIEW_TYPE_DEFAULT : VIEW_TYPE_ACTION_MODE;
         }
--- a/mobile/android/base/menu/GeckoMenuItem.java
+++ b/mobile/android/base/menu/GeckoMenuItem.java
@@ -22,16 +22,17 @@ public class GeckoMenuItem implements Me
     public static final int SHOW_AS_ACTION_NEVER = 0;
     public static final int SHOW_AS_ACTION_IF_ROOM = 1;
     public static final int SHOW_AS_ACTION_ALWAYS = 2;
 
     // A View that can show a MenuItem should be able to initialize from 
     // the properties of the MenuItem.
     public static interface Layout {
         public void initialize(GeckoMenuItem item);
+        public void setShowIcon(boolean show);
     }
 
     public static interface OnShowAsActionChangedListener {
         public boolean hasActionItemBar();
         public void onShowAsActionChanged(GeckoMenuItem item);
     }
 
     private int mId;
--- a/mobile/android/base/menu/MenuItemActionBar.java
+++ b/mobile/android/base/menu/MenuItemActionBar.java
@@ -62,9 +62,14 @@ public class MenuItemActionBar extends I
         setContentDescription(title);
     }
 
     @Override
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
         setColorFilter(enabled ? 0 : 0xFF999999);
     }
+
+    @Override
+    public void setShowIcon(boolean show) {
+        // Do nothing.
+    }
 }
--- a/mobile/android/base/menu/MenuItemActionView.java
+++ b/mobile/android/base/menu/MenuItemActionView.java
@@ -108,16 +108,21 @@ public class MenuItemActionView extends 
     public void setActionButtonClickListener(View.OnClickListener listener) {
         mActionButtonListener = listener;
 
         for (ImageButton button : mActionButtons) {
             button.setOnClickListener(listener);
         }
     }
 
+    @Override
+    public void setShowIcon(boolean show) {
+        mMenuItem.setShowIcon(show);
+    }
+
     public void addActionButton(Drawable drawable) {
         // If this is the first icon, retain the text.
         // If not, make the menu item an icon.
         final int count = mActionButtons.size();
         mMenuItem.setVisibility(View.GONE);
         mMenuButton.setVisibility(View.VISIBLE);
 
         if (drawable != null) {
--- a/mobile/android/base/menu/MenuItemDefault.java
+++ b/mobile/android/base/menu/MenuItemDefault.java
@@ -21,16 +21,17 @@ public class MenuItemDefault extends Tex
 
     private Drawable mIcon;
     private Drawable mState;
     private static Rect sIconBounds;
 
     private boolean mCheckable = false;
     private boolean mChecked = false;
     private boolean mHasSubMenu = false;
+    private boolean mShowIcon = false;
 
     public MenuItemDefault(Context context) {
         this(context, null);
     }
 
     public MenuItemDefault(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.menuItemDefaultStyle);
     }
@@ -80,25 +81,29 @@ public class MenuItemDefault extends Tex
         setTitle(item.getTitle());        
         setIcon(item.getIcon());
         setEnabled(item.isEnabled());
         setCheckable(item.isCheckable());
         setChecked(item.isChecked());
         setSubMenuIndicator(item.hasSubMenu());
     }
 
+    private void refreshIcon() {
+        setCompoundDrawables(mShowIcon ? mIcon : null, null, mState, null);
+    }
+
     void setIcon(Drawable icon) {
         mIcon = icon;
 
         if (mIcon != null) {
             mIcon.setBounds(sIconBounds);
             mIcon.setAlpha(isEnabled() ? 255 : 99);
         }
 
-        setCompoundDrawables(mIcon, null, mState, null);
+        refreshIcon();
     }
 
     void setIcon(int icon) {
         Drawable drawable = null;
 
         if (icon != 0)
             drawable = getResources().getDrawable(icon);
          
@@ -129,15 +134,23 @@ public class MenuItemDefault extends Tex
 
     private void setChecked(boolean checked) {
         if (mChecked != checked) {
             mChecked = checked;
             refreshDrawableState();
         }
     }
 
+    @Override
+    public void setShowIcon(boolean show) {
+        if (mShowIcon != show) {
+            mShowIcon = show;
+            refreshIcon();
+        }
+    }
+
     private void setSubMenuIndicator(boolean hasSubMenu) {
         if (mHasSubMenu != hasSubMenu) {
             mHasSubMenu = hasSubMenu;
             refreshDrawableState();
         }
     }
 }