feat(ui): allow phone to be locked while still showing AOD, bump minSDK to 27

This commit is contained in:
Nishant Mishra
2025-10-21 09:26:05 +05:30
parent 37f5fb433e
commit b16aeb499d
2 changed files with 15 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ android {
defaultConfig {
applicationId = "org.nsh07.pomodoro"
minSdk = 26
minSdk = 27
targetSdk = 36
versionCode = 13
versionName = "1.5.0"

View File

@@ -8,6 +8,8 @@
package org.nsh07.pomodoro.ui
import android.app.Activity
import android.view.WindowManager
import androidx.activity.compose.LocalActivity
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.animation.SharedTransitionScope
import androidx.compose.animation.animateColorAsState
@@ -61,19 +63,29 @@ fun SharedTransitionScope.AlwaysOnDisplay(
var sharedElementTransitionComplete by remember { mutableStateOf(false) }
val view = LocalView.current
val activity = LocalActivity.current
val window = remember { (view.context as Activity).window }
val insetsController = remember { WindowCompat.getInsetsController(window, view) }
DisposableEffect(Unit) {
view.keepScreenOn = true
window.addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)
activity?.setShowWhenLocked(true)
insetsController.apply {
hide(WindowInsetsCompat.Type.statusBars())
hide(WindowInsetsCompat.Type.navigationBars())
systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
onDispose {
view.keepScreenOn = false
window.clearFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)
activity?.setShowWhenLocked(false)
insetsController.apply {
show(WindowInsetsCompat.Type.statusBars())
show(WindowInsetsCompat.Type.navigationBars())