From 90f63ba057cd7b73ef2514a9f6f108cc610feac1 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 13 Feb 2014 04:22:45 +0100 Subject: [PATCH] Remove old setting for message content font size - export new setting - add upgrade code to convert old setting to new format --- res/xml/font_preferences.xml | 10 +-- src/com/fsck/k9/FontSizes.java | 70 ++++--------------- .../k9/activity/setup/FontSizeSettings.java | 15 ---- .../fsck/k9/preferences/GlobalSettings.java | 50 ++++++++++++- src/com/fsck/k9/preferences/Settings.java | 2 +- src/com/fsck/k9/view/MessageWebView.java | 7 +- 6 files changed, 67 insertions(+), 87 deletions(-) diff --git a/res/xml/font_preferences.xml b/res/xml/font_preferences.xml index cce4a7007..fd2c340b4 100644 --- a/res/xml/font_preferences.xml +++ b/res/xml/font_preferences.xml @@ -137,7 +137,7 @@ android:entryValues="@array/font_values" android:dialogTitle="@string/font_size_message_view_date" /> - - - = android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - ((PreferenceGroup) findPreference(PREFERENCE_SCREEN_MESSAGE_VIEW_FONTS)). - removePreference(mMessageViewContent); - } else { - ((PreferenceGroup) findPreference(PREFERENCE_SCREEN_MESSAGE_VIEW_FONTS)). - removePreference(mMessageViewContentSlider); - } - mMessageComposeInput = setupListPreference( PREFERENCE_MESSAGE_COMPOSE_INPUT_FONT, Integer.toString(fontSizes.getMessageComposeInput())); @@ -189,7 +175,6 @@ public class FontSizeSettings extends K9PreferenceActivity { fontSizes.setMessageViewAdditionalHeaders(Integer.parseInt(mMessageViewAdditionalHeaders.getValue())); fontSizes.setMessageViewSubject(Integer.parseInt(mMessageViewSubject.getValue())); fontSizes.setMessageViewDate(Integer.parseInt(mMessageViewDate.getValue())); - fontSizes.setMessageViewContent(Integer.parseInt(mMessageViewContent.getValue())); // Scale from [0, 1] fontSizes.setMessageViewContentAsPercent((int)(FONT_PERCENT_MIN + mMessageViewContentSlider.getValue() * diff --git a/src/com/fsck/k9/preferences/GlobalSettings.java b/src/com/fsck/k9/preferences/GlobalSettings.java index 79066d7d6..a55da2662 100644 --- a/src/com/fsck/k9/preferences/GlobalSettings.java +++ b/src/com/fsck/k9/preferences/GlobalSettings.java @@ -101,7 +101,8 @@ public class GlobalSettings { new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT)) )); s.put("fontSizeMessageViewContent", Settings.versions( - new V(1, new WebFontSizeSetting(3)) + new V(1, new WebFontSizeSetting(3)), + new V(31, null) )); s.put("fontSizeMessageViewDate", Settings.versions( new V(1, new FontSizeSetting(FontSizes.FONT_DEFAULT)) @@ -245,12 +246,16 @@ public class GlobalSettings { s.put("messageViewSpamActionVisible", Settings.versions( new V(30, new BooleanSetting(false)) )); + s.put("fontSizeMessageViewContentPercent", Settings.versions( + new V(31, new IntegerRangeSetting(40, 250, 100)) + )); SETTINGS = Collections.unmodifiableMap(s); Map u = new HashMap(); u.put(12, new SettingsUpgraderV12()); u.put(24, new SettingsUpgraderV24()); + u.put(31, new SettingsUpgraderV31()); UPGRADERS = Collections.unmodifiableMap(u); } @@ -321,6 +326,49 @@ public class GlobalSettings { } } + /** + * Upgrades the settings from version 30 to 31. + * + *

+ * Convert value from fontSizeMessageViewContent to + * fontSizeMessageViewContentPercent. + *

+ */ + public static class SettingsUpgraderV31 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + int oldSize = ((Integer) settings.get("fontSizeMessageViewContent")).intValue(); + + int newSize = convertFromOldSize(oldSize); + + settings.put("fontSizeMessageViewContentPercent", newSize); + + return new HashSet(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; + } + } + } + } + /** * The gallery bug work-around setting. * diff --git a/src/com/fsck/k9/preferences/Settings.java b/src/com/fsck/k9/preferences/Settings.java index 127865ee8..11ecc921a 100644 --- a/src/com/fsck/k9/preferences/Settings.java +++ b/src/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 30; + public static final int VERSION = 31; public static Map validate(int version, Map> settings, diff --git a/src/com/fsck/k9/view/MessageWebView.java b/src/com/fsck/k9/view/MessageWebView.java index 192165dcd..0e37c069c 100644 --- a/src/com/fsck/k9/view/MessageWebView.java +++ b/src/com/fsck/k9/view/MessageWebView.java @@ -109,15 +109,10 @@ public class MessageWebView extends RigidWebView { disableOverscrolling(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - webSettings.setTextZoom(K9.getFontSizes().getMessageViewContentAsPercent()); - } else { - webSettings.setTextSize(K9.getFontSizes().getMessageViewContent()); - } + webSettings.setTextZoom(K9.getFontSizes().getMessageViewContentAsPercent()); // Disable network images by default. This is overridden by preferences. blockNetworkData(true); - } /**