Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new setting "Show on the lock screen" #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -294,6 +297,7 @@ class MainActivity : ComponentActivity() {
viewModel.hideTimer()
(getSystemService(Context.ALARM_SERVICE) as AlarmManager).cancel(getShutDownPendingIntent())
}
applyShowOnLockedScreen(preferences.showOnLockedScreen)
}

private fun launchSettings() {
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -67,13 +68,17 @@ class SettingsActivity : ComponentActivity() {
},
onSetupLanguagePress = ::launchChangeAppLanguageIntent,
turnFlashlightOnStartupChecked = turnFlashlightOnStartupFlow,
showOnLockedScreenChecked = showOnLockedScreenFlow,
forcePortraitModeChecked = forcePortraitModeFlow,
showBrightDisplayButtonChecked = showBrightDisplayButtonFlow,
showSosButtonChecked = showSosButtonFlow,
showStroboscopeButtonChecked = showStroboscopeButtonFlow,
onTurnFlashlightOnStartupPress = {
preferences.turnFlashlightOn = it
},
onShowOnLockedScreenPress = {
preferences.showOnLockedScreen = it
},
onForcePortraitModePress = {
preferences.forcePortraitMode = it
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ internal fun GeneralSettingsSection(
showDisplayLanguage: Boolean,
displayLanguage: String,
turnFlashlightOnStartupChecked: Boolean,
showOnLockedScreenChecked: Boolean,
forcePortraitModeChecked: Boolean,
showBrightDisplayButtonChecked: Boolean,
showSosButtonChecked: Boolean,
showStroboscopeButtonChecked: Boolean,
onUseEnglishPress: (Boolean) -> Unit,
onSetupLanguagePress: () -> Unit,
onTurnFlashlightOnStartupPress: (Boolean) -> Unit,
onShowOnLockedScreenPress: (Boolean) -> Unit,
onForcePortraitModePress: (Boolean) -> Unit,
onShowBrightDisplayButtonPress: (Boolean) -> Unit,
onShowSosButtonPress: (Boolean) -> Unit,
Expand All @@ -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,
Expand Down Expand Up @@ -123,13 +130,15 @@ private fun SettingsScreenPreview() {
showDisplayLanguage = true,
displayLanguage = "English",
turnFlashlightOnStartupChecked = false,
showOnLockedScreenChecked = false,
forcePortraitModeChecked = true,
showBrightDisplayButtonChecked = true,
showSosButtonChecked = true,
showStroboscopeButtonChecked = true,
onUseEnglishPress = {},
onSetupLanguagePress = {},
onTurnFlashlightOnStartupPress = {},
onShowOnLockedScreenPress = {},
onForcePortraitModePress = {},
onShowBrightDisplayButtonPress = {},
onShowSosButtonPress = {},
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-lt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rPT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down