pull/32/head
kunfei 5 years ago
parent 3dfc060d64
commit 84f179fc00
  1. 17
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 26
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 3
      app/src/main/java/io/legado/app/ui/readbook/Help.kt

@ -1,6 +1,5 @@
package io.legado.app.base package io.legado.app.base
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -10,15 +9,17 @@ import androidx.appcompat.app.AppCompatActivity
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.* import io.legado.app.utils.applyTint
import io.legado.app.utils.disableAutoFill
import io.legado.app.utils.hideSoftInput
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
abstract class BaseActivity(private val layoutID: Int, private val fullScreen: Boolean = true) : AppCompatActivity(), abstract class BaseActivity(private val layoutID: Int, private val fullScreen: Boolean = true) :
AppCompatActivity(),
CoroutineScope by MainScope() { CoroutineScope by MainScope() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -80,14 +81,8 @@ abstract class BaseActivity(private val layoutID: Int, private val fullScreen: B
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
if (isTransparentStatusBar) {
window.statusBarColor = Color.TRANSPARENT
} else {
window.statusBarColor = getCompatColor(R.color.status_bar_bag)
}
} else {
window.statusBarColor = ThemeStore.statusBarColor(this, isTransparentStatusBar)
} }
ATH.setStatusbarColorAuto(this, fullScreen)
} }
open fun observeLiveBus() { open fun observeLiveBus() {

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.ActivityManager import android.app.ActivityManager
import android.content.Context import android.content.Context
import android.graphics.Color
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
@ -34,18 +35,27 @@ object ATH {
) > since ) > since
} }
fun setStatusbarColorAuto(activity: Activity) { fun setStatusbarColorAuto(activity: Activity, fullScreen: Boolean) {
val isTransparentStatusBar = activity.isTransparentStatusBar
setStatusbarColor( setStatusbarColor(
activity, activity,
ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) ThemeStore.statusBarColor(activity, isTransparentStatusBar),
isTransparentStatusBar, fullScreen
) )
} }
fun setStatusbarColor(activity: Activity, color: Int) { fun setStatusbarColor(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity: Activity,
color: Int,
isTransparentStatusBar: Boolean,
fullScreen: Boolean
) {
if (fullScreen && isTransparentStatusBar) {
activity.window.statusBarColor = Color.TRANSPARENT
} else {
activity.window.statusBarColor = color activity.window.statusBarColor = color
setLightStatusbarAuto(activity, color)
} }
setLightStatusbarAuto(activity, color)
} }
fun setLightStatusbarAuto(activity: Activity, bgColor: Int) { fun setLightStatusbarAuto(activity: Activity, bgColor: Int) {
@ -68,10 +78,10 @@ object ATH {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val decorView = activity.window.decorView val decorView = activity.window.decorView
var systemUiVisibility = decorView.systemUiVisibility var systemUiVisibility = decorView.systemUiVisibility
if (enabled) { systemUiVisibility = if (enabled) {
systemUiVisibility = systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
} else { } else {
systemUiVisibility = systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
} }
decorView.systemUiVisibility = systemUiVisibility decorView.systemUiVisibility = systemUiVisibility
} }

@ -20,8 +20,7 @@ object Help {
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
val hideNavigationBar = App.INSTANCE.getPrefBoolean("hideNavigationBar") val hideNavigationBar = App.INSTANCE.getPrefBoolean("hideNavigationBar")
if (hideNavigationBar) { if (hideNavigationBar) {
flag = flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
} }
if (hide) { if (hide) {
if (App.INSTANCE.getPrefBoolean("hideStatusBar")) { if (App.INSTANCE.getPrefBoolean("hideStatusBar")) {

Loading…
Cancel
Save