From 833290799ec029f75379ab6d29c090c16a9bc2e4 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Thu, 23 May 2019 15:10:35 -0700 Subject: [PATCH] For #1286 - Add Automatic Font Sizing Preference --- .../java/org/mozilla/fenix/components/Core.kt | 7 ++++--- .../fenix/settings/AccessibilityFragment.kt | 18 +++++++++++++++++- .../java/org/mozilla/fenix/utils/Settings.kt | 11 +++++++++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 7 +++++++ .../main/res/xml/accessibility_preferences.xml | 8 +++++++- 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 23de00dc49..3edb171113 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -52,9 +52,10 @@ class Core(private val context: Context) { .crashHandler(CrashHandlerService::class.java) .build() - val fontSize = Settings.getInstance(context).fontSizeFactor - if (fontSize != 1f) { + if (!Settings.getInstance(context).shouldUseAutoSize) { runtimeSettings.automaticFontSizeAdjustment = false + runtimeSettings.fontInflationEnabled = true + val fontSize = Settings.getInstance(context).fontSizeFactor runtimeSettings.fontSizeFactor = fontSize } @@ -75,7 +76,7 @@ class Core(private val context: Context) { trackingProtectionPolicy = createTrackingProtectionPolicy(), historyTrackingDelegate = HistoryDelegate(historyStorage), preferredColorScheme = getPreferredColorScheme(), - automaticFontSizeAdjustment = false + automaticFontSizeAdjustment = Settings.getInstance(context).shouldUseAutoSize ) GeckoEngine(context, defaultSettings, runtime) diff --git a/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt index 7e51a74cf6..bd952389b6 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreference import org.mozilla.fenix.R import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.utils.Settings @@ -25,12 +26,27 @@ class AccessibilityFragment : PreferenceFragmentCompat() { // Value is mapped from 0->30 in steps of 1 so let's convert to float in range 0.5->2.0 val newTextScale = ((newValue as Int * STEP_SIZE) + MIN_SCALE_VALUE).toFloat() / PERCENT_TO_DECIMAL Settings.getInstance(context!!).setFontSizeFactor(newTextScale) - requireComponents.core.engine.settings.automaticFontSizeAdjustment = (newTextScale == 1f) requireComponents.core.engine.settings.fontSizeFactor = newTextScale requireComponents.useCases.sessionUseCases.reload.invoke() } true } + + textSizePreference?.isVisible = !Settings.getInstance(context!!).shouldUseAutoSize + + val useAutoSizePreference = + findPreference(getString(R.string.pref_key_accessibility_auto_size)) + useAutoSizePreference?.setOnPreferenceChangeListener { _, newValue -> + Settings.getInstance(context!!).setAutoSize(newValue as Boolean) + requireComponents.core.engine.settings.automaticFontSizeAdjustment = newValue + if (!newValue) { + requireComponents.core.engine.settings.fontInflationEnabled = true + requireComponents.core.engine.settings.fontSizeFactor = Settings.getInstance(context!!).fontSizeFactor + } + textSizePreference?.isVisible = !newValue + requireComponents.useCases.sessionUseCases.reload.invoke() + true + } } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 7c96d08b61..1d134e8211 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -77,6 +77,17 @@ class Settings private constructor(context: Context) { ).apply() } + fun setAutoSize(newValue: Boolean) { + preferences.edit().putBoolean(appContext.getPreferenceKey(R.string.pref_key_accessibility_auto_size), newValue) + .apply() + } + + val shouldUseAutoSize: Boolean + get() = preferences.getBoolean( + appContext.getPreferenceKey(R.string.pref_key_accessibility_auto_size), + true + ) + fun setFontSizeFactor(newValue: Float) { preferences.edit().putFloat(appContext.getPreferenceKey(R.string.pref_key_accessibility_font_scale), newValue) .apply() diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index f22615a498..684412c108 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -9,6 +9,7 @@ pref_key_credit_cards_addresses pref_key_site_permissions pref_key_accessibility + pref_key_accessibility_auto_size pref_key_accessibility_font_scale pref_key_language pref_key_data_choices diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14a7a91467..2d7ad3cea4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -541,7 +541,14 @@ Entering full screen mode URL copied + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + Make text on websites larger or smaller + Font Size + + Automatic Font Sizing + + Font size will automatically match your system settings. Disable for manual control. diff --git a/app/src/main/res/xml/accessibility_preferences.xml b/app/src/main/res/xml/accessibility_preferences.xml index 78f496549a..8ed45e20bd 100644 --- a/app/src/main/res/xml/accessibility_preferences.xml +++ b/app/src/main/res/xml/accessibility_preferences.xml @@ -2,9 +2,14 @@ - +