예제 #1
0
파일: Prefs.java 프로젝트: sidamos/k-9
  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);
    }
  }
예제 #2
0
파일: K9.java 프로젝트: klonikar/k-9
  /**
   * 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));
  }
예제 #3
0
파일: K9.java 프로젝트: kamilk/k-9
  @Override
  public void onCreate() {
    maybeSetupStrictMode();
    super.onCreate();
    app = this;

    galleryBuggy = checkForBuggyGallery();

    Preferences prefs = Preferences.getPreferences(this);
    SharedPreferences sprefs = prefs.getPreferences();
    DEBUG = sprefs.getBoolean("enableDebugLogging", false);
    DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
    mAnimations = sprefs.getBoolean("animations", true);
    mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true);
    mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false);
    mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false);
    mManageBack = sprefs.getBoolean("manageBack", false);
    mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
    mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
    mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
    mHideSpecialAccounts = sprefs.getBoolean("hideSpecialAccounts", false);
    mMessageListStars = sprefs.getBoolean("messageListStars", true);
    mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes", false);
    mMessageListTouchable = sprefs.getBoolean("messageListTouchable", false);
    mMessageListPreviewLines = sprefs.getInt("messageListPreviewLines", 2);

    mMobileOptimizedLayout = sprefs.getBoolean("mobileOptimizedLayout", false);
    mZoomControlsEnabled = sprefs.getBoolean("zoomControlsEnabled", false);

    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);
    mChangeContactNameColor = sprefs.getBoolean("changeRegisteredNameColor", false);
    mContactNameColor = sprefs.getInt("registeredNameColor", 0xff00008f);
    mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
    mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);

    useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy());

    mConfirmDelete = sprefs.getBoolean("confirmDelete", false);

    mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false);

    compactLayouts = sprefs.getBoolean("compactLayouts", false);

    fontSizes.load(sprefs);

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

    K9.setK9Language(sprefs.getString("language", ""));
    K9.setK9Theme(sprefs.getInt("theme", android.R.style.Theme_Light));

    /*
     * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
     * doesn't work in Android and MimeMessage does not have access to a Context.
     */
    BinaryTempFileBody.setTempDirectory(getCacheDir());

    /*
     * Enable background sync of messages
     */

    setServicesEnabled(this);
    registerReceivers();

    MessagingController.getInstance(this)
        .addListener(
            new MessagingListener() {
              private void broadcastIntent(
                  String action, Account account, String folder, Message message) {
                try {
                  Uri uri =
                      Uri.parse(
                          "email://messages/"
                              + account.getAccountNumber()
                              + "/"
                              + Uri.encode(folder)
                              + "/"
                              + Uri.encode(message.getUid()));
                  Intent intent = new Intent(action, uri);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_TO,
                      Address.toString(message.getRecipients(Message.RecipientType.TO)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_CC,
                      Address.toString(message.getRecipients(Message.RecipientType.CC)));
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_BCC,
                      Address.toString(message.getRecipients(Message.RecipientType.BCC)));
                  intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
                  intent.putExtra(
                      K9.Intents.EmailReceived.EXTRA_FROM_SELF,
                      account.isAnIdentity(message.getFrom()));
                  K9.this.sendBroadcast(intent);
                  if (K9.DEBUG)
                    Log.d(
                        K9.LOG_TAG,
                        "Broadcasted: action="
                            + action
                            + " account="
                            + account.getDescription()
                            + " folder="
                            + folder
                            + " message uid="
                            + message.getUid());

                } catch (MessagingException e) {
                  Log.w(
                      K9.LOG_TAG,
                      "Error: action="
                          + action
                          + " account="
                          + account.getDescription()
                          + " folder="
                          + folder
                          + " message uid="
                          + message.getUid());
                }
              }

              @Override
              public void synchronizeMailboxRemovedMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
              }

              @Override
              public void messageDeleted(Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
              }

              @Override
              public void synchronizeMailboxNewMessage(
                  Account account, String folder, Message message) {
                broadcastIntent(
                    K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
              }

              @Override
              public void searchStats(final AccountStats stats) {
                // let observers know a fetch occured
                K9.this.sendBroadcast(
                    new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null));
              }
            });

    notifyObservers();
  }