List of usage examples for android.view SubMenu add
public MenuItem add(int groupId, int itemId, int order, CharSequence title);
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 ww w . jav a 2 s .c o m*/ return true; }
From source file:com.landenlabs.all_UiDemo.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); SubMenu pageMenu = menu.addSubMenu("Pages..."); int groupId = 1; int itemId = 100; for (PageItem item : mItems) { pageMenu.add(groupId, itemId, itemId, item.mTitle); itemId++;//from w w w . j a va2s . com } return true; }
From source file:org.gdg.frisbee.android.common.GdgNavDrawerActivity.java
private void setupDrawerContent(NavigationView navigationView) { Menu menu = navigationView.getMenu(); menu.add(GROUP_ID, Const.DRAWER_HOME, Menu.NONE, R.string.home_gdg).setIcon(R.drawable.ic_drawer_home_gdg); menu.add(GROUP_ID, Const.DRAWER_GDE, Menu.NONE, R.string.gde).setIcon(R.drawable.ic_drawer_gde); menu.add(GROUP_ID, Const.DRAWER_PULSE, Menu.NONE, R.string.pulse).setIcon(R.drawable.ic_drawer_pulse); //adding special events in navigation drawer final ArrayList<TaggedEventSeries> currentEventSeries = App.getInstance().currentTaggedEventSeries(); for (TaggedEventSeries taggedEventSeries : currentEventSeries) { menu.add(GROUP_ID, taggedEventSeries.getDrawerId(), Menu.NONE, taggedEventSeries.getTitleResId()) .setIcon(taggedEventSeries.getDrawerIconResId()); }//from w w w.j a v a2 s .c o m SubMenu subMenu = menu.addSubMenu(GAMES_GROUP_ID, Const.DRAWER_SUBMENU_GAMES, Menu.NONE, R.string.drawer_subheader_games); subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ACHIEVEMENTS, Menu.NONE, R.string.achievements) .setIcon(R.drawable.ic_drawer_achievements); subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ARROW, Menu.NONE, R.string.arrow) .setIcon(R.drawable.ic_drawer_arrow).setCheckable(true); menu.add(SETTINGS_GROUP_ID, Const.DRAWER_SETTINGS, Menu.NONE, R.string.settings) .setIcon(R.drawable.ic_drawer_settings); menu.add(SETTINGS_GROUP_ID, Const.DRAWER_HELP, Menu.NONE, R.string.help).setIcon(R.drawable.ic_drawer_help); menu.add(SETTINGS_GROUP_ID, Const.DRAWER_FEEDBACK, Menu.NONE, R.string.feedback) .setIcon(R.drawable.ic_drawer_feedback); menu.add(SETTINGS_GROUP_ID, Const.DRAWER_ABOUT, Menu.NONE, R.string.about) .setIcon(R.drawable.ic_drawer_about); menu.setGroupCheckable(GROUP_ID, true, true); final int selectedDrawerItemId = getIntent().getIntExtra(EXTRA_SELECTED_DRAWER_ITEM_ID, Const.DRAWER_HOME); final MenuItem selectedItem = menu.findItem(selectedDrawerItemId); if (selectedItem != null) { selectedItem.setChecked(true); } navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { onDrawerItemClick(menuItem); mDrawerLayout.closeDrawers(); return true; } }); View headerView = navigationView.getHeaderView(0); mDrawerImage = ButterKnife.findById(headerView, R.id.navdrawer_image); mDrawerUserPicture = ButterKnife.findById(headerView, R.id.navdrawer_user_picture); }
From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActionMode.java
private void getMenu(Menu menu) { MenuItem mi;/* w w w .j a v a 2s .c o m*/ menu.clear(); mi = menu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_DELETE_ID, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings); mi.setIcon(R.drawable.ic_delete); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // GROUP MENU if (selectedSpenObjects.size() > 1) { SubMenu groupSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST, R.string.editor_group_menu); groupSubMenu.setIcon(R.drawable.ic_group); groupSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID, R.string.editor_group); mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID, R.string.editor_ungroup); mi.setEnabled(false); for (SpenObjectBase obj : selectedSpenObjects) { if (obj.getType() == SpenObjectBase.TYPE_CONTAINER) { mi.setEnabled(true); break; } } } // UP MENU SubMenu upMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST, R.string.editor_front_menu); upMenu.setIcon(R.drawable.ic_move_up); upMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID, R.string.editor_forward); mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID, R.string.editor_front); // DOWN MENU SubMenu downMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST, R.string.editor_back_menu); downMenu.setIcon(R.drawable.ic_move_down); downMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID, R.string.editor_backward); mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID, Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID, R.string.editor_back); }
From source file:io.github.hidroh.materialistic.ReadabilityFragment.java
@Override protected void createOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_font_options, menu); mTextSizeOptionValues = getResources().getStringArray(R.array.pref_text_size_values); mFontOptionValues = getResources().getStringArray(R.array.font_values); SubMenu subMenu = menu.findItem(R.id.menu_font_size).getSubMenu(); String[] options = getResources().getStringArray(R.array.text_size_options); String initialTextSize = Preferences.Theme.getPreferredReadabilityTextSize(getActivity()); for (int i = 0; i < options.length; i++) { MenuItem item = subMenu.add(R.id.menu_font_size_group, Menu.NONE, i, options[i]); item.setChecked(TextUtils.equals(initialTextSize, mTextSizeOptionValues[i])); }/*from ww w .j av a 2 s . co m*/ subMenu.setGroupCheckable(R.id.menu_font_size_group, true, true); subMenu = menu.findItem(R.id.menu_font).getSubMenu(); options = getResources().getStringArray(R.array.font_options); String initialTypeface = Preferences.Theme.getReadabilityTypeface(getActivity()); for (int i = 0; i < options.length; i++) { MenuItem item = subMenu.add(R.id.menu_font_group, Menu.NONE, i, options[i]); item.setChecked(TextUtils.equals(initialTypeface, mFontOptionValues[i])); } subMenu.setGroupCheckable(R.id.menu_font_group, true, true); }
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 ww w . ja va 2 s . com*/ } } else { throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu"); } }
From source file:com.audiokernel.euphonyrmt.fragments.BrowseFragment.java
@Override public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenu.ContextMenuInfo menuInfo) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final int index = (int) info.id; if (index >= 0 && mItems.size() > index) { menu.setHeaderTitle(mItems.get((int) info.id).toString()); // If in simple mode, show "Play" (add, replace & play), "Add to queue" and "Add to playlist" if (mApp.isInSimpleMode()) { final MenuItem playItem = menu.add(ADD_REPLACE_PLAY, ADD_REPLACE_PLAY, 0, R.string.play); playItem.setOnMenuItemClickListener(this); final MenuItem addItem = menu.add(ADD, ADD, 0, R.string.addToQueue); addItem.setOnMenuItemClickListener(this); } else {//from w ww . j a va 2s.c om final MenuItem addItem = menu.add(ADD, ADD, 0, mIrAdd); addItem.setOnMenuItemClickListener(this); final MenuItem addAndReplaceItem = menu.add(ADD_REPLACE, ADD_REPLACE, 0, R.string.addAndReplace); addAndReplaceItem.setOnMenuItemClickListener(this); final MenuItem addAndReplacePlayItem = menu.add(ADD_REPLACE_PLAY, ADD_REPLACE_PLAY, 0, R.string.addAndReplacePlay); addAndReplacePlayItem.setOnMenuItemClickListener(this); final MenuItem addAndPlayItem = menu.add(ADD_PLAY, ADD_PLAY, 0, R.string.addAndPlay); addAndPlayItem.setOnMenuItemClickListener(this); } if (R.string.addPlaylist != mIrAdd && R.string.addStream != mIrAdd && mApp.oMPDAsyncHelper.oMPD.isCommandAvailable(MPDCommand.MPD_CMD_LISTPLAYLISTS)) { int id = 0; final SubMenu playlistMenu = menu.addSubMenu(R.string.addToPlaylist); MenuItem item = playlistMenu.add(ADD_TO_PLAYLIST, id++, (int) info.id, R.string.newPlaylist); item.setOnMenuItemClickListener(this); try { final List<Item> playlists = mApp.oMPDAsyncHelper.oMPD.getPlaylists(); if (null != playlists) { for (final Item pl : playlists) { item = playlistMenu.add(ADD_TO_PLAYLIST, id++, (int) info.id, pl.getName()); item.setOnMenuItemClickListener(this); } } } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to parse playlists.", e); } } final MenuItem gotoArtistItem = menu.add(GOTO_ARTIST, GOTO_ARTIST, 0, R.string.goToArtist); gotoArtistItem.setOnMenuItemClickListener(this); } }
From source file:net.pocketmine.server.HomeActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem log = menu.add(0, CONSOLE_CODE, 0, R.string.title_activity_log).setIcon(R.drawable.hardware_dock); MenuItemCompat.setShowAsAction(log, MenuItem.SHOW_AS_ACTION_IF_ROOM); SubMenu sub = menu.addSubMenu(getString(R.string.abs_settings)); /**// w w w . j a v a2s . c o m * Set Icon for Submenu */ sub.setIcon(R.drawable.action_settings); /** * Build navigation for submenu */ sub.add(0, VERSION_MANAGER_CODE, 0, getString(R.string.abs_version_manager)); sub.add(0, PROPERTIES_EDITOR_CODE, 0, getString(R.string.abs_properties_editor)); sub.add(0, PLUGINS_CODE, 0, getString(R.string.abs_plugins)); sub.add(0, FORCE_CLOSE_CODE, 0, getString(R.string.abs_force_close)); sub.add(0, ABOUT_US_CODE, 0, getString(R.string.abs_about)); sub.add(0, REINSTALL_PHP_CODE, 0, getString(R.string.php_reinstall)); MenuItem subgrp = sub.getItem(); MenuItemCompat.setShowAsAction(subgrp, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; }
From source file:me.fattycat.kun.teamwork.ui.activity.MainActivity.java
private void initTeamProjectMenu(boolean isClear) { LogUtils.i(TAG, "initTeamProjectMenu"); Menu menu = mNavView.getMenu(); menu.removeGroup(233);//from ww w .j a v a2s. c om SubMenu projectMenu = menu.addSubMenu(233, Menu.NONE, Menu.NONE, String.format("%s %s", getString(R.string.text_menu_project), TWSettings.sTeamList.get(TWSettings.sSelectedTeamPos).getName())); if (isClear) { projectMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, " ...").setCheckable(true) .setIcon(android.R.color.transparent); return; } int index = 0; for (TeamProjectModel model : mTeamProjectList) { projectMenu.add(Menu.NONE, index++, Menu.NONE, model.getName()).setCheckable(true) .setIcon(android.R.color.transparent); } if (index == 0) { projectMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, "").setCheckable(true) .setIcon(android.R.color.transparent); } }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * Creates a sub menu used to add items to a new playlist or an existing * one.//from www . jav a 2s.c o m * * @param context The {@link Context} to use. * @param groupId The group Id of the menu. * @param subMenu The {@link SubMenu} to add to. * @param showFavorites True if we should show the option to add to the * Favorites cache. */ public static void makePlaylistMenu(final Context context, final int groupId, final SubMenu subMenu, final boolean showFavorites) { // subMenu.clear(); subMenu.clearHeader(); if (showFavorites) { subMenu.add(groupId, FragmentMenuItems.ADD_TO_FAVORITES, Menu.NONE, R.string.add_to_favorites); } subMenu.add(groupId, FragmentMenuItems.NEW_PLAYLIST, Menu.NONE, R.string.new_empty_playlist); Cursor cursor = PlaylistLoader.makePlaylistCursor(context); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { final Intent intent = new Intent(); String name = cursor.getString(1); //LOG.info("makePlaylistMenu - add ["+name+"]"); if (name != null) { intent.putExtra("playlist", getIdForPlaylist(context, name)); subMenu.add(groupId, FragmentMenuItems.PLAYLIST_SELECTED, Menu.NONE, name).setIntent(intent); } cursor.moveToNext(); } } if (cursor != null) { cursor.close(); } }