diff --git a/k9mail/src/main/java/com/fsck/k9/K9.java b/k9mail/src/main/java/com/fsck/k9/K9.java index 8814a3ab1..ac113e51a 100644 --- a/k9mail/src/main/java/com/fsck/k9/K9.java +++ b/k9mail/src/main/java/com/fsck/k9/K9.java @@ -1,6 +1,7 @@ package com.fsck.k9; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -33,13 +34,12 @@ import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.K9MailLib; import com.fsck.k9.mail.Message; -import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.internet.BinaryTempFileBody; +import com.fsck.k9.mail.ssl.LocalKeyStore; import com.fsck.k9.mailstore.LocalStore; import com.fsck.k9.preferences.Storage; import com.fsck.k9.preferences.StorageEditor; import com.fsck.k9.provider.UnreadWidgetProvider; -import com.fsck.k9.mail.ssl.LocalKeyStore; import com.fsck.k9.service.BootReceiver; import com.fsck.k9.service.MailService; import com.fsck.k9.service.ShutdownReceiver; diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java index ed61d9701..1da864819 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java @@ -32,12 +32,11 @@ import com.fsck.k9.preferences.Settings.StringSetting; import com.fsck.k9.preferences.Settings.V; public class AccountSettings { - public static final Map> SETTINGS; - public static final Map UPGRADERS; + static final Map> SETTINGS; + private static final Map UPGRADERS; static { - Map> s = - new LinkedHashMap>(); + Map> s = new LinkedHashMap<>(); /** * When adding new settings here, be sure to increment {@link Settings.VERSION} @@ -85,16 +84,16 @@ public class AccountSettings { R.array.account_setup_expunge_policy_values)) )); s.put("folderDisplayMode", Settings.versions( - new V(1, new EnumSetting(FolderMode.class, FolderMode.NOT_SECOND_CLASS)) + new V(1, new EnumSetting<>(FolderMode.class, FolderMode.NOT_SECOND_CLASS)) )); s.put("folderPushMode", Settings.versions( - new V(1, new EnumSetting(FolderMode.class, FolderMode.FIRST_CLASS)) + new V(1, new EnumSetting<>(FolderMode.class, FolderMode.FIRST_CLASS)) )); s.put("folderSyncMode", Settings.versions( - new V(1, new EnumSetting(FolderMode.class, FolderMode.FIRST_CLASS)) + new V(1, new EnumSetting<>(FolderMode.class, FolderMode.FIRST_CLASS)) )); s.put("folderTargetMode", Settings.versions( - new V(1, new EnumSetting(FolderMode.class, FolderMode.NOT_SECOND_CLASS)) + new V(1, new EnumSetting<>(FolderMode.class, FolderMode.NOT_SECOND_CLASS)) )); s.put("goToUnreadMessageSearch", Settings.versions( new V(1, new BooleanSetting(false)) @@ -129,7 +128,7 @@ public class AccountSettings { R.array.account_settings_message_age_values)) )); s.put("messageFormat", Settings.versions( - new V(1, new EnumSetting( + new V(1, new EnumSetting<>( MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)) )); s.put("messageFormatAuto", Settings.versions( @@ -145,7 +144,7 @@ public class AccountSettings { new V(1, new BooleanSetting(false)) )); s.put("folderNotifyNewMailMode", Settings.versions( - new V(34, new EnumSetting(FolderMode.class, FolderMode.ALL)) + new V(34, new EnumSetting<>(FolderMode.class, FolderMode.ALL)) )); s.put("notifySelfNewMail", Settings.versions( new V(1, new BooleanSetting(true)) @@ -157,8 +156,7 @@ public class AccountSettings { new V(1, new StringSetting(Account.DEFAULT_QUOTE_PREFIX)) )); s.put("quoteStyle", Settings.versions( - new V(1, new EnumSetting( - QuoteStyle.class, Account.DEFAULT_QUOTE_STYLE)) + new V(1, new EnumSetting<>(QuoteStyle.class, Account.DEFAULT_QUOTE_STYLE)) )); s.put("replyAfterQuote", Settings.versions( new V(1, new BooleanSetting(Account.DEFAULT_REPLY_AFTER_QUOTE)) @@ -170,21 +168,19 @@ public class AccountSettings { new V(1, new RingtoneSetting("content://settings/system/notification_sound")) )); s.put("searchableFolders", Settings.versions( - new V(1, new EnumSetting( - Searchable.class, Searchable.ALL)) + new V(1, new EnumSetting<>(Searchable.class, Searchable.ALL)) )); s.put("sentFolderName", Settings.versions( new V(1, new StringSetting("Sent")) )); s.put("sortTypeEnum", Settings.versions( - new V(9, new EnumSetting(SortType.class, Account.DEFAULT_SORT_TYPE)) + new V(9, new EnumSetting<>(SortType.class, Account.DEFAULT_SORT_TYPE)) )); s.put("sortAscending", Settings.versions( new V(9, new BooleanSetting(Account.DEFAULT_SORT_ASCENDING)) )); s.put("showPicturesEnum", Settings.versions( - new V(1, new EnumSetting( - ShowPictures.class, ShowPictures.NEVER)) + new V(1, new EnumSetting<>(ShowPictures.class, ShowPictures.NEVER)) )); s.put("signatureBeforeQuotedText", Settings.versions( new V(1, new BooleanSetting(false)) @@ -240,11 +236,12 @@ public class AccountSettings { SETTINGS = Collections.unmodifiableMap(s); - Map u = new HashMap(); + // noinspection MismatchedQueryAndUpdateOfCollection, this map intentionally left blank + Map u = new HashMap<>(); UPGRADERS = Collections.unmodifiableMap(u); } - public static Map validate(int version, Map importedSettings, + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } @@ -257,8 +254,8 @@ public class AccountSettings { return Settings.convert(settings, SETTINGS); } - public static Map getAccountSettings(Storage storage, String uuid) { - Map result = new HashMap(); + static Map getAccountSettings(Storage storage, String uuid) { + Map result = new HashMap<>(); String prefix = uuid + "."; for (String key : SETTINGS.keySet()) { String value = storage.getString(prefix + key, null); @@ -277,10 +274,10 @@ public class AccountSettings { * integer strings. *

*/ - public static class IntegerResourceSetting extends PseudoEnumSetting { + private static class IntegerResourceSetting extends PseudoEnumSetting { private final Map mMapping; - public IntegerResourceSetting(int defaultValue, int resId) { + IntegerResourceSetting(int defaultValue, int resId) { super(defaultValue); Map mapping = new HashMap<>(); @@ -314,13 +311,13 @@ public class AccountSettings { * Basically a {@link PseudoEnumSetting} that is initialized from a resource array. *

*/ - public static class StringResourceSetting extends PseudoEnumSetting { + private static class StringResourceSetting extends PseudoEnumSetting { private final Map mMapping; - public StringResourceSetting(String defaultValue, int resId) { + StringResourceSetting(String defaultValue, int resId) { super(defaultValue); - Map mapping = new HashMap(); + Map mapping = new HashMap<>(); String[] values = K9.app.getResources().getStringArray(resId); for (String value : values) { mapping.put(value, value); @@ -345,8 +342,8 @@ public class AccountSettings { /** * The notification ringtone setting. */ - public static class RingtoneSetting extends SettingsDescription { - public RingtoneSetting(String defaultValue) { + private static class RingtoneSetting extends SettingsDescription { + RingtoneSetting(String defaultValue) { super(defaultValue); } @@ -360,8 +357,8 @@ public class AccountSettings { /** * The storage provider setting. */ - public static class StorageProviderSetting extends SettingsDescription { - public StorageProviderSetting() { + private static class StorageProviderSetting extends SettingsDescription { + StorageProviderSetting() { super(null); } @@ -381,10 +378,10 @@ public class AccountSettings { } } - public static class DeletePolicySetting extends PseudoEnumSetting { + private static class DeletePolicySetting extends PseudoEnumSetting { private Map mMapping; - public DeletePolicySetting(DeletePolicy defaultValue) { + DeletePolicySetting(DeletePolicy defaultValue) { super(defaultValue.setting); Map mapping = new HashMap<>(); mapping.put(DeletePolicy.NEVER.setting, "NEVER"); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java index 14ce3c314..d9f97044e 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java @@ -10,13 +10,12 @@ import java.util.TreeMap; import com.fsck.k9.mail.Folder.FolderClass; import com.fsck.k9.preferences.Settings.*; -public class FolderSettings { - public static final Map> SETTINGS; - public static final Map UPGRADERS; +class FolderSettings { + static final Map> SETTINGS; + private static final Map UPGRADERS; static { - Map> s = - new LinkedHashMap>(); + Map> s = new LinkedHashMap<>(); /** * When adding new settings here, be sure to increment {@link Settings.VERSION} @@ -24,16 +23,16 @@ public class FolderSettings { */ s.put("displayMode", Settings.versions( - new V(1, new EnumSetting(FolderClass.class, FolderClass.NO_CLASS)) + new V(1, new EnumSetting<>(FolderClass.class, FolderClass.NO_CLASS)) )); s.put("notifyMode", Settings.versions( - new V(34, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) + new V(34, new EnumSetting<>(FolderClass.class, FolderClass.INHERITED)) )); s.put("syncMode", Settings.versions( - new V(1, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) + new V(1, new EnumSetting<>(FolderClass.class, FolderClass.INHERITED)) )); s.put("pushMode", Settings.versions( - new V(1, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) + new V(1, new EnumSetting<>(FolderClass.class, FolderClass.INHERITED)) )); s.put("inTopGroup", Settings.versions( new V(1, new BooleanSetting(false)) @@ -44,11 +43,12 @@ public class FolderSettings { SETTINGS = Collections.unmodifiableMap(s); - Map u = new HashMap(); + // noinspection MismatchedQueryAndUpdateOfCollection, this map intentionally left blank + Map u = new HashMap<>(); UPGRADERS = Collections.unmodifiableMap(u); } - public static Map validate(int version, Map importedSettings, + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } @@ -61,9 +61,9 @@ public class FolderSettings { return Settings.convert(settings, SETTINGS); } - public static Map getFolderSettings(Storage storage, String uuid, + static Map getFolderSettings(Storage storage, String uuid, String folderName) { - Map result = new HashMap(); + Map result = new HashMap<>(); String prefix = uuid + "." + folderName + "."; for (String key : SETTINGS.keySet()) { String value = storage.getString(prefix + key, null); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java index b603b38ac..89bcc5d2e 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java @@ -2,7 +2,6 @@ package com.fsck.k9.preferences; import java.io.File; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -37,12 +36,11 @@ import com.fsck.k9.preferences.Settings.WebFontSizeSetting; import static com.fsck.k9.K9.LockScreenNotificationVisibility; public class GlobalSettings { - public static final Map> SETTINGS; - public static final Map UPGRADERS; + static final Map> SETTINGS; + private static final Map UPGRADERS; static { - Map> s = - new LinkedHashMap>(); + Map> s = new LinkedHashMap<>(); /** * When adding new settings here, be sure to increment {@link Settings.VERSION} @@ -58,7 +56,7 @@ public class GlobalSettings { Environment.DIRECTORY_DOWNLOADS))) )); s.put("backgroundOperations", Settings.versions( - new V(1, new EnumSetting( + new V(1, new EnumSetting<>( K9.BACKGROUND_OPS.class, K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC)) )); s.put("changeRegisteredNameColor", Settings.versions( @@ -191,7 +189,7 @@ public class GlobalSettings { new V(1, new BooleanSetting(true)) )); s.put("sortTypeEnum", Settings.versions( - new V(10, new EnumSetting(SortType.class, Account.DEFAULT_SORT_TYPE)) + new V(10, new EnumSetting<>(SortType.class, Account.DEFAULT_SORT_TYPE)) )); s.put("sortAscending", Settings.versions( new V(10, new BooleanSetting(Account.DEFAULT_SORT_ASCENDING)) @@ -216,7 +214,7 @@ public class GlobalSettings { new V(22, new BooleanSetting(false)) )); s.put("notificationHideSubject", Settings.versions( - new V(12, new EnumSetting( + new V(12, new EnumSetting<>( NotificationHideSubject.class, NotificationHideSubject.NEVER)) )); s.put("useBackgroundAsUnreadIndicator", Settings.versions( @@ -226,7 +224,7 @@ public class GlobalSettings { new V(20, new BooleanSetting(true)) )); s.put("splitViewMode", Settings.versions( - new V(23, new EnumSetting(SplitViewMode.class, SplitViewMode.NEVER)) + new V(23, new EnumSetting<>(SplitViewMode.class, SplitViewMode.NEVER)) )); s.put("messageComposeTheme", Settings.versions( new V(24, new SubThemeSetting(K9.Theme.USE_GLOBAL)) @@ -268,7 +266,7 @@ public class GlobalSettings { new V(32, new BooleanSetting(false)) )); s.put("lockScreenNotificationVisibility", Settings.versions( - new V(37, new EnumSetting(LockScreenNotificationVisibility.class, + new V(37, new EnumSetting<>(LockScreenNotificationVisibility.class, LockScreenNotificationVisibility.MESSAGE_COUNT)) )); s.put("confirmDeleteFromNotification", Settings.versions( @@ -278,7 +276,7 @@ public class GlobalSettings { new V(38, new BooleanSetting(false)) )); s.put("notificationQuickDelete", Settings.versions( - new V(38, new EnumSetting(NotificationQuickDelete.class, + new V(38, new EnumSetting<>(NotificationQuickDelete.class, NotificationQuickDelete.NEVER)) )); s.put("notificationDuringQuietTimeEnabled", Settings.versions( @@ -293,7 +291,7 @@ public class GlobalSettings { SETTINGS = Collections.unmodifiableMap(s); - Map u = new HashMap(); + Map u = new HashMap<>(); u.put(12, new SettingsUpgraderV12()); u.put(24, new SettingsUpgraderV24()); u.put(31, new SettingsUpgraderV31()); @@ -301,7 +299,7 @@ public class GlobalSettings { UPGRADERS = Collections.unmodifiableMap(u); } - public static Map validate(int version, Map importedSettings) { + static Map validate(int version, Map importedSettings) { return Settings.validate(version, SETTINGS, importedSettings, false); } @@ -313,8 +311,8 @@ public class GlobalSettings { return Settings.convert(settings, SETTINGS); } - public static Map getGlobalSettings(Storage storage) { - Map result = new HashMap(); + static Map getGlobalSettings(Storage storage) { + Map result = new HashMap<>(); for (String key : SETTINGS.keySet()) { String value = storage.getString(key, null); if (value != null) { @@ -329,19 +327,19 @@ public class GlobalSettings { * * Map the 'keyguardPrivacy' value to the new NotificationHideSubject enum. */ - public static class SettingsUpgraderV12 implements SettingsUpgrader { + private static class SettingsUpgraderV12 implements SettingsUpgrader { @Override public Set upgrade(Map settings) { Boolean keyguardPrivacy = (Boolean) settings.get("keyguardPrivacy"); - if (keyguardPrivacy != null && keyguardPrivacy.booleanValue()) { + if (keyguardPrivacy != null && keyguardPrivacy) { // current setting: only show subject when unlocked settings.put("notificationHideSubject", NotificationHideSubject.WHEN_LOCKED); } else { // always show subject [old default] settings.put("notificationHideSubject", NotificationHideSubject.NEVER); } - return new HashSet(Arrays.asList("keyguardPrivacy")); + return new HashSet<>(Collections.singletonList("keyguardPrivacy")); } } @@ -353,7 +351,7 @@ public class GlobalSettings { * the same value as theme. *

*/ - public static class SettingsUpgraderV24 implements SettingsUpgrader { + private static class SettingsUpgraderV24 implements SettingsUpgrader { @Override public Set upgrade(Map settings) { @@ -379,13 +377,13 @@ public class GlobalSettings { @Override public Set upgrade(Map settings) { - int oldSize = ((Integer) settings.get("fontSizeMessageViewContent")).intValue(); + int oldSize = (Integer) settings.get("fontSizeMessageViewContent"); int newSize = convertFromOldSize(oldSize); settings.put("fontSizeMessageViewContentPercent", newSize); - return new HashSet(Arrays.asList("fontSizeMessageViewContent")); + return new HashSet<>(Collections.singletonList("fontSizeMessageViewContent")); } public static int convertFromOldSize(int oldSize) { @@ -418,13 +416,13 @@ public class GlobalSettings { * {@code res/values/arrays.xml}. *

*/ - public static class LanguageSetting extends PseudoEnumSetting { + private static class LanguageSetting extends PseudoEnumSetting { private final Map mMapping; - public LanguageSetting() { + LanguageSetting() { super(""); - Map mapping = new HashMap(); + Map mapping = new HashMap<>(); String[] values = K9.app.getResources().getStringArray(R.array.settings_language_values); for (String value : values) { if (value.length() == 0) { @@ -454,11 +452,11 @@ public class GlobalSettings { /** * The theme setting. */ - public static class ThemeSetting extends SettingsDescription { + static class ThemeSetting extends SettingsDescription { private static final String THEME_LIGHT = "light"; private static final String THEME_DARK = "dark"; - public ThemeSetting(K9.Theme defaultValue) { + ThemeSetting(K9.Theme defaultValue) { super(defaultValue); } @@ -512,10 +510,10 @@ public class GlobalSettings { /** * The message view theme setting. */ - public static class SubThemeSetting extends ThemeSetting { + private static class SubThemeSetting extends ThemeSetting { private static final String THEME_USE_GLOBAL = "use_global"; - public SubThemeSetting(Theme defaultValue) { + SubThemeSetting(Theme defaultValue) { super(defaultValue); } @@ -555,8 +553,8 @@ public class GlobalSettings { /** * A time setting. */ - public static class TimeSetting extends SettingsDescription { - public TimeSetting(String defaultValue) { + private static class TimeSetting extends SettingsDescription { + TimeSetting(String defaultValue) { super(defaultValue); } @@ -572,8 +570,8 @@ public class GlobalSettings { /** * A directory on the file system. */ - public static class DirectorySetting extends SettingsDescription { - public DirectorySetting(File defaultPath) { + private static class DirectorySetting extends SettingsDescription { + DirectorySetting(File defaultPath) { super(defaultPath.toString()); } diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java index b09e80182..fa82f6f62 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java @@ -12,13 +12,13 @@ import com.fsck.k9.K9; import com.fsck.k9.R; import com.fsck.k9.preferences.Settings.*; -public class IdentitySettings { - public static final Map> SETTINGS; - public static final Map UPGRADERS; +class IdentitySettings { + static final Map> SETTINGS; + private static final Map UPGRADERS; static { Map> s = - new LinkedHashMap>(); + new LinkedHashMap<>(); /** * When adding new settings here, be sure to increment {@link Settings.VERSION} @@ -37,11 +37,12 @@ public class IdentitySettings { SETTINGS = Collections.unmodifiableMap(s); - Map u = new HashMap(); + // noinspection MismatchedQueryAndUpdateOfCollection, this map intentionally left blank + Map u = new HashMap<>(); UPGRADERS = Collections.unmodifiableMap(u); } - public static Map validate(int version, Map importedSettings, + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } @@ -54,9 +55,9 @@ public class IdentitySettings { return Settings.convert(settings, SETTINGS); } - public static Map getIdentitySettings(Storage storage, String uuid, + static Map getIdentitySettings(Storage storage, String uuid, int identityIndex) { - Map result = new HashMap(); + Map result = new HashMap<>(); String prefix = uuid + "."; String suffix = "." + Integer.toString(identityIndex); for (String key : SETTINGS.keySet()) { @@ -69,15 +70,15 @@ public class IdentitySettings { } - public static boolean isEmailAddressValid(String email) { + static boolean isEmailAddressValid(String email) { return new EmailAddressValidator().isValidAddressOnly(email); } /** * The message signature setting. */ - public static class SignatureSetting extends SettingsDescription { - public SignatureSetting() { + private static class SignatureSetting extends SettingsDescription { + SignatureSetting() { super(null); } @@ -95,10 +96,10 @@ public class IdentitySettings { /** * An optional email address setting. */ - public static class OptionalEmailAddressSetting extends SettingsDescription { + private static class OptionalEmailAddressSetting extends SettingsDescription { private EmailAddressValidator mValidator; - public OptionalEmailAddressSetting() { + OptionalEmailAddressSetting() { super(null); mValidator = new EmailAddressValidator(); } diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java index 155b7f298..195c4b5bf 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java @@ -1,13 +1,14 @@ package com.fsck.k9.preferences; + import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; -import java.util.Map.Entry; import android.util.Log; @@ -225,8 +226,7 @@ public class Settings { * @return A {@code TreeMap} using the version number as key, the {@code SettingsDescription} * as value. */ - static TreeMap versions( - V... versionDescriptions) { + static TreeMap versions(V... versionDescriptions) { TreeMap map = new TreeMap<>(); for (V v : versionDescriptions) { map.put(v.version, v.description);