Merge pull request #1209 from 1552980358/master

Add support customize background image blurring
pull/1211/head
kunfei 3 years ago committed by GitHub
commit bac4db623b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/build.gradle
  2. 26
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  3. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  4. 8
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  5. 53
      app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt
  6. 2
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  7. 28
      app/src/main/res/layout/fragment_image_blurring_dialog.xml
  8. 3
      app/src/main/res/values-zh-rHK/strings.xml
  9. 3
      app/src/main/res/values-zh-rTW/strings.xml
  10. 3
      app/src/main/res/values-zh/strings.xml
  11. 3
      app/src/main/res/values/strings.xml
  12. 8
      app/src/main/res/xml/pref_config_theme.xml

@ -213,6 +213,9 @@ dependencies {
implementation("io.noties.markwon:ext-tables:$markwonVersion") implementation("io.noties.markwon:ext-tables:$markwonVersion")
implementation("io.noties.markwon:html:$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') implementation('com.github.liuyueyi.quick-chinese-transfer:quick-transfer-core:0.2.1')

@ -2,6 +2,8 @@ package io.legado.app.base
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
@ -10,11 +12,15 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import com.google.android.renderscript.Toolkit
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey 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.constant.Theme
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ThemeConfig import io.legado.app.help.ThemeConfig
@ -174,9 +180,7 @@ abstract class BaseActivity<VB : ViewBinding>(
} }
if (imageBg) { if (imageBg) {
try { try {
ThemeConfig.getBgImage(this)?.let { window.decorView.background = BitmapDrawable(resources, getBackgroundImage(ThemeConfig.getBgImage(this) ?: return))
window.decorView.background = it
}
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
toastOnUi(e.localizedMessage) toastOnUi(e.localizedMessage)
} catch (e: Exception) { } catch (e: Exception) {
@ -185,6 +189,22 @@ abstract class BaseActivity<VB : ViewBinding>(
} }
} }
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() { private fun setupSystemBar() {
if (fullScreen && !isInMultiWindow) { if (fullScreen && !isInMultiWindow) {
ATH.fullScreen(this) ATH.fullScreen(this)

@ -91,11 +91,13 @@ object PreferKey {
const val cBackground = "colorBackground" const val cBackground = "colorBackground"
const val cBBackground = "colorBottomBackground" const val cBBackground = "colorBottomBackground"
const val bgImage = "backgroundImage" const val bgImage = "backgroundImage"
const val bgImageBlurring = "backgroundImageBlurring"
const val cNPrimary = "colorPrimaryNight" const val cNPrimary = "colorPrimaryNight"
const val cNAccent = "colorAccentNight" const val cNAccent = "colorAccentNight"
const val cNBackground = "colorBackgroundNight" const val cNBackground = "colorBackgroundNight"
const val cNBBackground = "colorBottomBackgroundNight" const val cNBBackground = "colorBottomBackgroundNight"
const val bgImageN = "backgroundImageNight" const val bgImageN = "backgroundImageNight"
const val bgImageNBlurring = "backgroundImageNightBlurring"
} }

@ -1,9 +1,9 @@
package io.legado.app.help package io.legado.app.help
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.Keep import androidx.annotation.Keep
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import io.legado.app.R import io.legado.app.R
@ -43,14 +43,14 @@ object ThemeConfig {
AppCompatDelegate.setDefaultNightMode(targetMode) AppCompatDelegate.setDefaultNightMode(targetMode)
} }
fun getBgImage(context: Context): Drawable? { fun getBgImage(context: Context): Bitmap? {
val bgPath = when (Theme.getTheme()) { val bgPath = when (Theme.getTheme()) {
Theme.Light -> context.getPrefString(PreferKey.bgImage) Theme.Light -> context.getPrefString(PreferKey.bgImage)
Theme.Dark -> context.getPrefString(PreferKey.bgImageN) Theme.Dark -> context.getPrefString(PreferKey.bgImageN)
else -> null else -> null
} }
if (bgPath.isNullOrBlank()) return null if (bgPath.isNullOrBlank()) return null
return BitmapDrawable.createFromPath(bgPath) return BitmapFactory.decodeFile(bgPath)
} }
fun upConfig() { fun upConfig() {

@ -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)
}

@ -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()) { PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
} else { } else {

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<androidx.appcompat.widget.AppCompatSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="25"
android:id="@+id/seek_bar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_view_value"
android:layout_gravity="center_horizontal"
android:textSize="17sp"
android:textColor="@color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/background_image_hint" />
</LinearLayout>

@ -804,6 +804,9 @@
<string name="pre_download_s">預先下載%s章正文</string> <string name="pre_download_s">預先下載%s章正文</string>
<string name="is_enabled">係咪啟用</string> <string name="is_enabled">係咪啟用</string>
<string name="background_image">背景圖片</string> <string name="background_image">背景圖片</string>
<string name="background_image_blurring">背景圖片虛化</string>
<string name="background_image_blurring_radius">虛化半徑</string>
<string name="background_image_hint">0為停用,啓用範圍1~25\n半徑數值越大,虛化效果越高</string>
<string name="export_folder">導出資料夾</string> <string name="export_folder">導出資料夾</string>
<string name="export_charset">導出編碼</string> <string name="export_charset">導出編碼</string>
<string name="export_to_web_dav">導出到WebDav</string> <string name="export_to_web_dav">導出到WebDav</string>

@ -807,6 +807,9 @@
<string name="pre_download_s">預先下載%s章正文</string> <string name="pre_download_s">預先下載%s章正文</string>
<string name="is_enabled">是否啟用</string> <string name="is_enabled">是否啟用</string>
<string name="background_image">背景圖片</string> <string name="background_image">背景圖片</string>
<string name="background_image_blurring">背景圖片虛化</string>
<string name="background_image_blurring_radius">虛化半徑</string>
<string name="background_image_hint">0為停用,啓用範圍1~25\n半徑數值越大,虛化效果越高</string>
<string name="export_folder">匯出資料夾</string> <string name="export_folder">匯出資料夾</string>
<string name="export_charset">匯出編碼</string> <string name="export_charset">匯出編碼</string>
<string name="export_to_web_dav">匯出到WebDav</string> <string name="export_to_web_dav">匯出到WebDav</string>

@ -807,6 +807,9 @@
<string name="pre_download_s">预先下载%s章正文</string> <string name="pre_download_s">预先下载%s章正文</string>
<string name="is_enabled">是否启用</string> <string name="is_enabled">是否启用</string>
<string name="background_image">背景图片</string> <string name="background_image">背景图片</string>
<string name="background_image_blurring">背景图片虚化</string>
<string name="background_image_blurring_radius">虚化半径</string>
<string name="background_image_hint">0为停用,启用范围1~25\n半径数值越大,虚化效果越高</string>
<string name="export_folder">导出文件夹</string> <string name="export_folder">导出文件夹</string>
<string name="export_charset">导出编码</string> <string name="export_charset">导出编码</string>
<string name="export_to_web_dav">导出到WebDav</string> <string name="export_to_web_dav">导出到WebDav</string>

@ -807,6 +807,9 @@
<string name="pre_download_s">Download %s chapters in advance</string> <string name="pre_download_s">Download %s chapters in advance</string>
<string name="is_enabled">Is enabled</string> <string name="is_enabled">Is enabled</string>
<string name="background_image">Background image</string> <string name="background_image">Background image</string>
<string name="background_image_blurring">Background image blurring</string>
<string name="background_image_blurring_radius">Blurring radius</string>
<string name="background_image_hint">Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring</string>
<string name="copy_book_url">Copy book URL</string> <string name="copy_book_url">Copy book URL</string>
<string name="copy_toc_url">Copy chapters URL</string> <string name="copy_toc_url">Copy chapters URL</string>
<string name="export_folder">Export folder</string> <string name="export_folder">Export folder</string>

@ -86,6 +86,10 @@
android:key="backgroundImage" android:key="backgroundImage"
android:title="@string/background_image" /> android:title="@string/background_image" />
<io.legado.app.ui.widget.prefs.Preference
android:key="backgroundImageBlurring"
android:title="@string/background_image_blurring" />
<io.legado.app.ui.widget.prefs.ColorPreference <io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_grey_200" android:defaultValue="@color/md_grey_200"
android:key="colorBottomBackground" android:key="colorBottomBackground"
@ -149,6 +153,10 @@
android:key="backgroundImageNight" android:key="backgroundImageNight"
android:title="@string/background_image" /> android:title="@string/background_image" />
<io.legado.app.ui.widget.prefs.Preference
android:key="backgroundImageNightBlurring"
android:title="@string/background_image_blurring" />
<io.legado.app.ui.widget.prefs.ColorPreference <io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_grey_800" android:defaultValue="@color/md_grey_800"
android:key="colorBottomBackgroundNight" android:key="colorBottomBackgroundNight"

Loading…
Cancel
Save