Update and implement setting blurring of background image for day mode

Signed-off-by: 1552980358 <1552980358@qq.com>
pull/1209/head
1552980358 3 years ago
parent c02331e9be
commit 13ccb69a9f
  1. 18
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 3
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  3. 3
      app/src/main/res/values-zh/strings.xml
  4. 3
      app/src/main/res/values/strings.xml
  5. 4
      app/src/main/res/xml/pref_config_theme.xml

@ -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,14 @@ 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.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 +179,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 +188,15 @@ abstract class BaseActivity<VB : ViewBinding>(
} }
} }
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() { private fun setupSystemBar() {
if (fullScreen && !isInMultiWindow) { if (fullScreen && !isInMultiWindow) {
ATH.fullScreen(this) ATH.fullScreen(this)

@ -183,6 +183,9 @@ class ThemeConfigFragment : BasePreferenceFragment(),
} }
} }
} }
PreferKey.bgImageBlurring -> {
ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager)
}
PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
} else { } else {

@ -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"

Loading…
Cancel
Save