List of usage examples for android.view Menu addSubMenu
SubMenu addSubMenu(int groupId, int itemId, int order, @StringRes int titleRes);
From source file:com.android.app.MediaPlaybackActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // Don't show the menu items if we got launched by path/filedescriptor, or // if we're in one shot mode. In most cases, these menu items are not // useful in those modes, so for consistency we never show them in these // modes, instead of tailoring them to the specific file being played. if (MusicUtils.getCurrentAudioId() >= 0) { menu.add(0, GOTO_START, 0, R.string.goto_start).setIcon(R.drawable.ic_menu_music_library); menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu() SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist) .setIcon(android.R.drawable.ic_menu_add); // these next two are in a separate group, so they can be shown/hidden as needed // based on the keyguard state menu.add(1, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short) .setIcon(R.drawable.ic_menu_set_as_ringtone); menu.add(1, DELETE_ITEM, 0, R.string.delete_item).setIcon(R.drawable.ic_menu_delete); Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); if (getPackageManager().resolveActivity(i, 0) != null) { menu.add(0, EFFECTS_PANEL, 0, R.string.effectspanel).setIcon(R.drawable.ic_menu_eq); }//ww w . j a v a 2s .c om return true; } return false; }
From source file:com.example.android.bluepayandroidsdk.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { itemStartSC = menu.add(0, START_SWIPE_CARD, Menu.NONE, "Swipe Card"); itemStartSC.setEnabled(true);// w w w. jav a2s . c o m sub = menu.addSubMenu(0, SETTINGS_ITEM, Menu.NONE, "Settings"); itemSubSaveLog = sub.add(0, SUB_SAVE_LOG_ITEM, Menu.NONE, "Save Log option"); itemSubUseAutoConfigProfile = sub.add(1, SUB_USE_AUTOCONFIG_PROFILE, Menu.NONE, "Use AutoConfig profile"); itemSubSelectReader = sub.add(1, SUB_SELECT_READER, Menu.NONE, "Change reader type"); itemSubLoadXML = sub.add(1, SUB_LOAD_XML, Menu.NONE, "Reload XML"); itemSubStartAutoConfig = sub.add(4, SUB_START_AUTOCONFIG, Menu.NONE, "Start AutoConfig"); itemSubStopAutoConfig = sub.add(6, SUB_STOP_AUTOCONFIG, Menu.NONE, "Stop AutoConfig"); sub.add(Menu.NONE, SUB_ATTACHED_TYPE, Menu.NONE, "Get attached type"); sub.add(Menu.NONE, SUB_SUPPORT_STATUS, Menu.NONE, "Get support status"); itemSubSaveLog.setCheckable(true); itemSubUseAutoConfigProfile.setCheckable(true); itemSubLoadXML.setEnabled(true); itemSubStartAutoConfig.setEnabled(true); itemSubStopAutoConfig.setEnabled(true); itemDelLogs = menu.add(0, DELETE_LOG_ITEM, Menu.NONE, "Delete Logs"); itemDelLogs.setEnabled(true); itemAbout = menu.add(0, ABOUT_ITEM, Menu.NONE, "About"); itemAbout.setEnabled(true); itemExitApp = menu.add(0, EXIT_IDT_APP, Menu.NONE, "Exit"); itemExitApp.setEnabled(true); return super.onCreateOptionsMenu(menu); }
From source file:cgeo.geocaching.cgeocaches.java
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_FILTER, 0, res.getString(R.string.caches_filter)).setIcon(R.drawable.ic_menu_filter); if (type != CacheListType.HISTORY) { menu.add(0, MENU_SORT, 0, res.getString(R.string.caches_sort)) .setIcon(R.drawable.ic_menu_sort_alphabetically); }// ww w . j a v a2s . c o m menu.add(0, MENU_SWITCH_SELECT_MODE, 0, res.getString(R.string.caches_select_mode)) .setIcon(R.drawable.ic_menu_agenda); menu.add(0, MENU_INVERT_SELECTION, 0, res.getString(R.string.caches_select_invert)) .setIcon(R.drawable.ic_menu_mark); if (type == CacheListType.OFFLINE) { SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_OFFLINE, 0, res.getString(R.string.caches_manage)) .setIcon(R.drawable.ic_menu_save); subMenu.add(0, MENU_DROP_CACHES, 0, res.getString(R.string.caches_drop_all)); // delete saved caches subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list)); subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list)); subMenu.add(0, MENU_DELETE_EVENTS, 0, res.getString(R.string.caches_delete_events)); subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs)); //TODO: add submenu/AlertDialog and use R.string.gpx_import_title subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title)); if (Settings.getWebDeviceCode() != null) { subMenu.add(0, MENU_IMPORT_WEB, 0, res.getString(R.string.web_import_title)); } subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches } else { if (type == CacheListType.HISTORY) { SubMenu subMenu = menu .addSubMenu(0, SUBMENU_MANAGE_HISTORY, 0, res.getString(R.string.caches_manage)) .setIcon(R.drawable.ic_menu_save); subMenu.add(0, MENU_REMOVE_FROM_HISTORY, 0, res.getString(R.string.cache_clear_history)); // remove from history subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs)); menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)) .setIcon(R.drawable.ic_menu_set_as); } else { menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.caches_store_offline)) .setIcon(R.drawable.ic_menu_set_as); // download details for all caches } } navigationMenu = CacheListAppFactory.addMenuItems(menu, this, res); if (type == CacheListType.OFFLINE) { SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_LISTS, 0, res.getString(R.string.list_menu)) .setIcon(R.drawable.ic_menu_more); subMenu.add(0, MENU_CREATE_LIST, 0, res.getString(R.string.list_menu_create)); subMenu.add(0, MENU_DROP_LIST, 0, res.getString(R.string.list_menu_drop)); subMenu.add(0, MENU_RENAME_LIST, 0, res.getString(R.string.list_menu_rename)); subMenu.add(0, MENU_SWITCH_LIST, 0, res.getString(R.string.list_menu_change)); } return true; }
From source file:com.native5.plugins.ActionBarPlugin.java
private boolean buildMenu(Menu menu, JSONArray definition, String menu_var) { // Sadly MenuItem.setIcon and SubMenu.setIcon have conficting return types (for chaining), thus this can't be done w/ generics :( class GetMenuItemIconTask extends AsyncTask<String, Void, Drawable> { public final MenuItem item; public Exception exception = null; GetMenuItemIconTask(MenuItem item) { this.item = item; }//from w w w . j a va 2 s. co m @Override protected Drawable doInBackground(String... uris) { return getDrawableForURI(uris[0]); } @Override protected void onPostExecute(Drawable icon) { if (icon != null) { item.setIcon(icon); } } } ; class GetSubMenuIconTask extends AsyncTask<String, Void, Drawable> { public final SubMenu item; public Exception exception = null; GetSubMenuIconTask(SubMenu item) { this.item = item; } @Override protected Drawable doInBackground(String... uris) { return getDrawableForURI(uris[0]); } @Override protected void onPostExecute(Drawable icon) { if (icon != null) { item.setIcon(icon); } } } ; try { for (int i = 0; i < definition.length(); ++i) { final JSONObject item_def = definition.getJSONObject(i); final String text = item_def.isNull("text") ? "" : item_def.getString("text"); if (!item_def.has("items")) { MenuItem item = menu.add(0, i, i, text); item.setTitleCondensed(text); if (item_def.isNull("icon") == false) { GetMenuItemIconTask task = new GetMenuItemIconTask(item); synchronized (task) { task.execute(item_def.getString("icon")); } } // Default to MenuItem.SHOW_AS_ACTION_IF_ROOM, otherwise take user defined value. item.setShowAsAction(item_def.has("show") ? item_def.getInt("show") : MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menu_callbacks.put(item, "var item = " + menu_var + "[" + i + "]; if(item.click) item.click();"); } else { SubMenu submenu = menu.addSubMenu(0, i, i, text); if (item_def.isNull("icon") == false) { GetSubMenuIconTask task = new GetSubMenuIconTask(submenu); synchronized (task) { task.execute(item_def.getString("icon")); } } // Set submenu header if (item_def.has("header")) { JSONObject header = item_def.getJSONObject("header"); if (header.has("title")) { submenu.setHeaderTitle(header.getString("title")); } if (header.has("icon")) { submenu.setHeaderIcon(getDrawableForURI(header.getString("icon"))); } } // Build sub-menu buildMenu(submenu, item_def.getJSONArray("items"), menu_var + "[" + i + "].items"); } } } catch (JSONException e) { return false; } return true; }
From source file:org.mozilla.gecko.BrowserApp.java
/** * Add the provided item to the provided menu, which should be * the root (mMenu)./*from w ww. j a v a 2 s . co m*/ */ private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info) { info.added = true; final Menu destination; if (info.parent == 0) { destination = menu; } else if (info.parent == GECKO_TOOLS_MENU) { // The tools menu only exists in our -v11 resources. if (Versions.feature11Plus) { final MenuItem tools = menu.findItem(R.id.tools); destination = tools != null ? tools.getSubMenu() : menu; } else { destination = menu; } } else { final MenuItem parent = menu.findItem(info.parent); if (parent == null) { return; } Menu parentMenu = findParentMenu(menu, parent); if (!parent.hasSubMenu()) { parentMenu.removeItem(parent.getItemId()); destination = parentMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle()); if (parent.getIcon() != null) { ((SubMenu) destination).getItem().setIcon(parent.getIcon()); } } else { destination = parent.getSubMenu(); } } final MenuItem item = destination.add(Menu.NONE, info.id, Menu.NONE, info.label); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET))); return true; } }); if (info.icon == null) { item.setIcon(R.drawable.ic_menu_addons_filler); } else { final int id = info.id; BitmapUtils.getDrawable(this, info.icon, new BitmapUtils.BitmapLoader() { @Override public void onBitmapFound(Drawable d) { // TODO: why do we re-find the item? final MenuItem item = destination.findItem(id); if (item == null) { return; } if (d == null) { item.setIcon(R.drawable.ic_menu_addons_filler); return; } item.setIcon(d); } }); } item.setCheckable(info.checkable); item.setChecked(info.checked); item.setEnabled(info.enabled); item.setVisible(info.visible); }
From source file:id.ridon.keude.AppDetailsData.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.clear();//w w w .jav a 2 s . c o m if (app == null) return true; if (app.canAndWantToUpdate()) { MenuItemCompat.setShowAsAction( menu.add(Menu.NONE, INSTALL, 0, R.string.menu_upgrade).setIcon(R.drawable.ic_menu_refresh), MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); } // Check count > 0 due to incompatible apps resulting in an empty list. if (!app.isInstalled() && app.suggestedVercode > 0 && adapter.getCount() > 0) { MenuItemCompat.setShowAsAction( menu.add(Menu.NONE, INSTALL, 1, R.string.menu_install).setIcon(android.R.drawable.ic_menu_add), MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); } else if (app.isInstalled()) { MenuItemCompat.setShowAsAction( menu.add(Menu.NONE, UNINSTALL, 1, R.string.menu_uninstall) .setIcon(android.R.drawable.ic_menu_delete), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); if (mPm.getLaunchIntentForPackage(app.id) != null) { MenuItemCompat.setShowAsAction( menu.add(Menu.NONE, LAUNCH, 1, R.string.menu_launch) .setIcon(android.R.drawable.ic_media_play), MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); } } MenuItemCompat.setShowAsAction( menu.add(Menu.NONE, SHARE, 1, R.string.menu_share).setIcon(android.R.drawable.ic_menu_share), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all) .setIcon(android.R.drawable.ic_menu_close_clear_cancel).setCheckable(true) .setChecked(app.ignoreAllUpdates); if (app.hasUpdates()) { menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this) .setIcon(android.R.drawable.ic_menu_close_clear_cancel).setCheckable(true) .setChecked(app.ignoreThisUpdate >= app.suggestedVercode); } if (app.webURL.length() > 0) { menu.add(Menu.NONE, WEBSITE, 3, R.string.menu_website).setIcon(android.R.drawable.ic_menu_view); } if (app.trackerURL.length() > 0) { menu.add(Menu.NONE, ISSUES, 4, R.string.menu_issues).setIcon(android.R.drawable.ic_menu_view); } if (app.sourceURL.length() > 0) { menu.add(Menu.NONE, SOURCE, 5, R.string.menu_source).setIcon(android.R.drawable.ic_menu_view); } if (app.bitcoinAddr != null || app.litecoinAddr != null || app.dogecoinAddr != null || app.flattrID != null || app.donateURL != null) { SubMenu donate = menu.addSubMenu(Menu.NONE, DONATE, 7, R.string.menu_donate) .setIcon(android.R.drawable.ic_menu_send); if (app.bitcoinAddr != null) donate.add(Menu.NONE, BITCOIN, 8, R.string.menu_bitcoin); if (app.litecoinAddr != null) donate.add(Menu.NONE, LITECOIN, 8, R.string.menu_litecoin); if (app.dogecoinAddr != null) donate.add(Menu.NONE, DOGECOIN, 8, R.string.menu_dogecoin); if (app.flattrID != null) donate.add(Menu.NONE, FLATTR, 9, R.string.menu_flattr); if (app.donateURL != null) donate.add(Menu.NONE, DONATE_URL, 10, R.string.menu_website); } if (app.isInstalled() && fdroidApp.bluetoothAdapter != null) { // ignore on devices without Bluetooth menu.add(Menu.NONE, SEND_VIA_BLUETOOTH, 6, R.string.send_via_bluetooth); } return true; }
From source file:com.nit.vicky.Reviewer.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Resources res = getResources(); UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card, R.drawable.ic_menu_mark);//from w w w. j a va 2 s.co m UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo, R.drawable.ic_menu_revert_disabled); UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card, R.drawable.ic_menu_edit); if (mPrefWhiteboard) { if (mShowWhiteboard) { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.hide_whiteboard, R.drawable.ic_menu_compose); } else { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.show_whiteboard, R.drawable.ic_menu_compose); } UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE, R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist); } SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note); removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note); if (mPrefTextSelection) { MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select)); item.setIcon(R.drawable.ic_menu_search); item.setEnabled(Lookup.isAvailable()); } return true; }
From source file:com.ichi2.anki2.Reviewer.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Resources res = getResources(); UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card, R.drawable.ic_menu_mark);//w w w. j a va2 s. c o m UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo, R.drawable.ic_menu_revert_disabled); UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card, R.drawable.ic_menu_edit); if (mPrefWhiteboard) { if (mShowWhiteboard) { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.hide_whiteboard, R.drawable.ic_menu_compose); } else { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.show_whiteboard, R.drawable.ic_menu_compose); } UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE, R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist); } if (mPrefRecord) { // TODO proper icon final MenuItem recorderItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD, Menu.NONE, Recorder.recording() ? R.string.record_stop : R.string.record_start, R.drawable.ic_circle_pressed); final MenuItem replayItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD_REPLAY, Menu.NONE, R.string.record_play, R.drawable.ic_circle_normal); // disable unless something is recorded replayItem.setEnabled(false); // set relevant listeners Recorder.setRecordingStartedListener(new Recorder.RecordingStartedListener() { @Override public void onRecordingStarted() { recorderItem.setTitle(R.string.record_stop); } }); Recorder.setRecordingFinishedListener(new Recorder.RecordingFinishedListener() { @Override public void onRecordingFinished() { recorderItem.setTitle(R.string.record_start); replayItem.setEnabled(true); } }); Recorder.setRecorderResetListener(new Recorder.RecorderResetListener() { @Override public void onRecorderReset() { replayItem.setEnabled(false); } }); } SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note); removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note); if (mPrefTextSelection) { MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select)); item.setIcon(R.drawable.ic_menu_search); item.setEnabled(Lookup.isAvailable()); } return true; }