List of usage examples for android.view MenuItem getSubMenu
public SubMenu getSubMenu();
From source file:com.android.screenspeak.contextmenu.ListMenuManager.java
@Override public boolean showMenu(int menuId) { mLastUtterance = mService.getSpeechController().getLastUtterance(); dismissAll();//from w w w.j a v a2s. c o m // Some ScreenSpeak tutorial modules don't allow context menus. if (AccessibilityTutorialActivity.isTutorialActive() && !AccessibilityTutorialActivity.shouldAllowContextMenus()) { return false; } mService.saveFocusedNode(); final ListMenu menu = new ListMenu(mService); menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.hasSubMenu()) { CharSequence[] items = getItemsFromMenu(item.getSubMenu()); ListMenu menu = (ListMenu) item.getSubMenu(); showDialogMenu(menu.getTitle(), items, menu); } else if (item.getItemId() == R.id.spell_last_utterance) { AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (node != null) { AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node); CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat, null); compat.recycle(); mService.getSpeechController().spellUtterance(text); } } else if (item.getItemId() == R.id.repeat_last_utterance) { mService.getSpeechController().interrupt(); mService.getSpeechController().repeatUtterance(mLastUtterance); } else { mMenuClickProcessor.onMenuItemClicked(item); } return true; } }); ListMenuPreparer menuPreparer = new ListMenuPreparer(mService); menuPreparer.prepareMenu(menu, menuId); showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu); return false; }
From source file:com.android.talkback.contextmenu.ListMenuManager.java
@Override public boolean showMenu(int menuId) { mLastUtterance = mService.getSpeechController().getLastUtterance(); dismissAll();/*from w w w . j a v a 2 s .c o m*/ // Some TalkBack tutorial modules don't allow context menus. if (AccessibilityTutorialActivity.isTutorialActive() && !AccessibilityTutorialActivity.shouldAllowContextMenus()) { return false; } mService.saveFocusedNode(); final ListMenu menu = new ListMenu(mService); menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.hasSubMenu()) { CharSequence[] items = getItemsFromMenu(item.getSubMenu()); ListMenu menu = (ListMenu) item.getSubMenu(); showDialogMenu(menu.getTitle(), items, menu); } else if (item.getItemId() == R.id.spell_last_utterance) { AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (node != null) { AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node); CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat, null); compat.recycle(); mService.getSpeechController().spellUtterance(text); } } else if (item.getItemId() == R.id.repeat_last_utterance) { mService.getSpeechController().interrupt(); mService.getSpeechController().repeatUtterance(mLastUtterance); } else { mMenuClickProcessor.onMenuItemClicked(item); } return true; } }); ListMenuPreparer menuPreparer = new ListMenuPreparer(mService); menuPreparer.prepareMenu(menu, menuId); showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu); return false; }
From source file:org.bohrmeista.chan.ui.activity.ImageViewActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.image_view, menu); MenuItem imageSearch = menu.findItem(R.id.action_image_search); SubMenu subMenu = imageSearch.getSubMenu(); for (ImageSearch engine : ImageSearch.engines) { subMenu.add(Menu.NONE, engine.getId(), Menu.NONE, engine.getName()); }/*from w w w . ja v a 2 s . com*/ return true; }
From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java
public void UpdateJumpToGroupMenu(ArrayList<Group> groups) { StartActivity rootactivity = (StartActivity) getActivity(); if (rootactivity != null) { Menu menu = rootactivity.getActionMenu(); if (menu != null) { MenuItem jumpto = menu.findItem(R.id.action_jumpto); Menu submenu = jumpto.getSubMenu(); if (submenu == null) return; ///*from w w w .jav a 2 s . c o m*/ submenu.removeGroup(Menu.NONE); if (groups.size() > 0) { int gid = 0; for (Group group : groups) { MenuItem grp = submenu.add(Menu.NONE, gid, gid, group.Name); // prg.setIcon(R.drawable.ic_action_flash_on); MenuCompat.setShowAsAction(grp, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT); grp.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { mIndicator.setCurrentItem(menuItem.getItemId()); return true; } }); gid++; } } } } }
From source file:com.github.kanata3249.ffxieq.android.FoodSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; FoodListView flv;// w ww . j a v a 2s . co m item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); flv = (FoodListView) findViewById(R.id.ListView); if (flv != null) { String types[] = flv.getAvailableFoodTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java
public void UpdateCurrentGroupMenu() { StartActivity rootactivity = (StartActivity) getActivity(); Menu menu = rootactivity.getActionMenu(); if (menu != null) { MenuItem automation = menu.findItem(R.id.menu_automation); if (automation != null) { automation.setEnabled(false); Menu submenu = automation.getSubMenu(); if (submenu == null) return; ///*from w w w .j a va 2 s. c o m*/ submenu.removeGroup(Menu.NONE); if (mGroupPrograms.size() > 0) { for (Module program : mGroupPrograms) { MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName()); prg.setIcon(R.drawable.ic_action_flash_on); MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT); final String paddress = program.Address; String groupname = ""; try { groupname = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8"); } catch (Exception e) { } final String gname = groupname; prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { String apicall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + paddress + "/" + gname + "/" + new Date().getTime(); Control.callServiceApi(apicall, null); return true; } }); } automation.setEnabled(true); } } // // MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro"); // recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // @Override // public boolean onMenuItemClick(MenuItem menuItem) { // StartActivity sa = (StartActivity)getActivity(); // sa.openMacroRecordMenu(); // return true; // } // }); // rootactivity.supportInvalidateOptionsMenu(); } }
From source file:com.github.pockethub.android.ui.MainActivity.java
private void setUpNavigationMenu() { MenuItem organizationContainer = navigationView.getMenu().findItem(R.id.navigation_organizations); if (organizationContainer.hasSubMenu()) { SubMenu organizationsMenu = organizationContainer.getSubMenu(); for (int i = 1; i < orgs.size(); i++) { User organization = orgs.get(i); if (organizationsMenu.findItem(organization.id()) == null) { MenuItem organizationMenuItem = organizationsMenu.add(Menu.NONE, organization.id(), Menu.NONE, organization.name() != null ? organization.name() : organization.login()); organizationMenuItem.setIcon(R.drawable.ic_github_organization_black_24dp); //Because of tinting the real image would became a grey block //avatars.bind(organizationMenuItem, organization); menuItemOrganizationMap.put(organizationMenuItem, organization); }/*from w ww. j a va 2 s . c o m*/ } } else { throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu"); } }
From source file:net.bible.android.control.page.window.WindowControl.java
/** * Add the Window sub-menu resource which is not included in the main.xml for the main menu * Set the synchronised checkbox in the app menu before displayed * Disable various menu items if links window selected *//* w ww .j a va2 s . c o m*/ public void updateOptionsMenu(Menu menu) { // when updating main menu rather than Window options menu MenuItem windowSubmenuItemPosition = menu.findItem(R.id.windowSubMenu); if (windowSubmenuItemPosition != null) { // check the Window sub-menu has been added Menu subMenuToPopulate = windowSubmenuItemPosition.getSubMenu(); if (subMenuToPopulate.findItem(R.id.windowNew) == null) { new MenuInflater(BibleApplication.getApplication()).inflate(R.menu.window_popup_menu, subMenuToPopulate); } } MenuItem synchronisedMenuItem = menu.findItem(R.id.windowSynchronise); MenuItem moveFirstMenuItem = menu.findItem(R.id.windowMoveFirst); MenuItem closeMenuItem = menu.findItem(R.id.windowClose); MenuItem minimiseMenuItem = menu.findItem(R.id.windowMinimise); MenuItem maximiseMenuItem = menu.findItem(R.id.windowMaximise); Window window = getActiveWindow(); if (synchronisedMenuItem != null && moveFirstMenuItem != null) { // set synchronised & maximised checkbox state synchronisedMenuItem.setChecked(window.isSynchronised()); maximiseMenuItem.setChecked(window.isMaximised()); // the dedicated links window cannot be treated as a normal window boolean isDedicatedLinksWindowActive = isActiveWindow(windowRepository.getDedicatedLinksWindow()); synchronisedMenuItem.setEnabled(!isDedicatedLinksWindowActive); moveFirstMenuItem.setEnabled(!isDedicatedLinksWindowActive); // cannot close last normal window closeMenuItem.setEnabled(isWindowRemovable(window)); minimiseMenuItem.setEnabled(isWindowMinimisable(window)); // if window is already first then cannot promote List<Window> visibleWindows = windowRepository.getVisibleWindows(); if (visibleWindows.size() > 0 && window.equals(visibleWindows.get(0))) { moveFirstMenuItem.setEnabled(false); } } }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public void onPrepareOptionsMenu(final Menu menu) { final Resources res = getResources(); final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity()); final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false); final long[] accountIds = getAccountIds(getActivity()); final MenuItem itemAdd = menu.findItem(R.id.add_submenu); if (itemAdd != null && itemAdd.hasSubMenu()) { final SubMenu subMenu = itemAdd.getSubMenu(); subMenu.clear();/* w w w . ja va 2s .c om*/ final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap(); final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(map.entrySet()); Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON); for (final Entry<String, CustomTabConfiguration> entry : tabs) { final String type = entry.getKey(); final CustomTabConfiguration conf = entry.getValue(); final boolean isOfficiakKeyAccountRequired = TAB_TYPE_ACTIVITIES_ABOUT_ME.equals(type) || TAB_TYPE_ACTIVITIES_BY_FRIENDS.equals(type); final boolean accountIdRequired = conf .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; final Intent intent = new Intent(INTENT_ACTION_ADD_TAB); intent.setClass(getActivity(), CustomTabEditorActivity.class); intent.putExtra(EXTRA_TYPE, type); intent.putExtra(EXTRA_OFFICIAL_KEY_ONLY, isOfficiakKeyAccountRequired); final MenuItem subItem = subMenu.add(conf.getDefaultTitle()); final boolean disabledByNoAccount = accountIdRequired && accountIds.length == 0; final boolean disabledByNoOfficialKey = !forcePrivateAPI && isOfficiakKeyAccountRequired && !hasOfficialKeyAccounts; final boolean disabledByDuplicateTab = conf.isSingleTab() && isTabAdded(getActivity(), type); final boolean shouldDisable = disabledByDuplicateTab || disabledByNoOfficialKey || disabledByNoAccount; subItem.setVisible(!shouldDisable); subItem.setEnabled(!shouldDisable); final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null); subItem.setIcon(icon); subItem.setIntent(intent); } } ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu); }
From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java
private void updateAccounts() { final Menu menu = binding.navigation.getMenu(); final MenuItem libraries = menu.findItem(R.id.nav_libraries); final SubMenu subMenu = libraries.getSubMenu(); while (subMenu.size() > 0) { subMenu.removeItem(subMenu.getItem(0).getItemId()); }//from w w w .jav a 2 s . c o m final List<Account> accounts = getServer().getAccounts(); for (int index = 0; index < accounts.size(); index++) { final Account account = accounts.get(index); final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName()); if (account.getId().equals("local")) { menuItem.setIcon(R.drawable.ic_folder_24dp); } else { menuItem.setIcon(R.drawable.ic_cloud_24dp); } menuItem.setCheckable(true); } final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE, R.string.nav_addaccount); menuItem.setIcon(R.drawable.ic_add_24dp); for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) { final View child = binding.navigation.getChildAt(i); if (child != null && child instanceof ListView) { final ListView menuView = (ListView) child; final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter(); final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter(); wrapped.notifyDataSetChanged(); } } getServer().loadRecent(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem recent = menu.findItem(R.id.nav_recent); if (recent != null) { recent.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); getServer().loadStarred(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem starred = menu.findItem(R.id.nav_starred); if (starred != null) { starred.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); }