Bug 947261 - Ensure that mActionItemBarPresenter is removed from the menu when cleared. r=sriram, a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Tue, 17 Dec 2013 20:44:14 -0800
changeset 175453 1be80da4f90d90596c33b9267a449daf09d8cf8d
parent 175452 07e7f637e2a4b1d87fe6fbb30182e8eec0b3226d
child 175454 6395885b7e0e40e3e5a70c150a6ba1bf5be930ea
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram, lsblakk
bugs947261
milestone28.0a2
Bug 947261 - Ensure that mActionItemBarPresenter is removed from the menu when cleared. r=sriram, a=lsblakk
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);
     }