Bug 1328868 - Part 7 - Detect the previous font size setting and migrate it to the new shared preference. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 05 Feb 2017 14:22:28 +0100
changeset 501265 b97d82ebf5c783de8787c33cb45dfb2d7a56c4bd
parent 501264 8662381b78913f2b881633cead6dfe6dce356bef
child 501266 7fa4fe64d8aa91f0c4110a21638d0cac66ebf154
push id49917
push usermozilla@buttercookie.de
push dateSun, 19 Mar 2017 12:39:17 +0000
reviewerssebastian
bugs1328868
milestone55.0a1
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
mobile/android/base/java/org/mozilla/gecko/GeckoFontScaleListener.java
--- 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) {