mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Remove old setting for message content font size
- export new setting - add upgrade code to convert old setting to new format
This commit is contained in:
parent
3527930f89
commit
90f63ba057
@ -137,7 +137,7 @@
|
||||
android:entryValues="@array/font_values"
|
||||
android:dialogTitle="@string/font_size_message_view_date" />
|
||||
|
||||
<ListPreference
|
||||
<ListPreference
|
||||
android:persistent="false"
|
||||
android:key="message_view_additional_headers_font"
|
||||
android:title="@string/font_size_message_view_additional_headers"
|
||||
@ -145,14 +145,6 @@
|
||||
android:entryValues="@array/font_values"
|
||||
android:dialogTitle="@string/font_size_message_view_additional_headers" />
|
||||
|
||||
<ListPreference
|
||||
android:persistent="false"
|
||||
android:key="message_view_content_font"
|
||||
android:title="@string/font_size_message_view_content"
|
||||
android:entries="@array/font_entries_webview"
|
||||
android:entryValues="@array/font_values_webview"
|
||||
android:dialogTitle="@string/font_size_message_view_content" />
|
||||
|
||||
<com.fsck.k9.activity.setup.SliderPreference
|
||||
android:persistent="false"
|
||||
android:key="message_view_content_font_slider"
|
||||
|
@ -2,9 +2,10 @@ package com.fsck.k9;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.TypedValue;
|
||||
import android.webkit.WebSettings.TextSize;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fsck.k9.preferences.GlobalSettings;
|
||||
|
||||
/**
|
||||
* Manage font size of the information displayed in the account list, folder
|
||||
* list, message list and in the message view.
|
||||
@ -114,18 +115,8 @@ public class FontSizes {
|
||||
*/
|
||||
private int messageViewDate;
|
||||
|
||||
/**
|
||||
* Font size of the message content in the message view activity.
|
||||
*
|
||||
* Note: The unit is WebSettings.TextSize, this option is used only on Android 3.2 (API level 13) and below.
|
||||
*/
|
||||
private TextSize messageViewContent = TextSize.NORMAL;
|
||||
|
||||
|
||||
/**
|
||||
* Font size of the message content in the message view activity, as percent from default size.
|
||||
*
|
||||
* Note: This option is used only on Android 4.0 (API level 14) and above.
|
||||
*/
|
||||
private int messageViewContentPercent;
|
||||
|
||||
@ -184,7 +175,6 @@ public class FontSizes {
|
||||
editor.putInt(MESSAGE_VIEW_ADDITIONAL_HEADERS, messageViewAdditionalHeaders);
|
||||
editor.putInt(MESSAGE_VIEW_SUBJECT, messageViewSubject);
|
||||
editor.putInt(MESSAGE_VIEW_DATE, messageViewDate);
|
||||
editor.putInt(MESSAGE_VIEW_CONTENT, getMessageViewContentAsInt());
|
||||
editor.putInt(MESSAGE_VIEW_CONTENT_PERCENT, getMessageViewContentAsPercent());
|
||||
|
||||
editor.putInt(MESSAGE_COMPOSE_INPUT, messageComposeInput);
|
||||
@ -213,12 +203,22 @@ public class FontSizes {
|
||||
messageViewAdditionalHeaders = prefs.getInt(MESSAGE_VIEW_ADDITIONAL_HEADERS, messageViewAdditionalHeaders);
|
||||
messageViewSubject = prefs.getInt(MESSAGE_VIEW_SUBJECT, messageViewSubject);
|
||||
messageViewDate = prefs.getInt(MESSAGE_VIEW_DATE, messageViewDate);
|
||||
setMessageViewContent(prefs.getInt(MESSAGE_VIEW_CONTENT, 3));
|
||||
setMessageViewContentAsPercent(prefs.getInt(MESSAGE_VIEW_CONTENT_PERCENT, 100));
|
||||
|
||||
loadMessageViewContentPercent(prefs);
|
||||
|
||||
messageComposeInput = prefs.getInt(MESSAGE_COMPOSE_INPUT, messageComposeInput);
|
||||
}
|
||||
|
||||
private void loadMessageViewContentPercent(SharedPreferences prefs) {
|
||||
int fallbackValue = 100;
|
||||
if (!prefs.contains(MESSAGE_VIEW_CONTENT_PERCENT)) {
|
||||
int oldValue = prefs.getInt(MESSAGE_VIEW_CONTENT, 3);
|
||||
fallbackValue = GlobalSettings.SettingsUpgraderV31.convertFromOldSize(oldValue);
|
||||
}
|
||||
|
||||
setMessageViewContentAsPercent(prefs.getInt(MESSAGE_VIEW_CONTENT_PERCENT, fallbackValue));
|
||||
}
|
||||
|
||||
public int getAccountName() {
|
||||
return accountName;
|
||||
}
|
||||
@ -331,46 +331,6 @@ public class FontSizes {
|
||||
this.messageViewDate = messageViewDate;
|
||||
}
|
||||
|
||||
public TextSize getMessageViewContent() {
|
||||
return messageViewContent;
|
||||
}
|
||||
|
||||
public int getMessageViewContentAsInt() {
|
||||
switch (messageViewContent) {
|
||||
case SMALLEST:
|
||||
return 1;
|
||||
case SMALLER:
|
||||
return 2;
|
||||
default:
|
||||
case NORMAL:
|
||||
return 3;
|
||||
case LARGER:
|
||||
return 4;
|
||||
case LARGEST:
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageViewContent(int size) {
|
||||
switch (size) {
|
||||
case 1:
|
||||
messageViewContent = TextSize.SMALLEST;
|
||||
break;
|
||||
case 2:
|
||||
messageViewContent = TextSize.SMALLER;
|
||||
break;
|
||||
case 3:
|
||||
messageViewContent = TextSize.NORMAL;
|
||||
break;
|
||||
case 4:
|
||||
messageViewContent = TextSize.LARGER;
|
||||
break;
|
||||
case 5:
|
||||
messageViewContent = TextSize.LARGEST;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMessageViewContentAsPercent() {
|
||||
return messageViewContentPercent;
|
||||
}
|
||||
@ -394,4 +354,4 @@ public class FontSizes {
|
||||
v.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
||||
/*
|
||||
* Keys of the preferences defined in res/xml/font_preferences.xml
|
||||
*/
|
||||
private static final String PREFERENCE_SCREEN_MESSAGE_VIEW_FONTS = "message_view_fonts";
|
||||
private static final String PREFERENCE_ACCOUNT_NAME_FONT = "account_name_font";
|
||||
private static final String PREFERENCE_ACCOUNT_DESCRIPTION_FONT = "account_description_font";
|
||||
private static final String PREFERENCE_FOLDER_NAME_FONT = "folder_name_font";
|
||||
@ -34,7 +33,6 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
||||
private static final String PREFERENCE_MESSAGE_VIEW_ADDITIONAL_HEADERS_FONT = "message_view_additional_headers_font";
|
||||
private static final String PREFERENCE_MESSAGE_VIEW_SUBJECT_FONT = "message_view_subject_font";
|
||||
private static final String PREFERENCE_MESSAGE_VIEW_DATE_FONT = "message_view_date_font";
|
||||
private static final String PREFERENCE_MESSAGE_VIEW_CONTENT_FONT = "message_view_content_font";
|
||||
private static final String PREFERENCE_MESSAGE_VIEW_CONTENT_FONT_SLIDER = "message_view_content_font_slider";
|
||||
private static final String PREFERENCE_MESSAGE_COMPOSE_INPUT_FONT = "message_compose_input_font";
|
||||
|
||||
@ -52,7 +50,6 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
||||
private ListPreference mMessageViewAdditionalHeaders;
|
||||
private ListPreference mMessageViewSubject;
|
||||
private ListPreference mMessageViewDate;
|
||||
private ListPreference mMessageViewContent;
|
||||
private SliderPreference mMessageViewContentSlider;
|
||||
private ListPreference mMessageComposeInput;
|
||||
|
||||
@ -121,9 +118,6 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
||||
mMessageViewDate = setupListPreference(
|
||||
PREFERENCE_MESSAGE_VIEW_DATE_FONT,
|
||||
Integer.toString(fontSizes.getMessageViewDate()));
|
||||
mMessageViewContent = setupListPreference(
|
||||
PREFERENCE_MESSAGE_VIEW_CONTENT_FONT,
|
||||
Integer.toString(fontSizes.getMessageViewContentAsInt()));
|
||||
|
||||
mMessageViewContentSlider = (SliderPreference) findPreference(
|
||||
PREFERENCE_MESSAGE_VIEW_CONTENT_FONT_SLIDER);
|
||||
@ -152,14 +146,6 @@ public class FontSizeSettings extends K9PreferenceActivity {
|
||||
mMessageViewContentSlider.getOnPreferenceChangeListener().onPreferenceChange(
|
||||
mMessageViewContentSlider, new Float(mMessageViewContentSlider.getValue()));
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 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() *
|
||||
|
@ -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<Integer, SettingsUpgrader> u = new HashMap<Integer, SettingsUpgrader>();
|
||||
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.
|
||||
*
|
||||
* <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The gallery bug work-around setting.
|
||||
*
|
||||
|
@ -35,7 +35,7 @@ public class Settings {
|
||||
*
|
||||
* @see SettingsExporter
|
||||
*/
|
||||
public static final int VERSION = 30;
|
||||
public static final int VERSION = 31;
|
||||
|
||||
public static Map<String, Object> validate(int version, Map<String,
|
||||
TreeMap<Integer, SettingsDescription>> settings,
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user