@Override public void dispatchInvalidateOptionsMenu() { if (DEBUG) Log.d(TAG, "[dispatchInvalidateOptionsMenu]"); if (mMenu == null) { Context context = mActivity; if (mActionBar != null) { TypedValue outValue = new TypedValue(); mActivity.getTheme().resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true); if (outValue.resourceId != 0) { // We are unable to test if this is the same as our current theme // so we just wrap it and hope that if the attribute was specified // then the user is intentionally specifying an alternate theme. context = new ContextThemeWrapper(context, outValue.resourceId); } } mMenu = new MenuBuilder(context); mMenu.setCallback(mMenuBuilderCallback); } mMenu.stopDispatchingItemsChanged(); mMenu.clear(); if (!callbackCreateOptionsMenu(mMenu)) { mMenu = null; if (mActionBar != null) { if (DEBUG) Log.d(TAG, "[dispatchInvalidateOptionsMenu] setting action bar menu to null"); mActionBar.setMenu(null, mMenuPresenterCallback); } return; } if (!callbackPrepareOptionsMenu(mMenu)) { if (mActionBar != null) { if (DEBUG) Log.d(TAG, "[dispatchInvalidateOptionsMenu] setting action bar menu to null"); mActionBar.setMenu(null, mMenuPresenterCallback); } mMenu.startDispatchingItemsChanged(); return; } // TODO figure out KeyEvent? See PhoneWindow#preparePanel KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC); mMenu.startDispatchingItemsChanged(); if (DEBUG) Log.d(TAG, "[dispatchInvalidateOptionsMenu] setting action bar menu to " + mMenu); mActionBar.setMenu(mMenu, mMenuPresenterCallback); }
private void dispatchPresenterUpdate(boolean cleared) { if (mPresenters.isEmpty()) return; stopDispatchingItemsChanged(); for (WeakReference<MenuPresenter> ref : mPresenters) { final MenuPresenter presenter = ref.get(); if (presenter == null) { mPresenters.remove(ref); } else { presenter.updateMenuView(cleared); } } startDispatchingItemsChanged(); }
public boolean collapseItemActionView(MenuItemImpl item) { if (mPresenters.isEmpty() || mExpandedItem != item) return false; boolean collapsed = false; stopDispatchingItemsChanged(); for (WeakReference<MenuPresenter> ref : mPresenters) { final MenuPresenter presenter = ref.get(); if (presenter == null) { mPresenters.remove(ref); } else if ((collapsed = presenter.collapseItemActionView(this, item))) { break; } } startDispatchingItemsChanged(); if (collapsed) { mExpandedItem = null; } return collapsed; }
private boolean preparePanel() { // Already prepared (isPrepared will be reset to false later) if (mMenuIsPrepared) { return true; } // Init the panel state's menu--return false if init failed if (mMenu == null || mMenuRefreshContent) { if (mMenu == null) { if (!initializePanelMenu() || (mMenu == null)) { return false; } } if (wActionBar != null) { wActionBar.setMenu(mMenu, this); } // Call callback, and return if it doesn't want to display menu. // Creating the panel menu will involve a lot of manipulation; // don't dispatch change events to presenters until we're done. mMenu.stopDispatchingItemsChanged(); if (!callbackCreateOptionsMenu(mMenu)) { // Ditch the menu created above mMenu = null; if (wActionBar != null) { // Don't show it in the action bar either wActionBar.setMenu(null, this); } return false; } mMenuRefreshContent = false; } // Callback and return if the callback does not want to show the menu // Preparing the panel menu can involve a lot of manipulation; // don't dispatch change events to presenters until we're done. mMenu.stopDispatchingItemsChanged(); // Restore action view state before we prepare. This gives apps // an opportunity to override frozen/restored state in onPrepare. if (mMenuFrozenActionViewState != null) { mMenu.restoreActionViewStates(mMenuFrozenActionViewState); mMenuFrozenActionViewState = null; } if (!callbackPrepareOptionsMenu(mMenu)) { if (wActionBar != null) { // The app didn't want to show the menu for now but it still exists. // Clear it out of the action bar. wActionBar.setMenu(null, this); } mMenu.startDispatchingItemsChanged(); return false; } // Set the proper keymap KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC); mMenu.startDispatchingItemsChanged(); // Set other state mMenuIsPrepared = true; return true; }