public static void save(SharedPreferences.Editor editor) { editor.putBoolean("enableDebugLogging", K9.DEBUG); editor.putBoolean("enableSensitiveLogging", K9.DEBUG_SENSITIVE); editor.putString("backgroundOperations", K9.backgroundOps.toString()); editor.putBoolean("animations", mAnimations); editor.putBoolean("gesturesEnabled", mGesturesEnabled); editor.putBoolean("useVolumeKeysForNavigation", mUseVolumeKeysForNavigation); editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation); editor.putBoolean("manageBack", mManageBack); editor.putBoolean("zoomControlsEnabled", mZoomControlsEnabled); editor.putBoolean("mobileOptimizedLayout", mMobileOptimizedLayout); editor.putBoolean("quietTimeEnabled", mQuietTimeEnabled); editor.putString("quietTimeStarts", mQuietTimeStarts); editor.putString("quietTimeEnds", mQuietTimeEnds); editor.putBoolean("startIntegratedInbox", mStartIntegratedInbox); editor.putBoolean("measureAccounts", mMeasureAccounts); editor.putBoolean("countSearchMessages", mCountSearchMessages); editor.putBoolean("hideSpecialAccounts", mHideSpecialAccounts); editor.putBoolean("messageListStars", mMessageListStars); editor.putBoolean("messageListCheckboxes", mMessageListCheckboxes); editor.putBoolean("messageListTouchable", mMessageListTouchable); editor.putInt("messageListPreviewLines", mMessageListPreviewLines); editor.putBoolean("showCorrespondentNames", mShowCorrespondentNames); editor.putBoolean("showContactName", mShowContactName); editor.putBoolean("changeRegisteredNameColor", mChangeContactNameColor); editor.putInt("registeredNameColor", mContactNameColor); editor.putBoolean("messageViewFixedWidthFont", mMessageViewFixedWidthFont); editor.putBoolean("messageViewReturnToList", mMessageViewReturnToList); editor.putString("language", language); editor.putInt("theme", theme); editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround); editor.putBoolean("confirmDelete", mConfirmDelete); editor.putBoolean("keyguardPrivacy", mKeyguardPrivacy); editor.putBoolean("compactLayouts", compactLayouts); fontSizes.save(editor); }
/** * 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)); }
/** * Save settings from our statics into the app database. * * <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 editor Preferences to save into */ public static void save(SharedPreferences.Editor editor) { editor.putBoolean("enableDebugLogging", K9.DEBUG); editor.putBoolean("enableSensitiveLogging", K9.DEBUG_SENSITIVE); editor.putString("backgroundOperations", K9.backgroundOps.name()); editor.putBoolean("animations", mAnimations); editor.putBoolean("gesturesEnabled", mGesturesEnabled); editor.putBoolean("useVolumeKeysForNavigation", mUseVolumeKeysForNavigation); editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation); editor.putBoolean("autofitWidth", mAutofitWidth); editor.putBoolean("quietTimeEnabled", mQuietTimeEnabled); editor.putString("quietTimeStarts", mQuietTimeStarts); editor.putString("quietTimeEnds", mQuietTimeEnds); editor.putBoolean("startIntegratedInbox", mStartIntegratedInbox); editor.putBoolean("measureAccounts", mMeasureAccounts); editor.putBoolean("countSearchMessages", mCountSearchMessages); editor.putBoolean("messageListSenderAboveSubject", mMessageListSenderAboveSubject); editor.putBoolean("hideSpecialAccounts", mHideSpecialAccounts); editor.putBoolean("messageListStars", mMessageListStars); editor.putInt("messageListPreviewLines", mMessageListPreviewLines); editor.putBoolean("messageListCheckboxes", mMessageListCheckboxes); editor.putBoolean("showCorrespondentNames", mShowCorrespondentNames); editor.putBoolean("showContactName", mShowContactName); editor.putBoolean("showContactPicture", sShowContactPicture); editor.putBoolean("changeRegisteredNameColor", mChangeContactNameColor); editor.putInt("registeredNameColor", mContactNameColor); editor.putBoolean("messageViewFixedWidthFont", mMessageViewFixedWidthFont); editor.putBoolean("messageViewReturnToList", mMessageViewReturnToList); editor.putBoolean("messageViewShowNext", mMessageViewShowNext); editor.putBoolean("wrapFolderNames", mWrapFolderNames); editor.putBoolean("hideUserAgent", mHideUserAgent); editor.putBoolean("hideTimeZone", mHideTimeZone); editor.putString("language", language); editor.putInt("theme", theme.ordinal()); editor.putInt("messageViewTheme", messageViewTheme.ordinal()); editor.putInt("messageComposeTheme", composerTheme.ordinal()); editor.putBoolean("fixedMessageViewTheme", useFixedMessageTheme); editor.putBoolean("confirmDelete", mConfirmDelete); editor.putBoolean("confirmDeleteStarred", mConfirmDeleteStarred); editor.putBoolean("confirmSpam", mConfirmSpam); editor.putBoolean("confirmDeleteFromNotification", mConfirmDeleteFromNotification); editor.putString("sortTypeEnum", mSortType.name()); editor.putBoolean("sortAscending", mSortAscending.get(mSortType)); editor.putString("notificationHideSubject", sNotificationHideSubject.toString()); editor.putString("notificationQuickDelete", sNotificationQuickDelete.toString()); editor.putString( "lockScreenNotificationVisibility", sLockScreenNotificationVisibility.toString()); editor.putString("attachmentdefaultpath", mAttachmentDefaultPath); editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator); editor.putBoolean("threadedView", sThreadedViewEnabled); editor.putString("splitViewMode", sSplitViewMode.name()); editor.putBoolean("colorizeMissingContactPictures", sColorizeMissingContactPictures); editor.putBoolean("messageViewArchiveActionVisible", sMessageViewArchiveActionVisible); editor.putBoolean("messageViewDeleteActionVisible", sMessageViewDeleteActionVisible); editor.putBoolean("messageViewMoveActionVisible", sMessageViewMoveActionVisible); editor.putBoolean("messageViewCopyActionVisible", sMessageViewCopyActionVisible); editor.putBoolean("messageViewSpamActionVisible", sMessageViewSpamActionVisible); fontSizes.save(editor); }
@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(); }