This commit is contained in:
kunfei 2023-07-04 20:50:17 +08:00
parent 8ac2027556
commit bb19ad68fc
3 changed files with 20 additions and 16 deletions

View File

@ -17,11 +17,9 @@ object AppLog {
mLogs.removeLastOrNull()
}
mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable))
if (throwable != null) {
if (BuildConfig.DEBUG) {
val stackTrace = Thread.currentThread().stackTrace
Log.e(stackTrace[3].className, message, throwable)
}
if (BuildConfig.DEBUG) {
val stackTrace = Thread.currentThread().stackTrace
Log.e(stackTrace[3].className, message, throwable)
}
}

View File

@ -199,7 +199,15 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
upSystemUiVisibility()
binding.readMenu.upBrightnessState()
if (hasFocus) {
//调节系统亮度后如果设置亮度值和原来一样亮度不会变
launch {
delay(100)
binding.readMenu.setScreenBrightness(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
delay(1000)
binding.readMenu.upBrightnessState()
}
}
}
override fun onConfigurationChanged(newConfig: Configuration) {

View File

@ -11,7 +11,7 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import android.view.WindowManager
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
import android.view.animation.Animation
import android.widget.FrameLayout
import android.widget.SeekBar
@ -248,26 +248,24 @@ class ReadMenu @JvmOverloads constructor(
binding.ivBrightnessAuto.setColorFilter(context.buttonDisabledColor)
binding.seekBrightness.isEnabled = true
}
setScreenBrightness(AppConfig.readBrightness)
setScreenBrightness(AppConfig.readBrightness.toFloat())
}
/**
* 设置屏幕亮度
*/
private fun setScreenBrightness(value: Int) {
fun setScreenBrightness(value: Float) {
activity?.run {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (!brightnessAuto()) {
brightness = value.toFloat()
var brightness = BRIGHTNESS_OVERRIDE_NONE
if (!brightnessAuto() && value != BRIGHTNESS_OVERRIDE_NONE) {
brightness = value
if (brightness < 1f) brightness = 1f
brightness /= 255f
}
val params = window.attributes
params.screenBrightness = brightness
window.attributes = params
if (AppConfig.recordLog) {
AppLog.put("设置亮度$brightness")
}
AppLog.put("设置亮度$brightness")
}
}
@ -364,7 +362,7 @@ class ReadMenu @JvmOverloads constructor(
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
if (fromUser) {
setScreenBrightness(progress)
setScreenBrightness(progress.toFloat())
}
}