pull/32/head
kunfei 5 years ago
parent 31d1872b76
commit fe310524e7
  1. 17
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 21
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt

@ -9,7 +9,6 @@ import android.text.SpannableStringBuilder
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
@ -83,7 +82,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
changeSourceDialog =
supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
}
setScreenBrightness(getPrefInt("brightness", 100))
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
@ -458,21 +456,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
/**
* 设置屏幕亮度
*/
override fun setScreenBrightness(value: Int) {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (!read_menu.brightnessAuto()) {
brightness = value.toFloat()
if (brightness < 1f) brightness = 1f
brightness /= 255f
}
val params = window.attributes
params.screenBrightness = brightness
window.attributes = params
}
override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) {
when (dialogId) {
TEXT_COLOR -> {

@ -2,6 +2,7 @@ package io.legado.app.ui.readbook
import android.content.Context
import android.util.AttributeSet
import android.view.WindowManager
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.FrameLayout
@ -59,6 +60,22 @@ class ReadMenu : FrameLayout {
iv_brightness_auto.setColorFilter(context.buttonDisabledColor)
seek_brightness.isEnabled = true
}
setScreenBrightness(context.getPrefInt("brightness", 100))
}
/**
* 设置屏幕亮度
*/
private fun setScreenBrightness(value: Int) {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (!brightnessAuto()) {
brightness = value.toFloat()
if (brightness < 1f) brightness = 1f
brightness /= 255f
}
val params = activity?.window?.attributes
params?.screenBrightness = brightness
activity?.window?.attributes = params
}
fun runMenuIn() {
@ -93,11 +110,10 @@ class ReadMenu : FrameLayout {
!brightnessAuto()
)
upBrightnessState()
callBack?.setScreenBrightness(context.getPrefInt("brightness", 100))
}
seek_brightness.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
callBack?.setScreenBrightness(progress)
setScreenBrightness(progress)
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
@ -231,7 +247,6 @@ class ReadMenu : FrameLayout {
}
interface CallBack {
fun setScreenBrightness(value: Int)
fun autoPage()
fun skipToPage(page: Int)
fun moveToPrevChapter(last: Boolean)

Loading…
Cancel
Save