From 65abc0c666b75c9fe164d4740d1fceccfa2017d8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Oct 2021 15:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseActivity.kt | 4 +- .../main/java/io/legado/app/lib/theme/ATH.kt | 42 ------------------- .../app/ui/book/read/ReadBookBaseActivity.kt | 3 +- .../io/legado/app/utils/ActivityExtensions.kt | 32 ++++++++++++++ 4 files changed, 36 insertions(+), 45 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 61aa04b48..88941e805 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -171,10 +171,10 @@ abstract class BaseActivity( open fun upNavigationBarColor() { if (AppConfig.immNavigationBar) { - ATH.setNavigationBarColorAuto(this, ThemeStore.navigationBarColor(this)) + setNavigationBarColorAuto(ThemeStore.navigationBarColor(this)) } else { val nbColor = ColorUtils.darkenColor(ThemeStore.navigationBarColor(this)) - ATH.setNavigationBarColorAuto(this, nbColor) + setNavigationBarColorAuto(nbColor) } } diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 97b359ad8..b4074dbc3 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -8,7 +8,6 @@ import android.graphics.Color import android.graphics.drawable.GradientDrawable import android.os.Build import android.view.View -import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR import android.view.WindowInsetsController import android.view.WindowManager import android.widget.EdgeEffect @@ -118,47 +117,6 @@ object ATH { } } - fun setNavigationBarColorAuto( - activity: Activity, - color: Int, - ) { - activity.window.navigationBarColor = color - setLightNavigationBar(activity, ColorUtils.isColorLight(color)) - } - - fun setLightNavigationBar(activity: Activity, enabled: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - activity.window.insetsController?.let { - if (enabled) { - it.setSystemBarsAppearance( - WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, - WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS - ) - } else { - it.setSystemBarsAppearance( - 0, - WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS - ) - } - } - } - setLightNavigationBarO(activity, enabled) - } - - @Suppress("DEPRECATION") - private fun setLightNavigationBarO(activity: Activity, enabled: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val decorView = activity.window.decorView - var systemUiVisibility = decorView.systemUiVisibility - systemUiVisibility = if (enabled) { - systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } else { - systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() - } - decorView.systemUiVisibility = systemUiVisibility - } - } - fun setTaskDescriptionColorAuto(activity: Activity) { setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity)) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt index 080727d8b..c61217cdb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt @@ -142,7 +142,8 @@ abstract class ReadBookBaseActivity : when { binding.readMenu.isVisible -> super.upNavigationBarColor() bottomDialog > 0 -> super.upNavigationBarColor() - else -> ATH.setNavigationBarColorAuto(this, ReadBookConfig.bgMeanColor) + !AppConfig.immNavigationBar -> super.upNavigationBarColor() + else -> setNavigationBarColorAuto(ReadBookConfig.bgMeanColor) } } 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 8ea8b9802..d4e0bb09f 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.util.DisplayMetrics import android.view.* import android.widget.FrameLayout +import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.DialogFragment @@ -39,6 +40,37 @@ val Activity.windowSize: DisplayMetrics return displayMetrics } +@Suppress("DEPRECATION") +fun Activity.setNavigationBarColorAuto(@ColorInt color: Int) { + val isLightBor = ColorUtils.isColorLight(color) + window.navigationBarColor = color + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.insetsController?.let { + if (isLightBor) { + it.setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } else { + it.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val decorView = window.decorView + var systemUiVisibility = decorView.systemUiVisibility + systemUiVisibility = if (isLightBor) { + systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } else { + systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() + } + decorView.systemUiVisibility = systemUiVisibility + } +} + /////以下方法需要在View完全被绘制出来之后调用,否则判断不了,在比如 onWindowFocusChanged()方法中可以得到正确的结果///// /**