2011-04-20 15:37:48 -04:00
|
|
|
package com.fsck.k9.preferences;
|
|
|
|
|
2011-10-16 22:52:33 -04:00
|
|
|
import java.io.File;
|
2012-08-01 19:41:40 -04:00
|
|
|
import java.util.Arrays;
|
2011-10-07 14:29:03 -04:00
|
|
|
import java.util.Collections;
|
2011-05-01 22:06:22 -04:00
|
|
|
import java.util.HashMap;
|
2012-08-01 19:41:40 -04:00
|
|
|
import java.util.HashSet;
|
2011-04-20 15:37:48 -04:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
2011-12-10 22:57:47 -05:00
|
|
|
import java.util.Set;
|
2011-12-10 23:16:22 -05:00
|
|
|
import java.util.TreeMap;
|
|
|
|
|
2011-05-01 22:06:22 -04:00
|
|
|
import android.content.SharedPreferences;
|
2011-10-16 22:52:33 -04:00
|
|
|
import android.os.Environment;
|
|
|
|
|
2012-05-15 02:13:30 -04:00
|
|
|
import com.fsck.k9.Account;
|
2011-04-20 15:37:48 -04:00
|
|
|
import com.fsck.k9.FontSizes;
|
|
|
|
import com.fsck.k9.K9;
|
2012-08-01 19:41:40 -04:00
|
|
|
import com.fsck.k9.K9.NotificationHideSubject;
|
2013-01-24 14:30:07 -05:00
|
|
|
import com.fsck.k9.K9.SplitViewMode;
|
2013-02-07 10:55:42 -05:00
|
|
|
import com.fsck.k9.K9.Theme;
|
2011-04-20 15:37:48 -04:00
|
|
|
import com.fsck.k9.R;
|
2012-05-15 02:13:30 -04:00
|
|
|
import com.fsck.k9.Account.SortType;
|
2011-04-20 15:37:48 -04:00
|
|
|
import com.fsck.k9.preferences.Settings.*;
|
|
|
|
|
2014-12-04 00:57:50 -05:00
|
|
|
import static com.fsck.k9.K9.LockScreenNotificationVisibility;
|
|
|
|
|
2011-04-20 15:37:48 -04:00
|
|
|
public class GlobalSettings {
|
2011-12-10 23:16:22 -05:00
|
|
|
public static final Map<String, TreeMap<Integer, SettingsDescription>> SETTINGS;
|
2011-12-10 22:57:47 -05:00
|
|
|
public static final Map<Integer, SettingsUpgrader> UPGRADERS;
|
2011-04-20 15:37:48 -04:00
|
|
|
|
|
|
|
static {
|
2011-12-10 23:16:22 -05:00
|
|
|
Map<String, TreeMap<Integer, SettingsDescription>> s =
|
|
|
|
new LinkedHashMap<String, TreeMap<Integer, SettingsDescription>>();
|
2011-04-20 15:37:48 -04:00
|
|
|
|
2012-04-08 18:27:39 -04:00
|
|
|
/**
|
|
|
|
* When adding new settings here, be sure to increment {@link Settings.VERSION}
|
|
|
|
* and use that for whatever you add here.
|
|
|
|
*/
|
|
|
|
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("animations", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("attachmentdefaultpath", Settings.versions(
|
|
|
|
new V(1, new DirectorySetting(Environment.getExternalStorageDirectory().toString()))
|
|
|
|
));
|
|
|
|
s.put("backgroundOperations", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(1, new EnumSetting<K9.BACKGROUND_OPS>(
|
2014-03-14 12:47:41 -04:00
|
|
|
K9.BACKGROUND_OPS.class, K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("changeRegisteredNameColor", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("confirmDelete", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("confirmDeleteStarred", Settings.versions(
|
2011-12-10 23:03:53 -05:00
|
|
|
new V(2, new BooleanSetting(false))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("confirmSpam", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("countSearchMessages", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("enableDebugLogging", Settings.versions(
|
2012-10-16 16:48:31 -04:00
|
|
|
new V(1, new BooleanSetting(false))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("enableSensitiveLogging", Settings.versions(
|
2012-10-16 16:48:31 -04:00
|
|
|
new V(1, new BooleanSetting(false))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeAccountDescription", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeAccountName", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeFolderName", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeFolderStatus", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
2012-01-11 19:05:01 -05:00
|
|
|
s.put("fontSizeMessageComposeInput", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(5, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2012-01-11 19:05:01 -05:00
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("fontSizeMessageListDate", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageListPreview", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageListSender", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageListSubject", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewAdditionalHeaders", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewCC", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewContent", Settings.versions(
|
2014-02-12 22:22:45 -05:00
|
|
|
new V(1, new WebFontSizeSetting(3)),
|
|
|
|
new V(31, null)
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewDate", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewSender", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewSubject", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewTime", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("fontSizeMessageViewTo", Settings.versions(
|
2013-02-08 21:19:22 -05:00
|
|
|
new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("gesturesEnabled", Settings.versions(
|
2012-01-05 19:36:32 -05:00
|
|
|
new V(1, new BooleanSetting(true)),
|
|
|
|
new V(4, new BooleanSetting(false))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("hideSpecialAccounts", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("keyguardPrivacy", Settings.versions(
|
2012-08-01 19:41:40 -04:00
|
|
|
new V(1, new BooleanSetting(false)),
|
|
|
|
new V(12, null)
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
|
|
|
s.put("language", Settings.versions(
|
|
|
|
new V(1, new LanguageSetting())
|
|
|
|
));
|
|
|
|
s.put("measureAccounts", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(true))
|
|
|
|
));
|
2012-10-09 18:22:00 -04:00
|
|
|
s.put("messageListCheckboxes", Settings.versions(
|
2013-08-16 16:01:35 -04:00
|
|
|
new V(1, new BooleanSetting(false))
|
2012-10-09 18:22:00 -04:00
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("messageListPreviewLines", Settings.versions(
|
|
|
|
new V(1, new IntegerRangeSetting(1, 100, 2))
|
|
|
|
));
|
2013-08-16 02:48:41 -04:00
|
|
|
s.put("messageListStars", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(true))
|
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("messageViewFixedWidthFont", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("messageViewReturnToList", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("messageViewShowNext", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("quietTimeEnabled", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("quietTimeEnds", Settings.versions(
|
|
|
|
new V(1, new TimeSetting("7:00"))
|
|
|
|
));
|
|
|
|
s.put("quietTimeStarts", Settings.versions(
|
|
|
|
new V(1, new TimeSetting("21:00"))
|
|
|
|
));
|
|
|
|
s.put("registeredNameColor", Settings.versions(
|
|
|
|
new V(1, new ColorSetting(0xFF00008F))
|
|
|
|
));
|
|
|
|
s.put("showContactName", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("showCorrespondentNames", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(true))
|
|
|
|
));
|
2012-05-15 02:13:30 -04:00
|
|
|
s.put("sortTypeEnum", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(10, new EnumSetting<SortType>(SortType.class, Account.DEFAULT_SORT_TYPE))
|
2012-05-15 02:13:30 -04:00
|
|
|
));
|
|
|
|
s.put("sortAscending", Settings.versions(
|
|
|
|
new V(10, new BooleanSetting(Account.DEFAULT_SORT_ASCENDING))
|
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("startIntegratedInbox", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("theme", Settings.versions(
|
2013-02-07 10:55:42 -05:00
|
|
|
new V(1, new ThemeSetting(K9.Theme.LIGHT))
|
2011-12-10 23:16:22 -05:00
|
|
|
));
|
2012-09-13 20:25:39 -04:00
|
|
|
s.put("messageViewTheme", Settings.versions(
|
2013-02-07 10:55:42 -05:00
|
|
|
new V(16, new ThemeSetting(K9.Theme.LIGHT)),
|
|
|
|
new V(24, new SubThemeSetting(K9.Theme.USE_GLOBAL))
|
2012-09-13 20:25:39 -04:00
|
|
|
));
|
2011-12-10 23:16:22 -05:00
|
|
|
s.put("useVolumeKeysForListNavigation", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
|
|
|
s.put("useVolumeKeysForNavigation", Settings.versions(
|
|
|
|
new V(1, new BooleanSetting(false))
|
|
|
|
));
|
2012-11-26 17:50:43 -05:00
|
|
|
s.put("wrapFolderNames", Settings.versions(
|
2012-12-22 23:31:23 -05:00
|
|
|
new V(22, new BooleanSetting(false))
|
2012-11-26 17:50:43 -05:00
|
|
|
));
|
2012-08-01 20:31:54 -04:00
|
|
|
s.put("notificationHideSubject", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(12, new EnumSetting<NotificationHideSubject>(
|
|
|
|
NotificationHideSubject.class, NotificationHideSubject.NEVER))
|
2012-08-01 20:31:54 -04:00
|
|
|
));
|
2012-10-02 16:56:06 -04:00
|
|
|
s.put("useBackgroundAsUnreadIndicator", Settings.versions(
|
|
|
|
new V(19, new BooleanSetting(true))
|
|
|
|
));
|
2012-10-28 15:10:52 -04:00
|
|
|
s.put("threadedView", Settings.versions(
|
|
|
|
new V(20, new BooleanSetting(true))
|
|
|
|
));
|
2013-01-24 14:30:07 -05:00
|
|
|
s.put("splitViewMode", Settings.versions(
|
2013-02-04 05:18:49 -05:00
|
|
|
new V(23, new EnumSetting<SplitViewMode>(SplitViewMode.class, SplitViewMode.NEVER))
|
2013-01-24 14:30:07 -05:00
|
|
|
));
|
2013-02-07 10:55:42 -05:00
|
|
|
s.put("messageComposeTheme", Settings.versions(
|
|
|
|
new V(24, new SubThemeSetting(K9.Theme.USE_GLOBAL))
|
|
|
|
));
|
|
|
|
s.put("fixedMessageViewTheme", Settings.versions(
|
|
|
|
new V(24, new BooleanSetting(true))
|
|
|
|
));
|
2013-02-08 09:41:14 -05:00
|
|
|
s.put("showContactPicture", Settings.versions(
|
|
|
|
new V(25, new BooleanSetting(true))
|
|
|
|
));
|
2013-04-04 17:11:17 -04:00
|
|
|
s.put("autofitWidth", Settings.versions(
|
2013-05-08 23:10:01 -04:00
|
|
|
new V(28, new BooleanSetting(true))
|
2013-04-04 17:11:17 -04:00
|
|
|
));
|
2013-08-16 12:42:13 -04:00
|
|
|
s.put("colorizeMissingContactPictures", Settings.versions(
|
|
|
|
new V(29, new BooleanSetting(true))
|
|
|
|
));
|
2013-08-24 05:34:52 -04:00
|
|
|
s.put("messageViewDeleteActionVisible", Settings.versions(
|
|
|
|
new V(30, new BooleanSetting(true))
|
|
|
|
));
|
|
|
|
s.put("messageViewArchiveActionVisible", Settings.versions(
|
2013-08-25 06:35:14 -04:00
|
|
|
new V(30, new BooleanSetting(false))
|
2013-08-24 05:34:52 -04:00
|
|
|
));
|
|
|
|
s.put("messageViewMoveActionVisible", Settings.versions(
|
2013-08-25 06:35:14 -04:00
|
|
|
new V(30, new BooleanSetting(false))
|
2013-08-24 05:34:52 -04:00
|
|
|
));
|
|
|
|
s.put("messageViewCopyActionVisible", Settings.versions(
|
2013-08-25 06:35:14 -04:00
|
|
|
new V(30, new BooleanSetting(false))
|
2013-08-24 05:34:52 -04:00
|
|
|
));
|
|
|
|
s.put("messageViewSpamActionVisible", Settings.versions(
|
2013-08-25 06:35:14 -04:00
|
|
|
new V(30, new BooleanSetting(false))
|
2013-08-24 05:34:52 -04:00
|
|
|
));
|
2014-02-12 22:22:45 -05:00
|
|
|
s.put("fontSizeMessageViewContentPercent", Settings.versions(
|
|
|
|
new V(31, new IntegerRangeSetting(40, 250, 100))
|
|
|
|
));
|
2014-05-26 17:57:25 -04:00
|
|
|
s.put("hideUserAgent", Settings.versions(
|
|
|
|
new V(32, new BooleanSetting(false))
|
|
|
|
));
|
2014-05-26 20:14:07 -04:00
|
|
|
s.put("hideTimeZone", Settings.versions(
|
|
|
|
new V(32, new BooleanSetting(false))
|
|
|
|
));
|
2014-12-04 00:57:50 -05:00
|
|
|
s.put("lockScreenNotificationVisibility", Settings.versions(
|
|
|
|
new V(37, new EnumSetting<>(LockScreenNotificationVisibility.class, LockScreenNotificationVisibility.MESSAGE_COUNT))
|
|
|
|
));
|
2011-10-07 15:20:12 -04:00
|
|
|
|
|
|
|
SETTINGS = Collections.unmodifiableMap(s);
|
2011-12-10 22:57:47 -05:00
|
|
|
|
|
|
|
Map<Integer, SettingsUpgrader> u = new HashMap<Integer, SettingsUpgrader>();
|
2012-08-01 20:31:54 -04:00
|
|
|
u.put(12, new SettingsUpgraderV12());
|
2013-02-07 10:55:42 -05:00
|
|
|
u.put(24, new SettingsUpgraderV24());
|
2014-02-12 22:22:45 -05:00
|
|
|
u.put(31, new SettingsUpgraderV31());
|
2012-08-01 20:31:54 -04:00
|
|
|
|
2011-12-10 22:57:47 -05:00
|
|
|
UPGRADERS = Collections.unmodifiableMap(u);
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Map<String, Object> validate(int version, Map<String, String> importedSettings) {
|
2011-12-10 23:16:22 -05:00
|
|
|
return Settings.validate(version, SETTINGS, importedSettings, false);
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Set<String> upgrade(int version, Map<String, Object> validatedSettings) {
|
2011-12-10 22:57:47 -05:00
|
|
|
return Settings.upgrade(version, UPGRADERS, SETTINGS, validatedSettings);
|
|
|
|
}
|
|
|
|
|
2011-12-11 00:02:31 -05:00
|
|
|
public static Map<String, String> convert(Map<String, Object> settings) {
|
|
|
|
return Settings.convert(settings, SETTINGS);
|
|
|
|
}
|
|
|
|
|
2011-05-01 22:06:22 -04:00
|
|
|
public static Map<String, String> getGlobalSettings(SharedPreferences storage) {
|
|
|
|
Map<String, String> result = new HashMap<String, String>();
|
|
|
|
for (String key : SETTINGS.keySet()) {
|
|
|
|
String value = storage.getString(key, null);
|
|
|
|
if (value != null) {
|
|
|
|
result.put(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:41:40 -04:00
|
|
|
/**
|
2012-08-01 20:31:54 -04:00
|
|
|
* Upgrades the settings from version 11 to 12
|
|
|
|
*
|
|
|
|
* Map the 'keyguardPrivacy' value to the new NotificationHideSubject enum.
|
2012-08-01 19:41:40 -04:00
|
|
|
*/
|
2012-08-01 20:31:54 -04:00
|
|
|
public static class SettingsUpgraderV12 implements SettingsUpgrader {
|
2012-08-01 19:41:40 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<String> upgrade(Map<String, Object> settings) {
|
|
|
|
Boolean keyguardPrivacy = (Boolean) settings.get("keyguardPrivacy");
|
2012-08-01 20:31:54 -04:00
|
|
|
if (keyguardPrivacy != null && keyguardPrivacy.booleanValue()) {
|
2012-08-01 19:41:40 -04:00
|
|
|
// current setting: only show subject when unlocked
|
2012-08-01 20:31:54 -04:00
|
|
|
settings.put("notificationHideSubject", NotificationHideSubject.WHEN_LOCKED);
|
2012-08-01 19:41:40 -04:00
|
|
|
} else {
|
|
|
|
// always show subject [old default]
|
2012-08-01 20:31:54 -04:00
|
|
|
settings.put("notificationHideSubject", NotificationHideSubject.NEVER);
|
2012-08-01 19:41:40 -04:00
|
|
|
}
|
2012-08-01 20:20:33 -04:00
|
|
|
return new HashSet<String>(Arrays.asList("keyguardPrivacy"));
|
2012-08-01 19:41:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 10:55:42 -05:00
|
|
|
/**
|
|
|
|
* Upgrades the settings from version 23 to 24.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Set <em>messageViewTheme</em> to {@link K9.Theme#USE_GLOBAL} if <em>messageViewTheme</em> has
|
|
|
|
* the same value as <em>theme</em>.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
public static class SettingsUpgraderV24 implements SettingsUpgrader {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<String> upgrade(Map<String, Object> settings) {
|
|
|
|
K9.Theme messageViewTheme = (K9.Theme) settings.get("messageViewTheme");
|
|
|
|
K9.Theme theme = (K9.Theme) settings.get("theme");
|
|
|
|
if (theme != null && messageViewTheme != null && theme == messageViewTheme) {
|
|
|
|
settings.put("messageViewTheme", K9.Theme.USE_GLOBAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 22:22:45 -05:00
|
|
|
/**
|
|
|
|
* Upgrades the settings from version 30 to 31.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Convert value from <em>fontSizeMessageViewContent</em> to
|
|
|
|
* <em>fontSizeMessageViewContentPercent</em>.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
public static class SettingsUpgraderV31 implements SettingsUpgrader {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<String> upgrade(Map<String, Object> settings) {
|
|
|
|
int oldSize = ((Integer) settings.get("fontSizeMessageViewContent")).intValue();
|
|
|
|
|
|
|
|
int newSize = convertFromOldSize(oldSize);
|
|
|
|
|
|
|
|
settings.put("fontSizeMessageViewContentPercent", newSize);
|
|
|
|
|
|
|
|
return new HashSet<String>(Arrays.asList("fontSizeMessageViewContent"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int convertFromOldSize(int oldSize) {
|
|
|
|
switch (oldSize) {
|
|
|
|
case 1: {
|
|
|
|
return 40;
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
return 75;
|
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
return 175;
|
|
|
|
}
|
|
|
|
case 5: {
|
|
|
|
return 250;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
default: {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:29:03 -04:00
|
|
|
/**
|
|
|
|
* The language setting.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Valid values are read from {@code settings_language_values} in
|
|
|
|
* {@code res/values/arrays.xml}.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
public static class LanguageSetting extends PseudoEnumSetting<String> {
|
|
|
|
private final Map<String, String> mMapping;
|
|
|
|
|
|
|
|
public LanguageSetting() {
|
|
|
|
super("");
|
|
|
|
|
|
|
|
Map<String, String> mapping = new HashMap<String, String>();
|
|
|
|
String[] values = K9.app.getResources().getStringArray(R.array.settings_language_values);
|
|
|
|
for (String value : values) {
|
|
|
|
if (value.length() == 0) {
|
|
|
|
mapping.put("", "default");
|
|
|
|
} else {
|
|
|
|
mapping.put(value, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mMapping = Collections.unmodifiableMap(mapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Map<String, String> getMapping() {
|
|
|
|
return mMapping;
|
|
|
|
}
|
|
|
|
|
2011-04-20 15:37:48 -04:00
|
|
|
@Override
|
2011-10-07 14:29:03 -04:00
|
|
|
public Object fromString(String value) throws InvalidSettingValueException {
|
|
|
|
if (mMapping.containsKey(value)) {
|
|
|
|
return value;
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
2011-10-07 14:29:03 -04:00
|
|
|
|
|
|
|
throw new InvalidSettingValueException();
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:29:03 -04:00
|
|
|
/**
|
|
|
|
* The theme setting.
|
|
|
|
*/
|
2012-03-29 00:33:01 -04:00
|
|
|
public static class ThemeSetting extends SettingsDescription {
|
|
|
|
private static final String THEME_LIGHT = "light";
|
|
|
|
private static final String THEME_DARK = "dark";
|
2011-10-07 14:29:03 -04:00
|
|
|
|
2013-02-07 10:55:42 -05:00
|
|
|
public ThemeSetting(K9.Theme defaultValue) {
|
2011-10-07 14:29:03 -04:00
|
|
|
super(defaultValue);
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-10-07 14:29:03 -04:00
|
|
|
public Object fromString(String value) throws InvalidSettingValueException {
|
|
|
|
try {
|
|
|
|
Integer theme = Integer.parseInt(value);
|
2013-02-06 14:08:57 -05:00
|
|
|
if (theme == K9.Theme.LIGHT.ordinal() ||
|
2012-03-29 00:33:01 -04:00
|
|
|
// We used to store the resource ID of the theme in the preference storage,
|
|
|
|
// but don't use the database upgrade mechanism to update the values. So
|
|
|
|
// we have to deal with the old format here.
|
|
|
|
theme == android.R.style.Theme_Light) {
|
2013-02-06 14:08:57 -05:00
|
|
|
return K9.Theme.LIGHT;
|
|
|
|
} else if (theme == K9.Theme.DARK.ordinal() || theme == android.R.style.Theme) {
|
|
|
|
return K9.Theme.DARK;
|
2011-10-07 14:29:03 -04:00
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) { /* do nothing */ }
|
|
|
|
|
|
|
|
throw new InvalidSettingValueException();
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
2012-03-29 00:33:01 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object fromPrettyString(String value) throws InvalidSettingValueException {
|
|
|
|
if (THEME_LIGHT.equals(value)) {
|
2013-02-06 14:08:57 -05:00
|
|
|
return K9.Theme.LIGHT;
|
2012-03-29 00:33:01 -04:00
|
|
|
} else if (THEME_DARK.equals(value)) {
|
2013-02-06 14:08:57 -05:00
|
|
|
return K9.Theme.DARK;
|
2012-03-29 00:33:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidSettingValueException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toPrettyString(Object value) {
|
2013-02-07 10:55:42 -05:00
|
|
|
switch ((K9.Theme) value) {
|
|
|
|
case DARK: {
|
|
|
|
return THEME_DARK;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return THEME_LIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString(Object value) {
|
|
|
|
return Integer.toString(((K9.Theme) value).ordinal());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The message view theme setting.
|
|
|
|
*/
|
|
|
|
public static class SubThemeSetting extends ThemeSetting {
|
|
|
|
private static final String THEME_USE_GLOBAL = "use_global";
|
|
|
|
|
|
|
|
public SubThemeSetting(Theme defaultValue) {
|
|
|
|
super(defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object fromString(String value) throws InvalidSettingValueException {
|
|
|
|
try {
|
|
|
|
Integer theme = Integer.parseInt(value);
|
|
|
|
if (theme == K9.Theme.USE_GLOBAL.ordinal()) {
|
|
|
|
return K9.Theme.USE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.fromString(value);
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
throw new InvalidSettingValueException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object fromPrettyString(String value) throws InvalidSettingValueException {
|
|
|
|
if (THEME_USE_GLOBAL.equals(value)) {
|
|
|
|
return K9.Theme.USE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.fromPrettyString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toPrettyString(Object value) {
|
|
|
|
if (((K9.Theme) value) == K9.Theme.USE_GLOBAL) {
|
|
|
|
return THEME_USE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.toPrettyString(value);
|
2012-03-29 00:33:01 -04:00
|
|
|
}
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
|
2011-10-07 14:29:03 -04:00
|
|
|
/**
|
|
|
|
* A time setting.
|
|
|
|
*/
|
|
|
|
public static class TimeSetting extends SettingsDescription {
|
|
|
|
public TimeSetting(String defaultValue) {
|
|
|
|
super(defaultValue);
|
|
|
|
}
|
|
|
|
|
2011-04-20 15:37:48 -04:00
|
|
|
@Override
|
2011-10-07 14:29:03 -04:00
|
|
|
public Object fromString(String value) throws InvalidSettingValueException {
|
|
|
|
if (!value.matches(TimePickerPreference.VALIDATION_EXPRESSION)) {
|
|
|
|
throw new InvalidSettingValueException();
|
|
|
|
}
|
|
|
|
return value;
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|
|
|
|
}
|
2011-10-16 22:52:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A directory on the file system.
|
|
|
|
*/
|
|
|
|
public static class DirectorySetting extends SettingsDescription {
|
|
|
|
public DirectorySetting(String defaultValue) {
|
|
|
|
super(defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object fromString(String value) throws InvalidSettingValueException {
|
|
|
|
try {
|
|
|
|
if (new File(value).isDirectory()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
} catch (Exception e) { /* do nothing */ }
|
|
|
|
|
|
|
|
throw new InvalidSettingValueException();
|
|
|
|
}
|
|
|
|
}
|
2011-04-20 15:37:48 -04:00
|
|
|
}
|