diff --git a/app/build.gradle b/app/build.gradle index 58ce975d7..e49b041a2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -213,6 +213,9 @@ dependencies { implementation("io.noties.markwon:ext-tables:$markwonVersion") implementation("io.noties.markwon:html:$markwonVersion") + // 谷歌RenderScript库 + implementation('com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3') + //转换繁体 implementation('com.github.liuyueyi.quick-chinese-transfer:quick-transfer-core:0.2.1') diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 6406c18bf..306e61943 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -2,6 +2,8 @@ package io.legado.app.base import android.content.Context import android.content.res.Configuration +import android.graphics.Bitmap +import android.graphics.drawable.BitmapDrawable import android.os.Build import android.os.Bundle import android.util.AttributeSet @@ -10,11 +12,15 @@ import android.view.MenuItem import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity +import androidx.preference.PreferenceManager import androidx.viewbinding.ViewBinding +import com.google.android.renderscript.Toolkit import io.legado.app.App import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey +import io.legado.app.constant.PreferKey.bgImageBlurring +import io.legado.app.constant.PreferKey.bgImageNBlurring import io.legado.app.constant.Theme import io.legado.app.help.AppConfig import io.legado.app.help.ThemeConfig @@ -174,9 +180,7 @@ abstract class BaseActivity( } if (imageBg) { try { - ThemeConfig.getBgImage(this)?.let { - window.decorView.background = it - } + window.decorView.background = BitmapDrawable(resources, getBackgroundImage(ThemeConfig.getBgImage(this) ?: return)) } catch (e: OutOfMemoryError) { toastOnUi(e.localizedMessage) } catch (e: Exception) { @@ -185,6 +189,22 @@ abstract class BaseActivity( } } + private fun getBackgroundImage(bitmap: Bitmap): Bitmap { + when (Theme.getTheme()) { + Theme.Light -> PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageBlurring, 0).apply { + if (this != 0) { + return Toolkit.blur(bitmap, this) + } + } + Theme.Dark -> PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageNBlurring, 0).apply { + if (this != 0) { + return Toolkit.blur(bitmap, this) + } + } + } + return bitmap + } + private fun setupSystemBar() { if (fullScreen && !isInMultiWindow) { ATH.fullScreen(this) 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 b92ad091c..d2224a584 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -91,11 +91,13 @@ object PreferKey { const val cBackground = "colorBackground" const val cBBackground = "colorBottomBackground" const val bgImage = "backgroundImage" + const val bgImageBlurring = "backgroundImageBlurring" const val cNPrimary = "colorPrimaryNight" const val cNAccent = "colorAccentNight" const val cNBackground = "colorBackgroundNight" const val cNBBackground = "colorBottomBackgroundNight" const val bgImageN = "backgroundImageNight" + const val bgImageNBlurring = "backgroundImageNightBlurring" } diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index bdbe9eb8d..39d33e02b 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -1,9 +1,9 @@ package io.legado.app.help import android.content.Context +import android.graphics.Bitmap +import android.graphics.BitmapFactory import android.graphics.Color -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.Drawable import androidx.annotation.Keep import androidx.appcompat.app.AppCompatDelegate import io.legado.app.R @@ -43,14 +43,14 @@ object ThemeConfig { AppCompatDelegate.setDefaultNightMode(targetMode) } - fun getBgImage(context: Context): Drawable? { + fun getBgImage(context: Context): Bitmap? { val bgPath = when (Theme.getTheme()) { Theme.Light -> context.getPrefString(PreferKey.bgImage) Theme.Dark -> context.getPrefString(PreferKey.bgImageN) else -> null } if (bgPath.isNullOrBlank()) return null - return BitmapDrawable.createFromPath(bgPath) + return BitmapFactory.decodeFile(bgPath) } fun upConfig() { diff --git a/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt b/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt new file mode 100644 index 000000000..06065dd69 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt @@ -0,0 +1,53 @@ +package io.legado.app.ui.config + +import android.app.Dialog +import android.content.SharedPreferences +import android.os.Bundle +import android.widget.SeekBar +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import androidx.preference.PreferenceManager +import io.legado.app.R +import io.legado.app.databinding.FragmentImageBlurringDialogBinding + +class ImageBlurringDialogFragment(private val prefName: String, private val block: () -> Unit): DialogFragment() { + + companion object { + private const val DEFAULT_VALUE = 0 + private const val TAG = "ImageBlurringDialogFragment" + } + + private val requireContext get() = requireContext() + private var _fragmentImageBlurringDialogBinding: FragmentImageBlurringDialogBinding? = null + private val fragmentImageBlurringDialog get() = _fragmentImageBlurringDialogBinding!! + private lateinit var sharedPreference: SharedPreferences + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + _fragmentImageBlurringDialogBinding = FragmentImageBlurringDialogBinding.inflate(layoutInflater) + sharedPreference = PreferenceManager.getDefaultSharedPreferences(requireContext) + sharedPreference.getInt(prefName, DEFAULT_VALUE).apply { + fragmentImageBlurringDialog.seekBar.progress = this + fragmentImageBlurringDialog.textViewValue.text = this.toString() + } + fragmentImageBlurringDialog.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + fragmentImageBlurringDialog.textViewValue.text = progress.toString() + } + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit + override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit + }) + return AlertDialog.Builder(requireContext) + .setTitle(R.string.background_image_blurring_radius) + .setView(fragmentImageBlurringDialog.root) + .setPositiveButton(R.string.dialog_confirm) { _, _ -> + sharedPreference.edit().putInt(prefName, fragmentImageBlurringDialog.seekBar.progress).commit() + block() + } + .setNegativeButton(R.string.dialog_cancel) { _, _ -> } + .create() + } + + fun show(fragmentManager: FragmentManager) = show(fragmentManager, TAG) + +} \ No newline at end of file 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 7571d8acf..44c7f0b28 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 @@ -183,6 +183,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), } } } + PreferKey.bgImageBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager) + PreferKey.bgImageNBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageNBlurring) { upTheme(true) }.show(parentFragmentManager) PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { selectImage.launch(requestCodeCover) } else { diff --git a/app/src/main/res/layout/fragment_image_blurring_dialog.xml b/app/src/main/res/layout/fragment_image_blurring_dialog.xml new file mode 100644 index 000000000..907aff57c --- /dev/null +++ b/app/src/main/res/layout/fragment_image_blurring_dialog.xml @@ -0,0 +1,28 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 491800154..2146ac4a7 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -804,6 +804,9 @@ 預先下載%s章正文 係咪啟用 背景圖片 + 背景圖片虛化 + 虛化半徑 + 0為停用,啓用範圍1~25\n半徑數值越大,虛化效果越高 導出資料夾 導出編碼 導出到WebDav diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e2e486326..4af6a2440 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -807,6 +807,9 @@ 預先下載%s章正文 是否啟用 背景圖片 + 背景圖片虛化 + 虛化半徑 + 0為停用,啓用範圍1~25\n半徑數值越大,虛化效果越高 匯出資料夾 匯出編碼 匯出到WebDav diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a6fc6c733..fd844c95e 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -807,6 +807,9 @@ 预先下载%s章正文 是否启用 背景图片 + 背景图片虚化 + 虚化半径 + 0为停用,启用范围1~25\n半径数值越大,虚化效果越高 导出文件夹 导出编码 导出到WebDav diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5cb9d844d..a61943742 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -807,6 +807,9 @@ Download %s chapters in advance Is enabled Background image + Background image blurring + Blurring radius + Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring Copy book URL Copy chapters URL Export folder diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 8fb8143be..564cb9811 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -86,6 +86,10 @@ android:key="backgroundImage" android:title="@string/background_image" /> + + + +