From 8907cec1d353761503e1f9e50149f105a35d5e28 Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:07:01 +0800
Subject: [PATCH 1/8] build.gradle: Add dependency
renderscript-intrinsics-replacement-toolkit
Signed-off-by: 1552980358 <1552980358@qq.com>
---
app/build.gradle | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 902af3cd7..76266295b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -98,8 +98,8 @@ android {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 11
- sourceCompatibility JavaVersion.VERSION_11
- targetCompatibility JavaVersion.VERSION_11
+ sourceCompatibility "1.8"
+ targetCompatibility "1.8"
}
kotlinOptions {
@@ -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')
From ccb31350559de1e4b1c45ec4556a054881e80bb9 Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:07:44 +0800
Subject: [PATCH 2/8] ThemeConfig.kt: Set getBgImage return type as Bitmap?
Signed-off-by: 1552980358 <1552980358@qq.com>
---
app/src/main/java/io/legado/app/help/ThemeConfig.kt | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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() {
From bf1b5bb813de17fb98f9a96c626efe9165fda63c Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:08:02 +0800
Subject: [PATCH 3/8] PreferKey.kt: Update key bgImageBlurring
Signed-off-by: 1552980358 <1552980358@qq.com>
---
app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 +
1 file changed, 1 insertion(+)
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..59c10f8e8 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -91,6 +91,7 @@ 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"
From c02331e9be37b72d6045ed16530cd57cf155ddb5 Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:08:28 +0800
Subject: [PATCH 4/8] Update ImageBlurringDialogFragment
Signed-off-by: 1552980358 <1552980358@qq.com>
---
.../ui/config/ImageBlurringDialogFragment.kt | 53 +++++++++++++++++++
.../layout/fragment_image_blurring_dialog.xml | 28 ++++++++++
2 files changed, 81 insertions(+)
create mode 100644 app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt
create mode 100644 app/src/main/res/layout/fragment_image_blurring_dialog.xml
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/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
From 13ccb69a9fbdee3fbcfbcfe22f382dba1f891d68 Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:09:17 +0800
Subject: [PATCH 5/8] Update and implement setting blurring of background image
for day mode
Signed-off-by: 1552980358 <1552980358@qq.com>
---
.../java/io/legado/app/base/BaseActivity.kt | 18 +++++++++++++++---
.../app/ui/config/ThemeConfigFragment.kt | 3 +++
app/src/main/res/values-zh/strings.xml | 3 +++
app/src/main/res/values/strings.xml | 3 +++
app/src/main/res/xml/pref_config_theme.xml | 4 ++++
5 files changed, 28 insertions(+), 3 deletions(-)
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..433ce1ba5 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,14 @@ 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.Theme
import io.legado.app.help.AppConfig
import io.legado.app.help.ThemeConfig
@@ -174,9 +179,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 +188,15 @@ abstract class BaseActivity(
}
}
+ private fun getBackgroundImage(bitmap: Bitmap): Bitmap {
+ PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageBlurring, 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/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
index da4d47c6f..2f8976d08 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,9 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}
}
}
+ PreferKey.bgImageBlurring -> {
+ ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager)
+ }
PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) {
selectImage.launch(requestCodeCover)
} else {
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 910663504..e1d905ecc 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 92954b0a0..f36ab7c67 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..50ffb4172 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" />
+
+
Date: Wed, 4 Aug 2021 17:14:23 +0800
Subject: [PATCH 6/8] build.gradle: Revert target JavaVersion back to
VERSION_11
Signed-off-by: 1552980358 <1552980358@qq.com>
---
app/build.gradle | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 76266295b..ca80a26a8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -98,8 +98,8 @@ android {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 11
- sourceCompatibility "1.8"
- targetCompatibility "1.8"
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
From 9a751d1fbbc67558ca6e68b99787fa6754cdbcf0 Mon Sep 17 00:00:00 2001
From: 1552980358 <1552980358@qq.com>
Date: Wed, 4 Aug 2021 17:51:59 +0800
Subject: [PATCH 7/8] Add support customize background image blurring
Signed-off-by: 1552980358 <1552980358@qq.com>
---
.../main/java/io/legado/app/base/BaseActivity.kt | 14 +++++++++++---
.../main/java/io/legado/app/constant/PreferKey.kt | 1 +
.../io/legado/app/ui/config/ThemeConfigFragment.kt | 5 ++---
app/src/main/res/xml/pref_config_theme.xml | 4 ++++
4 files changed, 18 insertions(+), 6 deletions(-)
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 433ce1ba5..306e61943 100644
--- a/app/src/main/java/io/legado/app/base/BaseActivity.kt
+++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt
@@ -20,6 +20,7 @@ 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
@@ -189,9 +190,16 @@ abstract class BaseActivity(
}
private fun getBackgroundImage(bitmap: Bitmap): Bitmap {
- PreferenceManager.getDefaultSharedPreferences(this).getInt(bgImageBlurring, 0).apply {
- if (this != 0) {
- return Toolkit.blur(bitmap, this)
+ 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
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 59c10f8e8..d2224a584 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -98,5 +98,6 @@ object PreferKey {
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/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
index 2f8976d08..8f6163216 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,9 +183,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}
}
}
- PreferKey.bgImageBlurring -> {
- ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager)
- }
+ 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/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml
index 50ffb4172..564cb9811 100644
--- a/app/src/main/res/xml/pref_config_theme.xml
+++ b/app/src/main/res/xml/pref_config_theme.xml
@@ -153,6 +153,10 @@
android:key="backgroundImageNight"
android:title="@string/background_image" />
+
+
Date: Wed, 4 Aug 2021 18:03:17 +0800
Subject: [PATCH 8/8] Update strings.xml for zh-rHK and zh-rTW
Signed-off-by: 1552980358 <1552980358@qq.com>
---
app/src/main/res/values-zh-rHK/strings.xml | 3 +++
app/src/main/res/values-zh-rTW/strings.xml | 3 +++
2 files changed, 6 insertions(+)
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 5d4812042..7ab4f87ea 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 cb5621f19..609cf8f27 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