From e37f597727f5099fed21d92c8887d5451b249409 Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Thu, 27 Sep 2012 11:22:08 -0700 Subject: [PATCH] Bug 788520: Menu item missing in Android 2.x. [r=mfinkle] --HG-- extra : rebase_source : 38c1b9a2f092687f849a4bb39f8784ab488d9fce --- mobile/android/base/BrowserApp.java | 58 +++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index b674f9f31c1..21d925b8da6 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -54,7 +54,19 @@ abstract public class BrowserApp extends GeckoApp private boolean mAboutHomeShowing; private static final int ADDON_MENU_OFFSET = 1000; - static Vector sAddonMenuItems = new Vector(); + private class MenuItemInfo { + int id; + String label; + String icon; + + public MenuItemInfo(int id, String label, String icon) { + this.id = id; + this.label = label; + this.icon = icon; + } + } + + private Vector mAddonMenuItemsCache; private PropertyAnimator mMainLayoutAnimator; @@ -637,8 +649,13 @@ abstract public class BrowserApp extends GeckoApp } private void addAddonMenuItem(final int id, final String label, final String icon) { - if (mMenu == null) + if (mMenu == null) { + if (mAddonMenuItemsCache == null) + mAddonMenuItemsCache = new Vector(); + + mAddonMenuItemsCache.add(new MenuItemInfo(id, label, icon)); return; + } final MenuItem item = mMenu.add(Menu.NONE, id, Menu.NONE, label); @@ -677,24 +694,25 @@ abstract public class BrowserApp extends GeckoApp }); } } - sAddonMenuItems.add(item); } private void removeAddonMenuItem(int id) { - for (MenuItem item : sAddonMenuItems) { - if (item.getItemId() == id) { - sAddonMenuItems.remove(item); - - if (mMenu == null) - break; - - MenuItem menuItem = mMenu.findItem(id); - if (menuItem != null) - mMenu.removeItem(id); - - break; + // Remove add-on menu item from cache, if available. + if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) { + for (MenuItemInfo item : mAddonMenuItemsCache) { + if (item.id == id) { + mAddonMenuItemsCache.remove(item); + break; + } } } + + if (mMenu == null) + return; + + MenuItem menuItem = mMenu.findItem(id); + if (menuItem != null) + mMenu.removeItem(id); } @Override @@ -707,6 +725,16 @@ abstract public class BrowserApp extends GeckoApp MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.browser_app_menu, mMenu); + + // Add add-on menu items if any. + if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) { + for (MenuItemInfo item : mAddonMenuItemsCache) { + addAddonMenuItem(item.id, item.label, item.icon); + } + + mAddonMenuItemsCache.clear(); + } + return true; }