Bug 947261 - Ensure that mActionItemBarPresenter is removed from the menu when cleared. r=sriram
authorRichard Newman <rnewman@mozilla.com>
Tue, 17 Dec 2013 20:44:14 -0800
changeset 161008 fb2697d854d01d40a7dbb74a6994a6072035b32e
parent 161007 c4921ed6aef3274fb85955c5351237619d4ba0c9
child 161009 3fab9a65035e04eb09eaaea0bf83179eea6761d6
push id25862
push usercbook@mozilla.com
push dateWed, 18 Dec 2013 11:40:53 +0000
treeherdermozilla-central@60373454fc52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs947261
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 947261 - Ensure that mActionItemBarPresenter is removed from the menu when cleared. r=sriram
mobile/android/base/menu/GeckoMenu.java
--- a/mobile/android/base/menu/GeckoMenu.java
+++ b/mobile/android/base/menu/GeckoMenu.java
@@ -212,16 +212,23 @@ public class GeckoMenu extends ListView
         GeckoSubMenu subMenu = new GeckoSubMenu(getContext());
         subMenu.setMenuItem(menuItem);
         subMenu.setCallback(mCallback);
         subMenu.setMenuPresenter(mMenuPresenter);
         ((GeckoMenuItem) menuItem).setSubMenu(subMenu);
         return subMenu;
     }
 
+    private void removeActionBarView() {
+        // Reset the adapter before removing the header view from a list.
+        setAdapter(null);
+        removeHeaderView((DefaultActionItemBar) mActionItemBarPresenter);
+        setAdapter(mAdapter);
+    }
+
     @Override
     public void clear() {
         for (GeckoMenuItem menuItem : mItems) {
             if (menuItem.hasSubMenu()) {
                 SubMenu sub = menuItem.getSubMenu();
                 if (sub == null) {
                     continue;
                 }
@@ -242,16 +249,22 @@ public class GeckoMenu extends ListView
          * these is switched to the correct locale.
          */
         if (mActionItemBarPresenter != null) {
             for (View item : mActionItems.values()) {
                 mActionItemBarPresenter.removeActionItem(item);
             }
         }
         mActionItems.clear();
+
+        // Remove the view, too -- the first addActionItem will re-add it,
+        // and this is simpler than changing that logic.
+        if (mActionItemBarPresenter instanceof DefaultActionItemBar) {
+            removeActionBarView();
+        }
     }
 
     @Override
     public void close() {
         if (mMenuPresenter != null)
             mMenuPresenter.closeMenu();
     }
 
@@ -336,20 +349,17 @@ public class GeckoMenu extends ListView
             if (mActionItemBarPresenter != null)
                 mActionItemBarPresenter.removeActionItem(mActionItems.get(item));
 
             mActionItems.remove(item);
             mItems.remove(item);
 
             if (mActionItems.size() == 0 && 
                 mActionItemBarPresenter instanceof DefaultActionItemBar) {
-                // Reset the adapter before removing the header view from a list.
-                setAdapter(null);
-                removeHeaderView((DefaultActionItemBar) mActionItemBarPresenter);
-                setAdapter(mAdapter);
+                removeActionBarView();
             }
 
             return;
         }
 
         mAdapter.removeMenuItem(item);
         mItems.remove(item);
     }