mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-05 21:20:45 +00:00
For #1286 - Add Automatic Font Sizing Preference
This commit is contained in:
parent
074eec7006
commit
833290799e
@ -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)
|
||||
|
@ -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<SwitchPreference>(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?) {
|
||||
|
@ -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()
|
||||
|
@ -9,6 +9,7 @@
|
||||
<string name="pref_key_credit_cards_addresses" translatable="false">pref_key_credit_cards_addresses</string>
|
||||
<string name="pref_key_site_permissions" translatable="false">pref_key_site_permissions</string>
|
||||
<string name="pref_key_accessibility" translatable="false">pref_key_accessibility</string>
|
||||
<string name="pref_key_accessibility_auto_size" translatable="false">pref_key_accessibility_auto_size</string>
|
||||
<string name="pref_key_accessibility_font_scale" translatable="false">pref_key_accessibility_font_scale</string>
|
||||
<string name="pref_key_language" translatable="false">pref_key_language</string>
|
||||
<string name="pref_key_data_choices" translatable="false">pref_key_data_choices</string>
|
||||
|
@ -541,7 +541,14 @@
|
||||
<string name="full_screen_notification">Entering full screen mode</string>
|
||||
<!-- Message for copying the URL via long press on the toolbar -->
|
||||
<string name="url_copied">URL copied</string>
|
||||
<!-- Sample text for accessiblity font size -->
|
||||
<string name="accessibility_text_size_sample_text">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.</string>
|
||||
<!-- Summary for Accessiblity Text Size Scaling Preference -->
|
||||
<string name="preference_accessibility_text_size_summary">Make text on websites larger or smaller</string>
|
||||
<!-- Title for Accessiblity Text Size Scaling Preference -->
|
||||
<string name="preference_accessibility_font_size_title">Font Size</string>
|
||||
<!-- Title for Accessiblity Text Automatic Size Scaling Preference -->
|
||||
<string name="preference_accessibility_auto_size">Automatic Font Sizing</string>
|
||||
<!-- Summary for Accessiblity Text Automatic Size Scaling Preference -->
|
||||
<string name="preference_accessibility_auto_size_summary">Font size will automatically match your system settings. Disable for manual control.</string>
|
||||
</resources>
|
||||
|
@ -2,9 +2,14 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/pref_key_accessibility_auto_size"
|
||||
android:summary="@string/preference_accessibility_auto_size_summary"
|
||||
android:title="@string/preference_accessibility_auto_size"
|
||||
app:iconSpaceReserved="false" />
|
||||
<!-- Custom Preference that scales from 50-200% by steps of 5 represented by 0-30 in steps of 1-->
|
||||
<org.mozilla.fenix.settings.TextPercentageSeekBarPreference
|
||||
android:defaultValue="10"
|
||||
@ -15,6 +20,7 @@
|
||||
android:title="@string/preference_accessibility_font_size_title"
|
||||
app:adjustable="true"
|
||||
app:iconSpaceReserved="false"
|
||||
app:isPreferenceVisible="false"
|
||||
app:min="0"
|
||||
app:seekBarIncrement="1"
|
||||
app:showSeekBarValue="true" />
|
||||
|
Loading…
Reference in New Issue
Block a user