mirror of
https://github.com/readest/readest.git
synced 2026-04-29 12:00:49 +00:00
This commit is contained in:
parent
b808fc5954
commit
5a3114de48
2 changed files with 15 additions and 8 deletions
|
|
@ -457,12 +457,19 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
|
|||
fun get_screen_brightness(invoke: Invoke) {
|
||||
val ret = JSObject()
|
||||
try {
|
||||
val brightness = Settings.System.getInt(
|
||||
activity.contentResolver,
|
||||
Settings.System.SCREEN_BRIGHTNESS
|
||||
)
|
||||
val normalizedBrightness = brightness / 255.0
|
||||
ret.put("brightness", normalizedBrightness)
|
||||
val window = activity.window
|
||||
val layoutParams = window.attributes
|
||||
val brightness = layoutParams.screenBrightness
|
||||
|
||||
if (brightness >= 0.0f) {
|
||||
ret.put("brightness", brightness.toDouble())
|
||||
} else {
|
||||
val systemBrightness = Settings.System.getInt(
|
||||
activity.contentResolver,
|
||||
Settings.System.SCREEN_BRIGHTNESS
|
||||
)
|
||||
ret.put("brightness", systemBrightness / 255.0)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ret.put("error", e.message)
|
||||
ret.put("brightness", -1.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue