List of usage examples for android.view Menu add
public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);
From source file:com.android.mms.ui.ComposeMessageActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.clear();//from www . j a v a 2 s . co m if (mSendDiscreetMode && !mForwardMessageMode) { // When we're in send-a-single-message mode from the lock screen, don't show // any menus. return true; } if (isRecipientCallable()) { MenuItem item = menu.add(0, MENU_CALL_RECIPIENT, 0, R.string.menu_call) .setIcon(R.drawable.ic_menu_call_holo_light).setTitle(R.string.menu_call); if (!isRecipientsEditorVisible()) { // If we're not composing a new message, show the call icon in the actionbar item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } } if (MmsConfig.getMmsEnabled() && mIsSmsEnabled) { if (!isSubjectEditorVisible()) { menu.add(0, MENU_ADD_SUBJECT, 0, R.string.add_subject).setIcon(R.drawable.ic_menu_edit); } if (!mWorkingMessage.hasAttachment()) { menu.add(0, MENU_ADD_ATTACHMENT, 0, R.string.add_attachment) .setIcon(R.drawable.ic_menu_attachment_holo_light).setTitle(R.string.add_attachment) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // add to actionbar } } menu.add(0, MENU_ADD_TEMPLATE, 0, R.string.template_insert).setIcon(android.R.drawable.ic_menu_add) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); if (isPreparedForSending() && mIsSmsEnabled) { menu.add(0, MENU_SEND, 0, R.string.send).setIcon(android.R.drawable.ic_menu_send); } if (!mWorkingMessage.hasSlideshow() && mIsSmsEnabled && mEnableEmoticons) { menu.add(0, MENU_INSERT_SMILEY, 0, R.string.menu_insert_smiley).setIcon(R.drawable.ic_menu_emoticons); } if (getRecipients().size() > 1) { menu.add(0, MENU_GROUP_PARTICIPANTS, 0, R.string.menu_group_participants); } if (mMsgListAdapter.getCount() > 0 && mIsSmsEnabled) { // Removed search as part of b/1205708 //menu.add(0, MENU_SEARCH, 0, R.string.menu_search).setIcon( // R.drawable.ic_menu_search); Cursor cursor = mMsgListAdapter.getCursor(); if ((null != cursor) && (cursor.getCount() > 0)) { menu.add(0, MENU_DELETE_THREAD, 0, R.string.delete_thread) .setIcon(android.R.drawable.ic_menu_delete); } } else if (mIsSmsEnabled) { menu.add(0, MENU_DISCARD, 0, R.string.discard).setIcon(android.R.drawable.ic_menu_delete); } buildAddAddressToContactMenuItem(menu); // Add to Blacklist item (if enabled) and we are running on CyanogenMod // This allows the app to be run on non-blacklist enabled roms (including Stock) if (MessageUtils.isCyanogenMod(this)) { if (BlacklistUtils.isBlacklistEnabled(this)) { menu.add(0, MENU_ADD_TO_BLACKLIST, 0, R.string.add_to_blacklist) .setIcon(R.drawable.ic_block_message_holo_dark) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } } if (mConversation.getThreadId() > 0) { menu.add(0, MENU_CONVERSATION_OPTIONS, 0, R.string.menu_conversation_options); } menu.add(0, MENU_PREFERENCES, 0, R.string.menu_preferences).setIcon(android.R.drawable.ic_menu_preferences); if (LogTag.DEBUG_DUMP) { menu.add(0, MENU_DEBUG_DUMP, 0, R.string.menu_debug_dump); } 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 ww .j ava 2 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); } 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.xmobileapp.rockplayer.RockPlayer.java
/******************************************* * //from ww w. ja v a 2s. c om * Create Menu * *******************************************/ public boolean onPrepareOptionsMenu(Menu menu) { /* * Initialize clean menu */ super.onPrepareOptionsMenu(menu); menu.clear(); /* * Add menu items */ if (this.SHUFFLE) menu.add(0, 0, 0, "Suffle Off"); else menu.add(0, 0, 0, "Shuffle On"); menu.add(0, 1, 1, "Search"); menu.add(0, 5, 5, "Share"); menu.add(0, 3, 3, "Get Art"); menu.add(0, 4, 4, "Concerts"); menu.add(0, 6, 6, "Playlists"); menu.add(0, 7, 7, "Preferences"); menu.add(0, 8, 8, "Help"); menu.add(0, 2, 2, "Exit"); /* * Add menu icons */ (menu.findItem(0)).setIcon(R.drawable.ic_menu_shuffle); (menu.findItem(3)).setIcon(R.drawable.ic_menu_music_library); (menu.findItem(5)).setIcon(android.R.drawable.ic_menu_share); (menu.findItem(1)).setIcon(android.R.drawable.ic_menu_search); //(menu.findItem(3)).setIcon(android.R.drawable.ic_menu_slideshow); (menu.findItem(4)).setIcon(android.R.drawable.ic_menu_today); (menu.findItem(6)).setIcon(R.drawable.ic_mp_current_playlist_btn); (menu.findItem(7)).setIcon(android.R.drawable.ic_menu_preferences); (menu.findItem(8)).setIcon(android.R.drawable.ic_menu_help); (menu.findItem(2)).setIcon(android.R.drawable.ic_menu_close_clear_cancel); //(menu.findItem(6)).setIcon(android.R.drawable.ic_menu_preferences); return true; }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void buildAddAddressToContactMenuItem(Menu menu) { // bug #7087793: for group of recipients, remove "Add to People" action. Rely on // individually creating contacts for unknown phone numbers by touching the individual // sender's avatars, one at a time ContactList contacts = getRecipients(); if (contacts.size() != 1) { return;/*from www . ja va 2s.c om*/ } // if we don't have a contact for the recipient, create a menu item to add the number // to contacts. Contact c = contacts.get(0); if (!c.existsInDatabase() && canAddToContacts(c)) { Intent intent = ConversationList.createAddContactIntent(c.getNumber()); menu.add(0, MENU_ADD_ADDRESS_TO_CONTACTS, 0, R.string.menu_add_to_contacts) .setIcon(android.R.drawable.ic_menu_add).setIntent(intent); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
/** * Cancel search dialog if it is open./*from w w w . ja v a 2 s . c o m*/ */ /* * void stopSearch() { // Close search dialog SearchManager searchManager = * (SearchManager) getSystemService(Context.SEARCH_SERVICE); * searchManager.stopSearch(); // Restore search widget to its normal * position PersonaSearch searchWidget = * mWorkspace.findSearchWidgetOnCurrentScreen(); if (searchWidget != null) { * searchWidget.stopSearch(false); } } */ @Override public boolean onCreateOptionsMenu(Menu menu) { if (mDesktopLocked && mSavedInstanceState == null) return false; super.onCreateOptionsMenu(menu); menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add).setIcon(android.R.drawable.ic_menu_add) .setAlphabeticShortcut('A'); menu.add(MENU_GROUP_NORMAL, MENU_SEARCH, 0, R.string.menu_search) .setIcon(android.R.drawable.ic_search_category_default) .setAlphabeticShortcut(SearchManager.MENU_KEY); menu.add(MENU_GROUP_NORMAL, MENU_NOTIFICATIONS, 0, R.string.menu_edit) .setIcon(android.R.drawable.ic_menu_edit).setAlphabeticShortcut('E'); final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); menu.add(MENU_GROUP_NORMAL, MENU_SETTINGS, 0, R.string.menu_settings) .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P').setIntent(settings); // ADW: add custom settings menu.add(MENU_GROUP_NORMAL, MENU_ALMOSTNEXUS, 0, R.string.menu_adw_settings) .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('X'); menu.add(MENU_GROUP_CATALOGUE, MENU_APP_GRP_CONFIG, 0, R.string.AppGroupConfig) .setIcon(android.R.drawable.ic_menu_agenda); // menu.add(MENU_GROUP_CATALOGUE, MENU_APP_GRP_RENAME, 0, // R.string.AppGroupRename) // .setIcon(R.drawable.ic_menu_notifications); menu.add(MENU_GROUP_CATALOGUE, MENU_APP_SWITCH_GRP, 0, R.string.AppGroupChoose) .setIcon(android.R.drawable.ic_menu_manage); menu.add(MENU_GROUP_CATALOGUE, MENU_APP_DELETE_GRP, 0, R.string.AppGroupDel) .setIcon(android.R.drawable.ic_menu_delete); menu.add(MENU_GROUP_NORMAL, MENU_LOCK_DESKTOP, 0, R.string.menu_lock) .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('X'); return true; }
From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { toolsSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST, R.string.editor_tools);/*from w w w .ja v a 2 s .com*/ toolsSubMenu.setIcon(R.drawable.ic_edit); toolsSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // TOOLS MENU MenuItem mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PEN, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PEN, R.string.editor_pen); mi.setIcon(R.drawable.ic_edit); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TEXT, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_TEXT, R.string.editor_text); mi.setIcon(R.drawable.ic_text); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SELECTION, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SELECTION, R.string.editor_selection); mi.setIcon(R.drawable.ic_selection); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ERASER, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ERASER, R.string.editor_eraser); mi.setIcon(R.drawable.ic_eraser); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // TOOL SETTINGS MENU SubMenu toolsSettingSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings); toolsSettingSubMenu.setIcon(R.drawable.ic_action_settings); toolsSettingSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN, R.string.editor_pen); mi.setIcon(R.drawable.ic_edit); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT, R.string.editor_text); mi.setIcon(R.drawable.ic_text); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION, R.string.editor_selection); mi.setIcon(R.drawable.ic_selection); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER, R.string.editor_eraser); mi.setIcon(R.drawable.ic_eraser); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // ADD MENU SubMenu addSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD, R.string.editor_add_menu); addSubMenu.setIcon(R.drawable.ic_add); addSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // IMAGE mi = addSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE, R.string.editor_add_image); mi.setIcon(R.drawable.ic_add_image); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // PAGES SubMenu pagesMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE, R.string.editor_pages); pagesMenu.setIcon(R.drawable.ic_pages); pagesMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE, R.string.editor_pages_move); mi.setIcon(R.drawable.ic_pages); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD, R.string.editor_pages_add); mi.setIcon(R.drawable.ic_add_page); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE, R.string.editor_pages_remove); mi.setIcon(R.drawable.ic_delete); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // EXTRA SETTINGS // SAVE mi = menu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SAVE, Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SAVE, R.string.editor_save); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); super.onCreateOptionsMenu(menu); 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 .ja va 2 s . c om 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; }