Bug 1328868 - Part 8 - 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 485522 dbb80e45d07fb0b947ec77cbb8560bd1f6acdb6b
parent 485521 d503b25d2f3f892d934f3d662991747e2a52c3d0
child 485523 0251a21d8078f5b486333fcf9fe8f06f60e00647
push id45754
push usermozilla@buttercookie.de
push dateThu, 16 Feb 2017 20:38:49 +0000
reviewerssebastian
bugs1328868
milestone54.0a1
Bug 1328868 - Part 8 - 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) {