diff --git a/app/src/main/java/io/legado/app/base/AppContextWrapper.kt b/app/src/main/java/io/legado/app/base/AppContextWrapper.kt index ae1aed567..74a7fa253 100644 --- a/app/src/main/java/io/legado/app/base/AppContextWrapper.kt +++ b/app/src/main/java/io/legado/app/base/AppContextWrapper.kt @@ -6,6 +6,7 @@ import android.content.res.Resources import android.os.Build import android.os.LocaleList import io.legado.app.constant.PreferKey +import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefString import java.util.* @@ -13,13 +14,17 @@ import java.util.* object AppContextWrapper { fun wrap(context: Context): Context { + var fontScale = context.getPrefInt(PreferKey.fontScale) / 10f + if (fontScale !in 1f..2f) { + fontScale = Configuration().fontScale + } return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val resources: Resources = context.resources val configuration: Configuration = resources.configuration val targetLocale = getSetLocale(context) configuration.setLocale(targetLocale) configuration.setLocales(LocaleList(targetLocale)) - configuration.fontScale = 1f + configuration.fontScale = fontScale context.createConfigurationContext(configuration) } else { val resources: Resources = context.resources @@ -27,7 +32,7 @@ object AppContextWrapper { val configuration: Configuration = resources.configuration @Suppress("DEPRECATION") configuration.locale = targetLocale - configuration.fontScale = 1f + configuration.fontScale = fontScale @Suppress("DEPRECATION") resources.updateConfiguration(configuration, resources.displayMetrics) context diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 956634b09..ac38b1264 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -2,6 +2,7 @@ package io.legado.app.constant object PreferKey { const val language = "language" + const val fontScale = "fontScale" const val themeMode = "themeMode" const val userAgent = "userAgent" const val showUnread = "showUnread" diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 9c5bab4fe..79d3147bc 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -56,6 +56,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN)) upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString()) + upPreferenceSummary(PreferKey.fontScale) findPreference(PreferKey.cBackground)?.let { it.onSaveColor = { color -> if (!ColorUtils.isColorLight(color)) { @@ -152,6 +153,18 @@ class ThemeConfigFragment : BasePreferenceFragment(), AppConfig.elevation = it recreateActivities() } + PreferKey.fontScale -> NumberPickerDialog(requireContext()) + .setTitle(getString(R.string.font_scale)) + .setMaxValue(20) + .setMinValue(10) + .setCustomButton((R.string.btn_default_s)) { + putPrefInt(PreferKey.fontScale, 0) + recreateActivities() + } + .show { + putPrefInt(PreferKey.fontScale, it) + recreateActivities() + } PreferKey.bgImage -> selectBgAction(false) PreferKey.bgImageN -> selectBgAction(true) "themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") @@ -257,11 +270,18 @@ class ThemeConfigFragment : BasePreferenceFragment(), postEvent(EventBus.RECREATE, "") } - private fun upPreferenceSummary(preferenceKey: String, value: String?) { + private fun upPreferenceSummary(preferenceKey: String, value: String? = null) { val preference = findPreference(preferenceKey) ?: return when (preferenceKey) { PreferKey.barElevation -> preference.summary = getString(R.string.bar_elevation_s, value) + PreferKey.fontScale -> { + var fontScale = getPrefInt(PreferKey.fontScale) / 10f + if (fontScale !in 1f..2f) { + fontScale = resources.configuration.fontScale + } + preference.summary = getString(R.string.font_scale_summary, fontScale) + } PreferKey.bgImage, PreferKey.bgImageN -> preference.summary = if (value.isNullOrBlank()) { getString(R.string.select_image) diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index d9cbf2d91..2ef67ef1b 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -900,5 +900,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index e9ef29aad..3d274d698 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -904,5 +904,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 2f8f9bbe2..2953fc98e 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -904,5 +904,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 955a1a155..800c0f971 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -901,5 +901,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9fa8e6148..03efde1c7 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -903,5 +903,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 350903004..59f15564e 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -903,5 +903,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7469ff404..594a64f3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -904,5 +904,7 @@ 删除登录头 查看登录头 登录头 + 字体大小 + 当前字体大小:%.1f diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index f2e80790b..602235647 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -33,6 +33,13 @@ android:title="@string/bar_elevation" app:iconSpaceReserved="false" /> + +