Skip to content

Commit b16aeb4

Browse files
committed
feat(ui): allow phone to be locked while still showing AOD, bump minSDK to 27
1 parent 37f5fb4 commit b16aeb4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131

3232
defaultConfig {
3333
applicationId = "org.nsh07.pomodoro"
34-
minSdk = 26
34+
minSdk = 27
3535
targetSdk = 36
3636
versionCode = 13
3737
versionName = "1.5.0"

app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
package org.nsh07.pomodoro.ui
99

1010
import android.app.Activity
11+
import android.view.WindowManager
12+
import androidx.activity.compose.LocalActivity
1113
import androidx.compose.animation.SharedTransitionLayout
1214
import androidx.compose.animation.SharedTransitionScope
1315
import androidx.compose.animation.animateColorAsState
@@ -61,19 +63,29 @@ fun SharedTransitionScope.AlwaysOnDisplay(
6163
var sharedElementTransitionComplete by remember { mutableStateOf(false) }
6264

6365
val view = LocalView.current
66+
val activity = LocalActivity.current
6467
val window = remember { (view.context as Activity).window }
6568
val insetsController = remember { WindowCompat.getInsetsController(window, view) }
6669

6770
DisposableEffect(Unit) {
68-
view.keepScreenOn = true
71+
window.addFlags(
72+
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
73+
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
74+
)
75+
activity?.setShowWhenLocked(true)
6976
insetsController.apply {
7077
hide(WindowInsetsCompat.Type.statusBars())
7178
hide(WindowInsetsCompat.Type.navigationBars())
7279
systemBarsBehavior =
7380
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
7481
}
82+
7583
onDispose {
76-
view.keepScreenOn = false
84+
window.clearFlags(
85+
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
86+
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
87+
)
88+
activity?.setShowWhenLocked(false)
7789
insetsController.apply {
7890
show(WindowInsetsCompat.Type.statusBars())
7991
show(WindowInsetsCompat.Type.navigationBars())

0 commit comments

Comments
 (0)