Exemple #1
0
  private void onToggleTheme() {
    if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
      K9.setK9MessageViewThemeSetting(K9.Theme.LIGHT);
    } else {
      K9.setK9MessageViewThemeSetting(K9.Theme.DARK);
    }

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                Context appContext = getApplicationContext();
                Preferences prefs = Preferences.getPreferences(appContext);
                Editor editor = prefs.getPreferences().edit();
                K9.save(editor);
                editor.commit();
              }
            })
        .start();

    restartActivity();
  }
Exemple #2
0
  /**
   * Load preferences into our statics.
   *
   * <p>If you're adding a preference here, odds are you'll need to add it to {@link
   * com.fsck.k9.preferences.GlobalSettings}, too.
   *
   * @param prefs Preferences to load
   */
  public static void loadPrefs(Preferences prefs) {
    SharedPreferences sprefs = prefs.getPreferences();
    DEBUG = sprefs.getBoolean("enableDebugLogging", false);
    if (!DEBUG && sIsDebuggable && Debug.isDebuggerConnected()) {
      // If the debugger is attached, we're probably (surprise surprise) debugging something.
      DEBUG = true;
      Log.i(K9.LOG_TAG, "Debugger attached; enabling debug logging.");
    }
    DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
    mAnimations = sprefs.getBoolean("animations", true);
    mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", false);
    mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false);
    mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false);
    mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
    mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
    mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
    mHideSpecialAccounts = sprefs.getBoolean("hideSpecialAccounts", false);
    mMessageListSenderAboveSubject = sprefs.getBoolean("messageListSenderAboveSubject", false);
    mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes", false);
    mMessageListStars = sprefs.getBoolean("messageListStars", true);
    mMessageListPreviewLines = sprefs.getInt("messageListPreviewLines", 2);

    mAutofitWidth = sprefs.getBoolean("autofitWidth", true);

    mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false);
    mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00");
    mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00");

    mShowCorrespondentNames = sprefs.getBoolean("showCorrespondentNames", true);
    mShowContactName = sprefs.getBoolean("showContactName", false);
    sShowContactPicture = sprefs.getBoolean("showContactPicture", true);
    mChangeContactNameColor = sprefs.getBoolean("changeRegisteredNameColor", false);
    mContactNameColor = sprefs.getInt("registeredNameColor", 0xff00008f);
    mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
    mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);
    mMessageViewShowNext = sprefs.getBoolean("messageViewShowNext", false);
    mWrapFolderNames = sprefs.getBoolean("wrapFolderNames", false);
    mHideUserAgent = sprefs.getBoolean("hideUserAgent", false);
    mHideTimeZone = sprefs.getBoolean("hideTimeZone", false);

    mConfirmDelete = sprefs.getBoolean("confirmDelete", false);
    mConfirmDeleteStarred = sprefs.getBoolean("confirmDeleteStarred", false);
    mConfirmSpam = sprefs.getBoolean("confirmSpam", false);
    mConfirmDeleteFromNotification = sprefs.getBoolean("confirmDeleteFromNotification", true);

    try {
      String value = sprefs.getString("sortTypeEnum", Account.DEFAULT_SORT_TYPE.name());
      mSortType = SortType.valueOf(value);
    } catch (Exception e) {
      mSortType = Account.DEFAULT_SORT_TYPE;
    }

    boolean sortAscending = sprefs.getBoolean("sortAscending", Account.DEFAULT_SORT_ASCENDING);
    mSortAscending.put(mSortType, sortAscending);

    String notificationHideSubject = sprefs.getString("notificationHideSubject", null);
    if (notificationHideSubject == null) {
      // If the "notificationHideSubject" setting couldn't be found, the app was probably
      // updated. Look for the old "keyguardPrivacy" setting and map it to the new enum.
      sNotificationHideSubject =
          (sprefs.getBoolean("keyguardPrivacy", false))
              ? NotificationHideSubject.WHEN_LOCKED
              : NotificationHideSubject.NEVER;
    } else {
      sNotificationHideSubject = NotificationHideSubject.valueOf(notificationHideSubject);
    }

    String notificationQuickDelete = sprefs.getString("notificationQuickDelete", null);
    if (notificationQuickDelete != null) {
      sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
    }

    String lockScreenNotificationVisibility =
        sprefs.getString("lockScreenNotificationVisibility", null);
    if (lockScreenNotificationVisibility != null) {
      sLockScreenNotificationVisibility =
          LockScreenNotificationVisibility.valueOf(lockScreenNotificationVisibility);
    }

    String splitViewMode = sprefs.getString("splitViewMode", null);
    if (splitViewMode != null) {
      sSplitViewMode = SplitViewMode.valueOf(splitViewMode);
    }

    mAttachmentDefaultPath =
        sprefs.getString(
            "attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
    sUseBackgroundAsUnreadIndicator = sprefs.getBoolean("useBackgroundAsUnreadIndicator", true);
    sThreadedViewEnabled = sprefs.getBoolean("threadedView", true);
    fontSizes.load(sprefs);

    try {
      setBackgroundOps(
          BACKGROUND_OPS.valueOf(
              sprefs.getString(
                  "backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name())));
    } catch (Exception e) {
      setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC);
    }

    sColorizeMissingContactPictures = sprefs.getBoolean("colorizeMissingContactPictures", true);

    sMessageViewArchiveActionVisible = sprefs.getBoolean("messageViewArchiveActionVisible", false);
    sMessageViewDeleteActionVisible = sprefs.getBoolean("messageViewDeleteActionVisible", true);
    sMessageViewMoveActionVisible = sprefs.getBoolean("messageViewMoveActionVisible", false);
    sMessageViewCopyActionVisible = sprefs.getBoolean("messageViewCopyActionVisible", false);
    sMessageViewSpamActionVisible = sprefs.getBoolean("messageViewSpamActionVisible", false);

    K9.setK9Language(sprefs.getString("language", ""));

    int themeValue = sprefs.getInt("theme", Theme.LIGHT.ordinal());
    // We used to save the resource ID of the theme. So convert that to the new format if
    // necessary.
    if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
      K9.setK9Theme(Theme.DARK);
    } else {
      K9.setK9Theme(Theme.LIGHT);
    }

    themeValue = sprefs.getInt("messageViewTheme", Theme.USE_GLOBAL.ordinal());
    K9.setK9MessageViewThemeSetting(Theme.values()[themeValue]);
    themeValue = sprefs.getInt("messageComposeTheme", Theme.USE_GLOBAL.ordinal());
    K9.setK9ComposerThemeSetting(Theme.values()[themeValue]);
    K9.setUseFixedMessageViewTheme(sprefs.getBoolean("fixedMessageViewTheme", true));
  }
Exemple #3
0
  private void saveSettings() {
    SharedPreferences preferences = Preferences.getPreferences(this).getPreferences();

    K9.setK9Language(mLanguage.getValue());

    K9.setK9Theme(themeNameToId(mTheme.getValue()));
    K9.setUseFixedMessageViewTheme(mFixedMessageTheme.isChecked());
    K9.setK9MessageViewThemeSetting(themeNameToId(mMessageTheme.getValue()));
    K9.setK9ComposerThemeSetting(themeNameToId(mComposerTheme.getValue()));

    K9.setAnimations(mAnimations.isChecked());
    K9.setGesturesEnabled(mGestures.isChecked());
    K9.setUseVolumeKeysForNavigation(mVolumeNavigation.getCheckedItems()[0]);
    K9.setUseVolumeKeysForListNavigation(mVolumeNavigation.getCheckedItems()[1]);
    K9.setStartIntegratedInbox(
        !mHideSpecialAccounts.isChecked() && mStartIntegratedInbox.isChecked());
    K9.setNotificationHideSubject(
        NotificationHideSubject.valueOf(mNotificationHideSubject.getValue()));

    int index = 0;
    K9.setConfirmDelete(mConfirmActions.getCheckedItems()[index++]);
    K9.setConfirmDeleteStarred(mConfirmActions.getCheckedItems()[index++]);
    if (NotificationController.platformSupportsExtendedNotifications()) {
      K9.setConfirmDeleteFromNotification(mConfirmActions.getCheckedItems()[index++]);
    }
    K9.setConfirmSpam(mConfirmActions.getCheckedItems()[index++]);
    K9.setConfirmDiscardMessage(mConfirmActions.getCheckedItems()[index++]);

    K9.setMeasureAccounts(mMeasureAccounts.isChecked());
    K9.setCountSearchMessages(mCountSearch.isChecked());
    K9.setHideSpecialAccounts(mHideSpecialAccounts.isChecked());
    K9.setMessageListPreviewLines(Integer.parseInt(mPreviewLines.getValue()));
    K9.setMessageListCheckboxes(mCheckboxes.isChecked());
    K9.setMessageListStars(mStars.isChecked());
    K9.setShowCorrespondentNames(mShowCorrespondentNames.isChecked());
    K9.setMessageListSenderAboveSubject(mSenderAboveSubject.isChecked());
    K9.setShowContactName(mShowContactName.isChecked());
    K9.setShowContactPicture(mShowContactPicture.isChecked());
    K9.setColorizeMissingContactPictures(mColorizeMissingContactPictures.isChecked());
    K9.setUseBackgroundAsUnreadIndicator(mBackgroundAsUnreadIndicator.isChecked());
    K9.setThreadedViewEnabled(mThreadedView.isChecked());
    K9.setChangeContactNameColor(mChangeContactNameColor.isChecked());
    K9.setMessageViewFixedWidthFont(mFixedWidth.isChecked());
    K9.setMessageViewReturnToList(mReturnToList.isChecked());
    K9.setMessageViewShowNext(mShowNext.isChecked());
    K9.setAutofitWidth(mAutofitWidth.isChecked());
    K9.setQuietTimeEnabled(mQuietTimeEnabled.isChecked());

    boolean[] enabledRefileActions = mVisibleRefileActions.getCheckedItems();
    K9.setMessageViewDeleteActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_DELETE]);
    K9.setMessageViewArchiveActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_ARCHIVE]);
    K9.setMessageViewMoveActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_MOVE]);
    K9.setMessageViewCopyActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_COPY]);
    K9.setMessageViewSpamActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_SPAM]);

    K9.setCheckMailDuringDoze(checkMailDuringDoze.isChecked());

    K9.setNotificationDuringQuietTimeEnabled(!mDisableNotificationDuringQuietTime.isChecked());
    K9.setQuietTimeStarts(mQuietTimeStarts.getTime());
    K9.setQuietTimeEnds(mQuietTimeEnds.getTime());
    K9.setWrapFolderNames(mWrapFolderNames.isChecked());

    if (mNotificationQuickDelete != null) {
      K9.setNotificationQuickDeleteBehaviour(
          NotificationQuickDelete.valueOf(mNotificationQuickDelete.getValue()));
    }

    if (mLockScreenNotificationVisibility != null) {
      K9.setLockScreenNotificationVisibility(
          K9.LockScreenNotificationVisibility.valueOf(
              mLockScreenNotificationVisibility.getValue()));
    }

    K9.setSplitViewMode(SplitViewMode.valueOf(mSplitViewMode.getValue()));
    K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString());
    boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());

    if (!K9.DEBUG && mDebugLogging.isChecked()) {
      Toast.makeText(this, R.string.debug_logging_enabled, Toast.LENGTH_LONG).show();
    }
    K9.DEBUG = mDebugLogging.isChecked();
    K9.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
    K9.setHideUserAgent(mHideUserAgent.isChecked());
    K9.setHideTimeZone(mHideTimeZone.isChecked());

    Editor editor = preferences.edit();
    K9.save(editor);
    editor.commit();

    if (needsRefresh) {
      MailService.actionReset(this, null);
    }
  }