pull/1395/head
gedoor 3 years ago
parent e566d77dbd
commit 65abc0c666
  1. 4
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 42
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  4. 32
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt

@ -171,10 +171,10 @@ abstract class BaseActivity<VB : ViewBinding>(
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)
}
}

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

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

@ -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()方法中可以得到正确的结果/////
/**

Loading…
Cancel
Save