From b16aeb499d8e4f7adb3ab2cb2264f6a766cd0e02 Mon Sep 17 00:00:00 2001 From: Nishant Mishra Date: Tue, 21 Oct 2025 09:26:05 +0530 Subject: [PATCH] feat(ui): allow phone to be locked while still showing AOD, bump minSDK to 27 --- app/build.gradle.kts | 2 +- .../org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e9f14c9..107cf83 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -31,7 +31,7 @@ android { defaultConfig { applicationId = "org.nsh07.pomodoro" - minSdk = 26 + minSdk = 27 targetSdk = 36 versionCode = 13 versionName = "1.5.0" diff --git a/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt b/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt index 8009ecb..3234814 100644 --- a/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt +++ b/app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt @@ -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())