/* * This function will return all the menu and sub-menu items that can * be directly (the shortcut directly corresponds) and indirectly * (the ALT-enabled char corresponds to the shortcut) associated * with the keyCode. */ @SuppressWarnings("deprecation") void findItemsWithShortcutForKey(List<MenuItemImpl> items, int keyCode, KeyEvent event) { final boolean qwerty = isQwertyMode(); final int metaState = event.getMetaState(); final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData(); // Get the chars associated with the keyCode (i.e using any chording combo) final boolean isKeyCodeMapped = event.getKeyData(possibleChars); // The delete key is not mapped to '\b' so we treat it specially if (!isKeyCodeMapped && (keyCode != KeyEvent.KEYCODE_DEL)) { return; } // Look for an item whose shortcut is this key. final int N = mItems.size(); for (int i = 0; i < N; i++) { MenuItemImpl item = mItems.get(i); if (item.hasSubMenu()) { ((MenuBuilder) item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event); } final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut(); if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) && (shortcutChar != 0) && (shortcutChar == possibleChars.meta[0] || shortcutChar == possibleChars.meta[2] || (qwerty && shortcutChar == '\b' && keyCode == KeyEvent.KEYCODE_DEL)) && item.isEnabled()) { items.add(item); } } }
public boolean performItemAction(MenuItem item, int flags) { MenuItemImpl itemImpl = (MenuItemImpl) item; if (itemImpl == null || !itemImpl.isEnabled()) { return false; } boolean invoked = itemImpl.invoke(); if (itemImpl.hasCollapsibleActionView()) { invoked |= itemImpl.expandActionView(); if (invoked) close(true); } else if (item.hasSubMenu()) { close(false); final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); final ActionProvider provider = item.getActionProvider(); if (provider != null && provider.hasSubMenu()) { provider.onPrepareSubMenu(subMenu); } invoked |= dispatchSubMenuSelected(subMenu); if (!invoked) close(true); } else { if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) { close(true); } } return invoked; }
@Override public void initialize(MenuItemImpl itemData, int menuType) { mItemData = itemData; setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE); setTitle(itemData.getTitleForItemView(this)); setCheckable(itemData.isCheckable()); setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut()); setIcon(itemData.getIcon()); setEnabled(itemData.isEnabled()); }
public boolean bindNativeOverflow( android.view.Menu menu, android.view.MenuItem.OnMenuItemClickListener listener, HashMap<android.view.MenuItem, MenuItemImpl> map) { final List<MenuItemImpl> nonActionItems = getNonActionItems(); if (nonActionItems == null || nonActionItems.size() == 0) { return false; } boolean visible = false; menu.clear(); for (MenuItemImpl nonActionItem : nonActionItems) { if (!nonActionItem.isVisible()) { continue; } visible = true; android.view.MenuItem nativeItem; if (nonActionItem.hasSubMenu()) { android.view.SubMenu nativeSub = menu.addSubMenu( nonActionItem.getGroupId(), nonActionItem.getItemId(), nonActionItem.getOrder(), nonActionItem.getTitle()); SubMenuBuilder subMenu = (SubMenuBuilder) nonActionItem.getSubMenu(); for (MenuItemImpl subItem : subMenu.getVisibleItems()) { android.view.MenuItem nativeSubItem = nativeSub.add( subItem.getGroupId(), subItem.getItemId(), subItem.getOrder(), subItem.getTitle()); nativeSubItem.setIcon(subItem.getIcon()); nativeSubItem.setOnMenuItemClickListener(listener); nativeSubItem.setEnabled(subItem.isEnabled()); nativeSubItem.setIntent(subItem.getIntent()); nativeSubItem.setNumericShortcut(subItem.getNumericShortcut()); nativeSubItem.setAlphabeticShortcut(subItem.getAlphabeticShortcut()); nativeSubItem.setTitleCondensed(subItem.getTitleCondensed()); nativeSubItem.setCheckable(subItem.isCheckable()); nativeSubItem.setChecked(subItem.isChecked()); if (subItem.isExclusiveCheckable()) { nativeSub.setGroupCheckable(subItem.getGroupId(), true, true); } map.put(nativeSubItem, subItem); } nativeItem = nativeSub.getItem(); } else { nativeItem = menu.add( nonActionItem.getGroupId(), nonActionItem.getItemId(), nonActionItem.getOrder(), nonActionItem.getTitle()); } nativeItem.setIcon(nonActionItem.getIcon()); nativeItem.setOnMenuItemClickListener(listener); nativeItem.setEnabled(nonActionItem.isEnabled()); nativeItem.setIntent(nonActionItem.getIntent()); nativeItem.setNumericShortcut(nonActionItem.getNumericShortcut()); nativeItem.setAlphabeticShortcut(nonActionItem.getAlphabeticShortcut()); nativeItem.setTitleCondensed(nonActionItem.getTitleCondensed()); nativeItem.setCheckable(nonActionItem.isCheckable()); nativeItem.setChecked(nonActionItem.isChecked()); if (nonActionItem.isExclusiveCheckable()) { menu.setGroupCheckable(nonActionItem.getGroupId(), true, true); } map.put(nativeItem, nonActionItem); } return visible; }