pull/32/head
kunfei 5 years ago
parent fab0d7c76f
commit f045b83689
  1. 26
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  2. 11
      app/src/main/java/io/legado/app/ui/readbook/Help.kt
  3. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt
  6. 2
      app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt
  7. 2
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  8. 2
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt

@ -8,6 +8,7 @@ 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
import android.view.Window
import android.widget.EdgeEffect import android.widget.EdgeEffect
import android.widget.ScrollView import android.widget.ScrollView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
@ -15,6 +16,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.isNightTheme import io.legado.app.utils.isNightTheme
@ -36,36 +38,36 @@ object ATH {
) > since ) > since
} }
fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { fun setStatusBarColorAuto(window: Window, fullScreen: Boolean) {
val isTransparentStatusBar = activity.isTransparentStatusBar val isTransparentStatusBar = App.INSTANCE.isTransparentStatusBar
setStatusBarColor( setStatusBarColor(
activity, window,
ThemeStore.statusBarColor(activity, isTransparentStatusBar), ThemeStore.statusBarColor(App.INSTANCE, isTransparentStatusBar),
isTransparentStatusBar, fullScreen isTransparentStatusBar, fullScreen
) )
} }
fun setStatusBarColor( fun setStatusBarColor(
activity: Activity, window: Window,
color: Int, color: Int,
isTransparentStatusBar: Boolean, isTransparentStatusBar: Boolean,
fullScreen: Boolean fullScreen: Boolean
) { ) {
if (fullScreen && isTransparentStatusBar) { if (fullScreen && isTransparentStatusBar) {
activity.window.statusBarColor = Color.TRANSPARENT window.statusBarColor = Color.TRANSPARENT
} else { } else {
activity.window.statusBarColor = color window.statusBarColor = color
} }
setLightStatusBarAuto(activity, color) setLightStatusBarAuto(window, color)
} }
fun setLightStatusBarAuto(activity: Activity, bgColor: Int) { fun setLightStatusBarAuto(window: Window, bgColor: Int) {
setLightStatusBar(activity, ColorUtils.isColorLight(bgColor)) setLightStatusBar(window, ColorUtils.isColorLight(bgColor))
} }
fun setLightStatusBar(activity: Activity, enabled: Boolean) { fun setLightStatusBar(window: Window, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val decorView = activity.window.decorView val decorView = window.decorView
val systemUiVisibility = decorView.systemUiVisibility val systemUiVisibility = decorView.systemUiVisibility
if (enabled) { if (enabled) {
decorView.systemUiVisibility = decorView.systemUiVisibility =

@ -4,6 +4,7 @@ import android.app.Activity
import android.view.View import android.view.View
import android.view.View.NO_ID import android.view.View.NO_ID
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window
import io.legado.app.App import io.legado.app.App
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -16,7 +17,7 @@ object Help {
private const val NAVIGATION = "navigationBarBackground" private const val NAVIGATION = "navigationBarBackground"
fun upSystemUiVisibility(activity: Activity, toolBarHide: Boolean = true) { fun upSystemUiVisibility(window: Window, toolBarHide: Boolean = true) {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_IMMERSIVE
@ -33,13 +34,13 @@ object Help {
flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
} }
} }
activity.window.decorView.systemUiVisibility = flag window.decorView.systemUiVisibility = flag
if (toolBarHide) { if (toolBarHide) {
ATH.setLightStatusBar(activity, ReadBookConfig.getConfig().statusIconDark()) ATH.setLightStatusBar(window, ReadBookConfig.getConfig().statusIconDark())
} else { } else {
ATH.setLightStatusBarAuto( ATH.setLightStatusBarAuto(
activity, window,
ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) ThemeStore.statusBarColor(App.INSTANCE, App.INSTANCE.isTransparentStatusBar)
) )
} }
} }

@ -437,7 +437,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
override fun upSystemUiVisibility() { override fun upSystemUiVisibility() {
Help.upSystemUiVisibility(this, !read_menu.isVisible) Help.upSystemUiVisibility(window, !read_menu.isVisible)
} }
/** /**

@ -55,10 +55,10 @@ class BgTextConfigDialog : DialogFragment() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
activity?.let { activity?.let {
Help.upSystemUiVisibility(it)
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
Help.upSystemUiVisibility(it)
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes
@ -103,7 +103,7 @@ class BgTextConfigDialog : DialogFragment() {
sw_dark_status_icon.onCheckedChange { buttonView, isChecked -> sw_dark_status_icon.onCheckedChange { buttonView, isChecked ->
if (buttonView?.isPressed == true) { if (buttonView?.isPressed == true) {
setStatusIconDark(isChecked) setStatusIconDark(isChecked)
activity?.let { activity?.window?.let {
Help.upSystemUiVisibility(it) Help.upSystemUiVisibility(it)
} }
} }

@ -31,10 +31,10 @@ class MoreConfigDialog : DialogFragment() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
activity?.let { activity?.let {
Help.upSystemUiVisibility(it)
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
Help.upSystemUiVisibility(it)
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes

@ -29,10 +29,10 @@ class PaddingConfigDialog : DialogFragment() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
activity?.let { activity?.let {
Help.upSystemUiVisibility(it)
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
Help.upSystemUiVisibility(it)
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes

@ -34,10 +34,10 @@ class ReadAloudDialog : DialogFragment() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
activity?.let { activity?.let {
Help.upSystemUiVisibility(it)
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
Help.upSystemUiVisibility(it)
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes

@ -46,10 +46,10 @@ class ReadStyleDialog : DialogFragment() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
activity?.let { activity?.let {
Help.upSystemUiVisibility(it)
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
Help.upSystemUiVisibility(it)
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.transparent)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes

Loading…
Cancel
Save