Exemple #1
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (getActivity() == null) {
      // Monkeys cause bad things. This callback may be delayed if for some reason the
      // preference screen was closed really quickly - just bail then.
      return false;
    }

    final String key = preference.getKey();

    if (PreferenceKeys.REMOVAL_ACTION.equals(key)) {
      final String removalAction = newValue.toString();
      mMailPrefs.setRemovalAction(removalAction);
      updateListSwipeTitle(removalAction);
    } else if (AUTO_ADVANCE_WIDGET.equals(key)) {
      final int prefsAutoAdvanceMode =
          AUTO_ADVANCE_VALUES[mAutoAdvance.findIndexOfValue((String) newValue)];
      mMailPrefs.setAutoAdvanceMode(prefsAutoAdvanceMode);
    } else if (!PreferenceKeys.CONVERSATION_LIST_SWIPE.equals(key)
        && !PreferenceKeys.SHOW_SENDER_IMAGES.equals(key)
        && !PreferenceKeys.DEFAULT_REPLY_ALL.equals(key)
        && !PreferenceKeys.CONVERSATION_OVERVIEW_MODE.equals(key)
        && !PreferenceKeys.CONFIRM_DELETE.equals(key)
        && !PreferenceKeys.CONFIRM_ARCHIVE.equals(key)
        && !PreferenceKeys.CONFIRM_SEND.equals(key)) {
      return false;
    }

    return true;
  }
Exemple #2
0
  @Override
  public void onResume() {
    super.onResume();

    // Manually initialize the preference views that require massaging. Prefs that require
    // massaging include:
    //  1. a prefs UI control that does not map 1:1 to storage
    //  2. a pref that must obtain its initial value from migrated storage, and for which we
    //     don't want to always persist a migrated value
    final int autoAdvanceModeIndex =
        prefValueToWidgetIndex(
            AUTO_ADVANCE_VALUES, mMailPrefs.getAutoAdvanceMode(), AutoAdvance.DEFAULT);
    mAutoAdvance.setValueIndex(autoAdvanceModeIndex);

    final String removalAction = mMailPrefs.getRemovalAction(supportsArchive());
    updateListSwipeTitle(removalAction);

    listenForPreferenceChange(
        PreferenceKeys.REMOVAL_ACTION,
        PreferenceKeys.CONVERSATION_LIST_SWIPE,
        PreferenceKeys.SHOW_SENDER_IMAGES,
        PreferenceKeys.DEFAULT_REPLY_ALL,
        PreferenceKeys.CONVERSATION_OVERVIEW_MODE,
        AUTO_ADVANCE_WIDGET,
        PreferenceKeys.CONFIRM_DELETE,
        PreferenceKeys.CONFIRM_ARCHIVE,
        PreferenceKeys.CONFIRM_SEND);
  }
Exemple #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    mMailPrefs = MailPrefs.get(getActivity());

    // Set the shared prefs name to use prefs auto-persist behavior by default.
    // Any pref more complex than the default (say, involving migration), should set
    // "persistent=false" in the XML and manually handle preference initialization and change.
    getPreferenceManager().setSharedPreferencesName(mMailPrefs.getSharedPreferencesName());

    addPreferencesFromResource(R.xml.general_preferences);

    mAutoAdvance = (ListPreference) findPreference(AUTO_ADVANCE_WIDGET);
  }
  /**
   * 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++;
          }
        }
      }
    }
  }