pull/1211/head
gedoor 3 years ago
parent 4de996711f
commit 0994e59d4c
  1. 16
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 26
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  12. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  13. 2
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  14. 2
      app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt
  15. 2
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  16. 4
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  17. 2
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  18. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  19. 4
      app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt
  20. 4
      app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt
  21. 2
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  22. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt
  23. 27
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
  24. 0
      app/src/main/java/io/legado/app/utils/JsonExtensions.kt

@ -2,7 +2,6 @@ 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
@ -13,13 +12,10 @@ import android.view.View
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
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
@ -179,7 +175,7 @@ abstract class BaseActivity<VB : ViewBinding>(
}
if (imageBg) {
try {
getBackgroundImage()?.let {
ThemeConfig.getBgImage(this, windowSize)?.let {
window.decorView.background = BitmapDrawable(resources, it)
}
} catch (e: OutOfMemoryError) {
@ -190,16 +186,6 @@ abstract class BaseActivity<VB : ViewBinding>(
}
}
private fun getBackgroundImage(): Bitmap? {
val bgImage = ThemeConfig.getBgImage(this) ?: return null
val blur = if (AppConfig.isNightTheme) {
getPrefInt(bgImageBlurring, 0)
} else {
getPrefInt(bgImageNBlurring, 0)
}
return Toolkit.blur(bgImage, blur)
}
private fun setupSystemBar() {
if (fullScreen && !isInMultiWindow) {
ATH.fullScreen(this)

@ -2,10 +2,11 @@ package io.legado.app.help
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.util.DisplayMetrics
import androidx.annotation.Keep
import androidx.appcompat.app.AppCompatDelegate
import com.google.android.renderscript.Toolkit
import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
@ -43,14 +44,23 @@ object ThemeConfig {
AppCompatDelegate.setDefaultNightMode(targetMode)
}
fun getBgImage(context: Context): Bitmap? {
val bgPath = when (Theme.getTheme()) {
Theme.Light -> context.getPrefString(PreferKey.bgImage)
Theme.Dark -> context.getPrefString(PreferKey.bgImageN)
fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? {
val bgCfg = when (Theme.getTheme()) {
Theme.Light -> Pair(
context.getPrefString(PreferKey.bgImage),
context.getPrefInt(PreferKey.bgImageBlurring, 0)
)
Theme.Dark -> Pair(
context.getPrefString(PreferKey.bgImageN),
context.getPrefInt(PreferKey.bgImageNBlurring, 0)
)
else -> null
}
if (bgPath.isNullOrBlank()) return null
return BitmapFactory.decodeFile(bgPath)
} ?: return null
if (bgCfg.first.isNullOrBlank()) return null
val bgImage = BitmapUtils
.decodeBitmap(bgCfg.first!!, metrics.widthPixels, metrics.heightPixels)
?: return null
return Toolkit.blur(bgImage, bgCfg.second)
}
fun upConfig() {

@ -14,9 +14,8 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogChangeCoverBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
class ChangeCoverDialog : BaseDialogFragment(),
@ -45,7 +44,7 @@ class ChangeCoverDialog : BaseDialogFragment(),
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -53,7 +53,7 @@ class ChangeSourceDialog : BaseDialogFragment(),
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -28,10 +28,10 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import io.legado.app.utils.windowSize
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@ -43,7 +43,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -29,9 +29,9 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@ -61,7 +61,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -11,9 +11,9 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.databinding.DialogReadPaddingBinding
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.getSize
import io.legado.app.utils.postEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
class PaddingConfigDialog : BaseDialogFragment() {
@ -21,7 +21,7 @@ class PaddingConfigDialog : BaseDialogFragment() {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.let {
it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
val attr = it.attributes

@ -19,8 +19,8 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.utils.getPrefLong
import io.legado.app.utils.getSize
import io.legado.app.utils.postEvent
import io.legado.app.utils.windowSize
import splitties.init.appCtx
class ReadAloudConfigDialog : DialogFragment() {
@ -28,7 +28,7 @@ class ReadAloudConfigDialog : DialogFragment() {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.let {
it.setBackgroundDrawableResource(R.color.transparent)
it.setLayout((dm.widthPixels * 0.9).toInt(), ViewGroup.LayoutParams.WRAP_CONTENT)

@ -54,7 +54,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -45,7 +45,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.8).toInt())
}

@ -444,7 +444,7 @@ class BookSourceEditActivity :
val rect = Rect()
// 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this@BookSourceEditActivity.getSize().heightPixels
val screenHeight = this@BookSourceEditActivity.windowSize.heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) {

@ -24,10 +24,10 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@ -39,7 +39,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -26,7 +26,7 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -76,7 +76,7 @@ class FilePickerDialog : DialogFragment(),
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.8).toInt())
}

@ -36,7 +36,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -19,9 +19,9 @@ import io.legado.app.databinding.ActivityReplaceEditBinding
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getSize
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import kotlin.math.abs
/**
@ -166,7 +166,7 @@ class ReplaceEditActivity :
val rect = Rect()
// 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this.getSize().heightPixels
val screenHeight = this.windowSize.heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) {

@ -256,7 +256,7 @@ class RssSourceEditActivity :
val rect = Rect()
// 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this@RssSourceEditActivity.getSize().heightPixels
val screenHeight = this@RssSourceEditActivity.windowSize.heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) {

@ -37,7 +37,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -8,8 +8,8 @@ import androidx.fragment.app.FragmentManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogTextViewBinding
import io.legado.app.utils.getSize
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import io.noties.markwon.Markwon
import io.noties.markwon.ext.tables.TablePlugin
import io.noties.markwon.html.HtmlPlugin
@ -49,7 +49,7 @@ class TextDialog : BaseDialogFragment() {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -13,8 +13,8 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemLogBinding
import io.legado.app.utils.getSize
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
class TextListDialog : BaseDialogFragment() {
@ -35,7 +35,7 @@ class TextListDialog : BaseDialogFragment() {
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -65,7 +65,7 @@ class FontSelectDialog : BaseDialogFragment(),
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}

@ -21,8 +21,8 @@ import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemIconPreferenceBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.getCompatDrawable
import io.legado.app.utils.getSize
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
@ -131,7 +131,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference
override fun onStart() {
super.onStart()
val dm = requireActivity().getSize()
val dm = requireActivity().windowSize
dialog?.window?.setLayout(
(dm.widthPixels * 0.8).toInt(),
ViewGroup.LayoutParams.WRAP_CONTENT

@ -6,20 +6,21 @@ import android.util.DisplayMetrics
import android.view.WindowInsets
import android.view.WindowMetrics
fun Activity.getSize(): DisplayMetrics {
val displayMetrics = DisplayMetrics()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics: WindowMetrics = windowManager.currentWindowMetrics
val insets = windowMetrics.windowInsets
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
displayMetrics.widthPixels = windowMetrics.bounds.width() - insets.left - insets.right
displayMetrics.heightPixels = windowMetrics.bounds.height() - insets.top - insets.bottom
} else {
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getMetrics(displayMetrics)
val Activity.windowSize: DisplayMetrics
get() {
val displayMetrics = DisplayMetrics()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics: WindowMetrics = windowManager.currentWindowMetrics
val insets = windowMetrics.windowInsets
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
displayMetrics.widthPixels = windowMetrics.bounds.width() - insets.left - insets.right
displayMetrics.heightPixels = windowMetrics.bounds.height() - insets.top - insets.bottom
} else {
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getMetrics(displayMetrics)
}
return displayMetrics
}
return displayMetrics
}
/**
* 该方法需要在View完全被绘制出来之后调用否则判断不了

Loading…
Cancel
Save