From b7fada7fed697ad1272705215065e725b8826f81 Mon Sep 17 00:00:00 2001 From: Sergiy Kozyr Date: Mon, 20 May 2024 09:32:34 +0300 Subject: [PATCH] Added new setting "Show on the lock screen" MainActivity applies locked screen flags according to the setting --- app/src/main/AndroidManifest.xml | 3 ++- .../flashlight/activities/MainActivity.kt | 19 +++++++++++++++++++ .../flashlight/activities/SettingsActivity.kt | 5 +++++ .../flashlight/helpers/Config.kt | 6 ++++++ .../flashlight/helpers/Constants.kt | 1 + .../flashlight/screens/SettingsScreen.kt | 9 +++++++++ app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-az/strings.xml | 1 + app/src/main/res/values-be/strings.xml | 1 + app/src/main/res/values-ca/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-et/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-iw/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-lt/strings.xml | 1 + app/src/main/res/values-nb-rNO/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 34 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f81d86b2..af9ad957 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,7 +39,8 @@ + android:theme="@style/AppTheme" + android:showOnLockScreen="true" /> = Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(flag) + setTurnScreenOn(flag) + } else { + val windowFlags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or + WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON + + if (flag) + window.addFlags(windowFlags) + else + window.clearFlags(windowFlags) + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt index a83ebfa3..6321eac5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/SettingsActivity.kt @@ -51,6 +51,7 @@ class SettingsActivity : ComponentActivity() { } } val turnFlashlightOnStartupFlow by preferences.turnFlashlightOnFlow.collectAsStateWithLifecycle(preferences.turnFlashlightOn) + val showOnLockedScreenFlow by preferences.showOnLockedScreenFlow.collectAsStateWithLifecycle(preferences.showOnLockedScreen) val forcePortraitModeFlow by preferences.forcePortraitModeFlow.collectAsStateWithLifecycle(preferences.forcePortraitMode) val showBrightDisplayButtonFlow by preferences.brightDisplayFlow.collectAsStateWithLifecycle(preferences.brightDisplay) val showSosButtonFlow by preferences.sosFlow.collectAsStateWithLifecycle(preferences.sos) @@ -67,6 +68,7 @@ class SettingsActivity : ComponentActivity() { }, onSetupLanguagePress = ::launchChangeAppLanguageIntent, turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow, + showOnLockedScreenChecked = showOnLockedScreenFlow, forcePortraitModeChecked = forcePortraitModeFlow, showBrightDisplayButtonChecked = showBrightDisplayButtonFlow, showSosButtonChecked = showSosButtonFlow, @@ -74,6 +76,9 @@ class SettingsActivity : ComponentActivity() { onTurnFlashlightOnStartupPress = { preferences.turnFlashlightOn = it }, + onShowOnLockedScreenPress = { + preferences.showOnLockedScreen = it + }, onForcePortraitModePress = { preferences.forcePortraitMode = it }, diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Config.kt index 911382ee..f2f7004d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Config.kt @@ -33,6 +33,12 @@ class Config(context: Context) : BaseConfig(context) { val turnFlashlightOnFlow = ::turnFlashlightOn.asFlowNonNull() + var showOnLockedScreen: Boolean + get() = prefs.getBoolean(SHOW_ON_LOCKED_SCREEN, false) + set(showOnLockedScreen) = prefs.edit().putBoolean(SHOW_ON_LOCKED_SCREEN, showOnLockedScreen).apply() + + val showOnLockedScreenFlow = ::showOnLockedScreen.asFlowNonNull() + var stroboscopeProgress: Int get() = prefs.getInt(STROBOSCOPE_PROGRESS, 1000) set(stroboscopeProgress) = prefs.edit().putInt(STROBOSCOPE_PROGRESS, stroboscopeProgress).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Constants.kt index 433e626f..895feb3e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Constants.kt @@ -4,6 +4,7 @@ const val BRIGHT_DISPLAY = "bright_display" const val BRIGHT_DISPLAY_COLOR = "bright_display_color" const val STROBOSCOPE = "stroboscope" const val TURN_FLASHLIGHT_ON = "turn_flashlight_on" +const val SHOW_ON_LOCKED_SCREEN = "show_on_locked_screen" const val IS_ENABLED = "is_enabled" const val TOGGLE = "toggle" const val TOGGLE_WIDGET_UI = "toggle_widget_ui" diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt index 392131af..7faeca02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/screens/SettingsScreen.kt @@ -52,6 +52,7 @@ internal fun GeneralSettingsSection( showDisplayLanguage: Boolean, displayLanguage: String, turnFlashlightOnStartupChecked: Boolean, + showOnLockedScreenChecked: Boolean, forcePortraitModeChecked: Boolean, showBrightDisplayButtonChecked: Boolean, showSosButtonChecked: Boolean, @@ -59,6 +60,7 @@ internal fun GeneralSettingsSection( onUseEnglishPress: (Boolean) -> Unit, onSetupLanguagePress: () -> Unit, onTurnFlashlightOnStartupPress: (Boolean) -> Unit, + onShowOnLockedScreenPress: (Boolean) -> Unit, onForcePortraitModePress: (Boolean) -> Unit, onShowBrightDisplayButtonPress: (Boolean) -> Unit, onShowSosButtonPress: (Boolean) -> Unit, @@ -83,6 +85,11 @@ internal fun GeneralSettingsSection( initialValue = turnFlashlightOnStartupChecked, onChange = onTurnFlashlightOnStartupPress ) + SettingsCheckBoxComponent( + label = stringResource(id = R.string.show_on_locked_screen), + initialValue = showOnLockedScreenChecked, + onChange = onShowOnLockedScreenPress + ) SettingsCheckBoxComponent( label = stringResource(id = com.simplemobiletools.commons.R.string.force_portrait_mode), initialValue = forcePortraitModeChecked, @@ -123,6 +130,7 @@ private fun SettingsScreenPreview() { showDisplayLanguage = true, displayLanguage = "English", turnFlashlightOnStartupChecked = false, + showOnLockedScreenChecked = false, forcePortraitModeChecked = true, showBrightDisplayButtonChecked = true, showSosButtonChecked = true, @@ -130,6 +138,7 @@ private fun SettingsScreenPreview() { onUseEnglishPress = {}, onSetupLanguagePress = {}, onTurnFlashlightOnStartupPress = {}, + onShowOnLockedScreenPress = {}, onForcePortraitModePress = {}, onShowBrightDisplayButtonPress = {}, onShowSosButtonPress = {}, diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 2caea613..f8242236 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -11,6 +11,7 @@ Stroboscope إظهار زر SOS قم بتشغيل المصباح عند بدء التشغيل + إظهار التطبيق فوق شاشة القفل