private final void b()
 {
   if ((d == null) || (d.size() == 0)) {
     return;
   }
   ccm localccm = new ccm(getContext());
   b.clear();
   Iterator localIterator = d.iterator();
   while (localIterator.hasNext())
   {
     Account localAccount = (Account)localIterator.next();
     b.addAll(localAccount.g());
   }
   localIterator = b.iterator();
   while (localIterator.hasNext()) {
     localccm.add((cha)localIterator.next());
   }
   setAdapter(localccm);
   a();
   setOnItemSelectedListener(this);
 }
 /**
  * Can be overridden in case a subclass needs a different uri format (such as one that does not
  * rely on account and/or conversation.
  */
 protected void setBaseUri() {
   // Since the uri specified in the conversation base uri may not be unique, we specify a
   // base uri that us guaranteed to be unique for this conversation.
   mBaseUri = "x-thread://" + mAccount.getEmailAddress().hashCode() + "/" + mConversation.id;
 }
Esempio n. 3
0
 private Intent generateProxyIntent(Uri uri) {
   return generateProxyIntent(
       mActivity, mAccount.viewIntentProxyUri, uri, mAccount.getEmailAddress());
 }
  // 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);
  }
  /**
   * Reorders the specified {@link Menu}, taking into account the user's Archive/Delete preference.
   */
  public static void reorderMenu(
      final Context context, final Account account, final Menu menu, final int maxItems) {
    final String removalAction =
        MailPrefs.get(context)
            .getRemovalAction(account.supportsCapability(AccountCapabilities.ARCHIVE));
    final boolean showArchive =
        MailPrefs.RemovalActions.ARCHIVE.equals(removalAction)
            || MailPrefs.RemovalActions.ARCHIVE_AND_DELETE.equals(removalAction);
    final boolean showDelete =
        MailPrefs.RemovalActions.DELETE.equals(removalAction)
            || MailPrefs.RemovalActions.ARCHIVE_AND_DELETE.equals(removalAction);

    // Do a first pass to extract necessary information on what is safe to display
    boolean archiveVisibleEnabled = false;
    boolean deleteVisibleEnabled = false;
    for (int i = 0; i < menu.size(); i++) {
      final MenuItem menuItem = menu.getItem(i);
      final int itemId = menuItem.getItemId();
      final boolean visible = menuItem.isVisible();
      final boolean enabled = menuItem.isEnabled();

      if (itemId == R.id.archive || itemId == R.id.remove_folder) {
        archiveVisibleEnabled |= (visible & enabled);
      } else if (itemId == R.id.delete || itemId == R.id.discard_drafts) {
        deleteVisibleEnabled |= (visible & enabled);
      }
    }

    int actionItems = 0;

    for (int i = 0; i < menu.size(); i++) {
      final MenuItem menuItem = menu.getItem(i);
      final int itemId = menuItem.getItemId();

      // We only want to promote it if it's visible and has an icon
      if (menuItem.isVisible() && menuItem.getIcon() != null) {
        if (itemId == R.id.archive || itemId == R.id.remove_folder) {
          /*
           * If this is disabled, and we want to show both archive and delete, we will
           * hide archive (rather than showing it disabled), and take up one of our
           * spaces. If we only want to show archive, we'll hide it, but not take up
           * a space.
           */
          if (!menuItem.isEnabled() && showArchive) {
            menuItem.setVisible(false);

            if (showDelete) {
              actionItems++;
            }
          } else {
            /*
             * We show this if the following are all true:
             * 1. The user wants to display archive, or delete is not visible
             * 2. We have room for it
             */
            if ((showArchive || !deleteVisibleEnabled) && actionItems < maxItems) {
              menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
              actionItems++;
            }
          }
        } else if (itemId == R.id.delete || itemId == R.id.discard_drafts) {
          /*
           * We show this if the following are all true:
           * 1. The user wants to display delete, or archive is not visible
           * 2. We have room for it
           */
          if ((showDelete || !archiveVisibleEnabled) && actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        } else if (itemId == R.id.change_folders) {
          final boolean showChangeFolder =
              account.supportsCapability(AccountCapabilities.MULTIPLE_FOLDERS_PER_CONV);
          menuItem.setVisible(showChangeFolder);

          if (showChangeFolder && actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        } else if (itemId == R.id.search) {
          menuItem.setShowAsAction(
              MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
          actionItems++;
        } else {
          if (actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        }
      }
    }
  }
  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;
  }