public boolean onPrepareOptionsMenu(Menu menu) { // We start out with every option enabled. Based on the current view, we disable actions // that are possible. LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu()."); if (mHelpItem != null) { mHelpItem.setVisible( mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT)); } if (mSendFeedbackItem != null) { mSendFeedbackItem.setVisible( mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK)); } if (mController.shouldHideMenuItems()) { // Shortcut: hide all remaining menu items if the drawer is shown final int size = menu.size(); for (int i = 0; i < size; i++) { final MenuItem item = menu.getItem(i); final int id = item.getItemId(); if (id != R.id.settings && id != R.id.feedback_menu_item && id != R.id.help_info_menu_item) { item.setVisible(false); } } return false; } if (mRefreshItem != null) { // See b/11158759 // Disable refresh on drafts folders. mRefreshItem.setVisible( mFolder != null && !mFolder.isDraft() && !mFolder.supportsCapability(FolderCapabilities.IS_VIRTUAL)); } if (mFolderSettingsItem != null) { mFolderSettingsItem.setVisible( mFolder != null && mFolder.supportsCapability(FolderCapabilities.SUPPORTS_SETTINGS)); } if (mEmptyTrashItem != null) { mEmptyTrashItem.setVisible( mAccount != null && mFolder != null && mAccount.supportsCapability(AccountCapabilities.EMPTY_TRASH) && mFolder.isTrash() && mFolder.totalCount > 0); } if (mEmptySpamItem != null) { mEmptySpamItem.setVisible( mAccount != null && mFolder != null && mAccount.supportsCapability(AccountCapabilities.EMPTY_SPAM) && mFolder.isType(FolderType.SPAM) && mFolder.totalCount > 0); } switch (mMode) { case ViewMode.CONVERSATION: case ViewMode.SEARCH_RESULTS_CONVERSATION: // We update the ActionBar options when we are entering conversation view because // waiting for the AbstractConversationViewFragment to do it causes duplicate icons // to show up during the time between the conversation is selected and the fragment // is added. setConversationModeOptions(menu); // We want to use the user's preferred menu items here final Resources resources = getResources(); final int maxItems = resources.getInteger(R.integer.actionbar_max_items); final int hiddenItems = resources.getInteger(R.integer.actionbar_hidden_non_cab_items_no_physical_button); final int totalItems = maxItems - (ViewConfiguration.get(getContext()).hasPermanentMenuKey() ? 0 : hiddenItems); reorderMenu(getContext(), mAccount, menu, totalItems); break; case ViewMode.CONVERSATION_LIST: // Show compose and search based on the account // The only option that needs to be disabled is search Utils.setMenuItemVisibility( menu, R.id.search, mAccount.supportsCapability(AccountCapabilities.FOLDER_SERVER_SEARCH)); break; case ViewMode.SEARCH_RESULTS_LIST: // Hide compose and search Utils.setMenuItemVisibility(menu, R.id.compose, false); Utils.setMenuItemVisibility(menu, R.id.search, false); break; } return false; }