Bug 1328868 - Part 7 - Detect the previous font size setting and migrate it to the new shared preference. r?sebastian
If the shared preference doesn't exist on startup, we check the value of font.size.inflation.minTwips and then turn the new setting on if minTwips was > 60, which is the case if the previous font size setting was set to at least "Small" or larger.
If the old setting was "Tiny" or else for new installations, we default the new setting to "off".
MozReview-Commit-ID: B9yB9JwRcqj
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoFontScaleListener.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoFontScaleListener.java
@@ -103,25 +103,41 @@ class GeckoFontScaleListener
fontInflation = FONT_INFLATION_OFF;
}
PrefsHelper.setPref(PREF_FONT_INFLATION, fontInflation);
PrefsHelper.setPref(PREF_SYSTEM_FONT_SCALE, Math.round(fontScale * 100));
}
private void onPrefChange(final SharedPreferences prefs) {
- boolean useSystemFontScale = prefs.getBoolean(GeckoPreferences.PREFS_SYSTEM_FONT_SIZE, false);
+ boolean useSystemFontScale;
+ if (prefs.contains(GeckoPreferences.PREFS_SYSTEM_FONT_SIZE)) {
+ useSystemFontScale = prefs.getBoolean(GeckoPreferences.PREFS_SYSTEM_FONT_SIZE, false);
+ } else {
+ migrateOldSetting(prefs);
+ return;
+ }
if (useSystemFontScale) {
start();
} else {
stop();
}
}
+ private void migrateOldSetting(final SharedPreferences prefs) {
+ PrefsHelper.getPref(PREF_FONT_INFLATION, new PrefsHelper.PrefHandlerBase() {
+ @Override
+ public void prefValue(String pref, int value) {
+ // The first setting step above "Tiny" used to correspond to a value of 80.
+ prefs.edit().putBoolean(GeckoPreferences.PREFS_SYSTEM_FONT_SIZE, (value > 60)).apply();
+ }
+ });
+ }
+
@Override
public void onChange(boolean selfChange) {
onSystemFontScaleChange(mApplicationContext.getContentResolver(), false);
}
@UiThread // According to the docs.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {