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 1d8b1f7cf..8f4105882 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.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( } 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( } } - 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) 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 39d33e02b..506082c9d 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -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() { diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index 5558da7fc..2d3084173 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index acd00f18d..b5e3873b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 89dfd8495..b3e7dfc66 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 8a7fff0a5..6beb2e626 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index e44eeb8b2..d07fb7618 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 38bf88920..d161a4ede 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 6ecc7356b..97e3a2bf6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 6e278246f..56aa2eb69 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 0ab548be7..74c2aaf8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 92ffb0c9a..9d608d7b7 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index be118d3de..b4275a7ae 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt index af573efb0..06964a969 100644 --- a/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index 814f7493e..9572b2582 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt index 8fd22551a..922875250 100644 --- a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index cd941c206..f5eac52f4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index f058c5577..7696f4b58 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt index 8c1df6110..75d02b6b5 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt index cc79dc726..6dd173274 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 22f205101..3b25ba29d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -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()) } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index 12b33a2c7..bf469748c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index 72840c097..842a95bbe 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -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完全被绘制出来之后调用,否则判断不了 diff --git a/app/src/main/java/io/legado/app/utils/MiscExtensions.kt b/app/src/main/java/io/legado/app/utils/JsonExtensions.kt similarity index 100% rename from app/src/main/java/io/legado/app/utils/MiscExtensions.kt rename to app/src/main/java/io/legado/app/utils/JsonExtensions.kt