feat:亮度实时调节
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package io.legado.app.ui.book.read
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import androidx.activity.compose.LocalActivity
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.SizeTransform
|
||||
@@ -3004,6 +3007,7 @@ private fun BrightnessBar(
|
||||
buttonGlassEnabled: Boolean = false,
|
||||
glassThumbEnabled: Boolean = false,
|
||||
) {
|
||||
val activity = LocalActivity.current
|
||||
var sliderValue by remember { mutableFloatStateOf(brightness.toFloat()) }
|
||||
var sliderDragging by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -3016,6 +3020,23 @@ private fun BrightnessBar(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSliderValue(value: Float) {
|
||||
if (brightnessAuto) return
|
||||
sliderDragging = true
|
||||
sliderValue = value.coerceIn(0f, 100f)
|
||||
val target = value.roundToInt().coerceIn(0, 100)
|
||||
|
||||
//直接先改亮度,如果在这里onBrightnessChange,会ANR
|
||||
activity?.let { act ->
|
||||
val lp = act.window.attributes
|
||||
val targetBrightness = target / 100f
|
||||
if (lp.screenBrightness != targetBrightness) {
|
||||
lp.screenBrightness = targetBrightness
|
||||
act.window.attributes = lp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun commitSliderValue(value: Float) {
|
||||
val target = value.roundToInt().coerceIn(0, 100)
|
||||
sliderDragging = false
|
||||
@@ -3052,8 +3073,7 @@ private fun BrightnessBar(
|
||||
value = sliderValue.coerceIn(0f, 100f),
|
||||
onValueChange = { value ->
|
||||
if (brightnessAuto) return@AppVerticalSlider
|
||||
sliderDragging = true
|
||||
sliderValue = value.coerceIn(0f, 100f)
|
||||
updateSliderValue(value)
|
||||
},
|
||||
onValueChangeFinished = {
|
||||
commitSliderValue(sliderValue)
|
||||
@@ -3095,8 +3115,7 @@ private fun BrightnessBar(
|
||||
value = sliderValue.coerceIn(0f, 100f),
|
||||
onValueChange = { value ->
|
||||
if (brightnessAuto) return@ReadMenuSlider
|
||||
sliderDragging = true
|
||||
sliderValue = value.coerceIn(0f, 100f)
|
||||
updateSliderValue(value)
|
||||
},
|
||||
onValueChangeFinished = {
|
||||
commitSliderValue(sliderValue)
|
||||
|
||||
Reference in New Issue
Block a user