Added new setting "Show on the lock screen"

MainActivity applies locked screen flags according to the setting
This commit is contained in:
Sergiy Kozyr 2024-05-20 09:32:34 +03:00 committed by S. Kozyr
parent ddf576aa04
commit b7fada7fed
No known key found for this signature in database
GPG Key ID: C622E5563CAC205D
34 changed files with 70 additions and 1 deletions

View File

@ -39,7 +39,8 @@
<activity
android:name=".activities.MainActivity"
android:theme="@style/AppTheme" />
android:theme="@style/AppTheme"
android:showOnLockScreen="true" />
<activity
android:name=".activities.WidgetTorchConfigureActivity"

View File

@ -11,7 +11,9 @@ import android.content.pm.PackageManager
import android.content.pm.ShortcutInfo
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
@ -283,6 +285,7 @@ class MainActivity : ComponentActivity() {
requestedOrientation = if (preferences.forcePortraitMode) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_SENSOR
invalidateOptionsMenu()
applyShowOnLockedScreen(preferences.showOnLockedScreen)
checkShortcuts()
}
@ -294,6 +297,7 @@ class MainActivity : ComponentActivity() {
viewModel.hideTimer()
(getSystemService(Context.ALARM_SERVICE) as AlarmManager).cancel(getShutDownPendingIntent())
}
applyShowOnLockedScreen(preferences.showOnLockedScreen)
}
private fun launchSettings() {
@ -564,4 +568,19 @@ class MainActivity : ComponentActivity() {
_stroboscopeActive.value = camera.toggleStroboscope()
}
}
private fun applyShowOnLockedScreen(flag: Boolean) {
if (Build.VERSION.SDK_INT >= 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)
}
}
}

View File

@ -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
},

View File

@ -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()

View File

@ -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"

View File

@ -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 = {},

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">إظهار زر SOS</string>
<string name="turn_flashlight_on">قم بتشغيل المصباح عند بدء التشغيل</string>
<string name="show_on_locked_screen">إظهار التطبيق فوق شاشة القفل</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Show an SOS button</string>
<string name="turn_flashlight_on">Başlanğıcda fənəri aç</string>
<string name="show_on_locked_screen">Kilid ekranında göstərin</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Паказваць кнопку СОС</string>
<string name="turn_flashlight_on">Уключаць ліхтарык пры запуску</string>
<string name="show_on_locked_screen">Паказваць на экране блакіроўкі</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostra un botó de SOS</string>
<string name="turn_flashlight_on">Activa la llanterna a l\'inici</string>
<string name="show_on_locked_screen">Mostra en la pantalla de bloqueig</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Zobrazit tlačítko SOS</string>
<string name="turn_flashlight_on">Zapnout svítilnu po spuštění</string>
<string name="show_on_locked_screen">Zobrazit na uzamčené obrazovce</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Eine SOS-Schaltfläche zeigen</string>
<string name="turn_flashlight_on">Taschenlampe beim Start einschalten</string>
<string name="show_on_locked_screen">Auf dem Sperrbildschirm anzeigen</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Προβολή κουμπιού SOS</string>
<string name="turn_flashlight_on">Άνοιγμα του φακού κατά την εκκίνηση</string>
<string name="show_on_locked_screen">Εμφάνιση στην Οθόνη Κλειδώματος</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostrar un botón de SOS</string>
<string name="turn_flashlight_on">Encender la linterna al inicio</string>
<string name="show_on_locked_screen">Mostrar en la pantalla de bloqueo</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Näita SOS-nuppu</string>
<string name="turn_flashlight_on">Rakenduse käivitamisel lülita taskulamp sisse</string>
<string name="show_on_locked_screen">Kuva lukustusekraanil</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Näytä SOS-painike</string>
<string name="turn_flashlight_on">Kytke taskulamppu päälle käynnistyksen yhteydessä</string>
<string name="show_on_locked_screen">Näytä lukitusnäytöllä</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Afficher un bouton « S.O.S. »</string>
<string name="turn_flashlight_on">Allumer la lampe de poche au démarrage</string>
<string name="show_on_locked_screen">Afficher sur l\'écran de verrouillage</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">SOS gomb megjelenítése</string>
<string name="turn_flashlight_on">Zseblámpa bekapcsolása indításkor</string>
<string name="show_on_locked_screen">Megjelenítés a zárolt képernyőn</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostra un pulsante SOS</string>
<string name="turn_flashlight_on">Accendi la torcia all\'avvio</string>
<string name="show_on_locked_screen">Mostra sulla schermata di blocco</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">הצג כפתור SOS</string>
<string name="turn_flashlight_on">הדלק את הפנס בעת ההפעלה</string>
<string name="show_on_locked_screen">הצג במסך הנעילה</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">SOSボタンを表示</string>
<string name="turn_flashlight_on">起動時にフラッシュライトを点灯</string>
<string name="show_on_locked_screen">ロック画面に表示</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Rodyti SOS mygtuką</string>
<string name="turn_flashlight_on">Įjungti žibintuvėlį paleidus programėlę</string>
<string name="show_on_locked_screen">Rodyti užrakinimo ekrane</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Vis SOS-knapp</string>
<string name="turn_flashlight_on">Skru på lommelykt ved oppstart</string>
<string name="show_on_locked_screen">Vis på låseskjerm</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Knop voor SOS-noodsignaal tonen</string>
<string name="turn_flashlight_on">Zaklamp bij starten aanzetten</string>
<string name="show_on_locked_screen">Toon op vergrendelscherm</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboskop</string>
<string name="show_sos">Pokazuj przycisk SOS</string>
<string name="turn_flashlight_on">Włączaj latarkę przy uruchomieniu</string>
<string name="show_on_locked_screen">Pokazuj na ekranie blokady</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostrar o botão de SOS</string>
<string name="turn_flashlight_on">Ligar a lanterna ao iniciar o app</string>
<string name="show_on_locked_screen">Mostrar na tela de bloqueio</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostrar botão de SOS</string>
<string name="turn_flashlight_on">Acender a lanterna ao iniciar</string>
<string name="show_on_locked_screen">Mostrar na tela de bloqueio</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Mostrar botão de SOS</string>
<string name="turn_flashlight_on">Acender a lanterna ao iniciar</string>
<string name="show_on_locked_screen">Mostrar na tela de bloqueio</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Afișați un buton SOS</string>
<string name="turn_flashlight_on">Porniți lanterna la pornire</string>
<string name="show_on_locked_screen">Arată pe ecranul de blocare</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Показать кнопку SOS</string>
<string name="turn_flashlight_on">Включать фонарик при запуске</string>
<string name="show_on_locked_screen">Показывать на экране блокировки</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Zobraziť tlačidlo SOS</string>
<string name="turn_flashlight_on">Aktivovať baterku po spustení</string>
<string name="show_on_locked_screen">Zobraziť na uzamknutej obrazovke</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">SOS düğmesini göster</string>
<string name="turn_flashlight_on">Başlangıçta feneri aç</string>
<string name="show_on_locked_screen">Kilit ekranında göster</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Показати кнопку SOS</string>
<string name="turn_flashlight_on">Вмикати ліхтарик при запуску</string>
<string name="show_on_locked_screen">Показувати на заблокованому екрані</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res

View File

@ -11,6 +11,7 @@
<string name="stroboscope">Stroboscope</string>
<string name="show_sos">Show an SOS button</string>
<string name="turn_flashlight_on">Turn flashlight on at startup</string>
<string name="show_on_locked_screen">Show on the lock screen</string>
<!--
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res