@Override
 public void onPrepareOptionsMenu(Menu menu) {
   // Only show option if we support message transforms and message has been transformed.
   Utils.setMenuItemVisibility(
       menu,
       R.id.show_original,
       supportsMessageTransforms()
           && mHasConversationBeenTransformed
           && !mHasConversationTransformBeenReverted);
 }
  // We need to do this here instead of in the fragment
  public void setConversationModeOptions(Menu menu) {
    if (mCurrentConversation == null) {
      return;
    }
    final boolean showMarkImportant = !mCurrentConversation.isImportant();
    Utils.setMenuItemVisibility(
        menu,
        R.id.mark_important,
        showMarkImportant
            && mAccount.supportsCapability(UIProvider.AccountCapabilities.MARK_IMPORTANT));
    Utils.setMenuItemVisibility(
        menu,
        R.id.mark_not_important,
        !showMarkImportant
            && mAccount.supportsCapability(UIProvider.AccountCapabilities.MARK_IMPORTANT));
    final boolean showDelete =
        mFolder != null && mFolder.supportsCapability(UIProvider.FolderCapabilities.DELETE);
    Utils.setMenuItemVisibility(menu, R.id.delete, showDelete);
    // We only want to show the discard drafts menu item if we are not showing the delete menu
    // item, and the current folder is a draft folder and the account supports discarding
    // drafts for a conversation
    final boolean showDiscardDrafts =
        !showDelete
            && mFolder != null
            && mFolder.isDraft()
            && mAccount.supportsCapability(AccountCapabilities.DISCARD_CONVERSATION_DRAFTS);
    Utils.setMenuItemVisibility(menu, R.id.discard_drafts, showDiscardDrafts);
    final boolean archiveVisible =
        mAccount.supportsCapability(AccountCapabilities.ARCHIVE)
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.ARCHIVE)
            && !mFolder.isTrash();
    Utils.setMenuItemVisibility(menu, R.id.archive, archiveVisible);
    Utils.setMenuItemVisibility(
        menu,
        R.id.remove_folder,
        !archiveVisible
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES)
            && !mFolder.isProviderFolder()
            && mAccount.supportsCapability(AccountCapabilities.ARCHIVE));
    Utils.setMenuItemVisibility(
        menu,
        R.id.move_to,
        mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.ALLOWS_REMOVE_CONVERSATION));
    Utils.setMenuItemVisibility(
        menu,
        R.id.move_to_inbox,
        mFolder != null && mFolder.supportsCapability(FolderCapabilities.ALLOWS_MOVE_TO_INBOX));

    final MenuItem removeFolder = menu.findItem(R.id.remove_folder);
    if (mFolder != null && removeFolder != null) {
      removeFolder.setTitle(
          mActivity.getApplicationContext().getString(R.string.remove_folder, mFolder.name));
    }
    Utils.setMenuItemVisibility(
        menu,
        R.id.report_spam,
        mAccount.supportsCapability(AccountCapabilities.REPORT_SPAM)
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.REPORT_SPAM)
            && !mCurrentConversation.spam);
    Utils.setMenuItemVisibility(
        menu,
        R.id.mark_not_spam,
        mAccount.supportsCapability(AccountCapabilities.REPORT_SPAM)
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.MARK_NOT_SPAM)
            && mCurrentConversation.spam);
    Utils.setMenuItemVisibility(
        menu,
        R.id.report_phishing,
        mAccount.supportsCapability(AccountCapabilities.REPORT_PHISHING)
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.REPORT_PHISHING)
            && !mCurrentConversation.phishing);
    Utils.setMenuItemVisibility(
        menu,
        R.id.mute,
        mAccount.supportsCapability(AccountCapabilities.MUTE)
            && mFolder != null
            && mFolder.supportsCapability(FolderCapabilities.DESTRUCTIVE_MUTE)
            && !mCurrentConversation.muted);
  }
  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;
  }