added option to hide seconds

This commit is contained in:
Josia Pietsch 2024-09-11 15:05:05 +02:00
parent 32c3c41266
commit ac2aa49ca1
Signed by: jrpie
GPG key ID: E70B571D66986A2D
7 changed files with 53 additions and 4 deletions

View file

@ -100,7 +100,16 @@ class HomeActivity: UIObject, AppCompatActivity(),
val timeVisible = LauncherPreferences.clock().timeVisible()
var dateFMT = "yyyy-MM-dd"
var timeFMT = "HH:mm:ss"
var timeFMT = "HH:mm"
var period = 100L
if (LauncherPreferences.clock().showSeconds()) {
timeFMT += ":ss"
}
/*
I thought about adding an option to show microseconds as well ( timeFMT += ".SSS" ).
However setting period ot 1L (or even 10L) causes high CPU load,
so that doesn't seem to be a good idea.
*/
if (LauncherPreferences.clock().localized()) {
dateFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, dateFMT)
timeFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, timeFMT)
@ -119,7 +128,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
binding.homeUpperView.isVisible = upperVisible
binding.homeLowerView.isVisible = lowerVisible
clockTimer = fixedRateTimer("clockTimer", true, 0L, 100) {
clockTimer = fixedRateTimer("clockTimer", true, 0L, period) {
this@HomeActivity.runOnUiThread {
if (lowerVisible) {
val t = lowerFormat.format(Date())

View file

@ -36,6 +36,7 @@ import eu.jonahbauer.android.preference.annotations.Preferences;
@Preference(name = "time_visible", type = boolean.class, defaultValue = "true"),
@Preference(name = "flip_date_time", type = boolean.class, defaultValue = "false"),
@Preference(name = "localized", type = boolean.class, defaultValue = "false"),
@Preference(name = "show_seconds", type = boolean.class, defaultValue = "true"),
}),
@PreferenceGroup(name = "display", prefix = "settings_display_", suffix = "_key", value = {
@Preference(name = "screen_timeout_disabled", type = boolean.class, defaultValue = "false"),

View file

@ -2,6 +2,7 @@ package de.jrpie.android.launcher.settings.launcher
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat
import de.jrpie.android.launcher.preferences.LauncherPreferences
@ -16,10 +17,38 @@ import de.jrpie.android.launcher.setDefaultHomeScreen
*/
class SettingsFragmentLauncher : PreferenceFragmentCompat() {
private var sharedPreferencesListener =
SharedPreferences.OnSharedPreferenceChangeListener { _, prefKey ->
if(prefKey?.startsWith("clock.") == true) {
updateVisibility()
}
}
private fun updateVisibility(){
val showSeconds = findPreference<androidx.preference.Preference>(
LauncherPreferences.clock().keys().showSeconds()
)
val timeVisible = LauncherPreferences.clock().timeVisible()
showSeconds?.isVisible = timeVisible
}
override fun onStart() {
super.onStart()
LauncherPreferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(sharedPreferencesListener)
}
override fun onPause() {
LauncherPreferences.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(sharedPreferencesListener)
super.onPause()
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
val selectWallpaper = findPreference<androidx.preference.Preference>(LauncherPreferences.theme().keys().wallpaper())
val selectWallpaper = findPreference<androidx.preference.Preference>(
LauncherPreferences.theme().keys().wallpaper()
)
selectWallpaper?.setOnPreferenceClickListener {
// https://github.com/LineageOS/android_packages_apps_Trebuchet/blob/6caab89b21b2b91f0a439e1fd8c4510dcb255819/src/com/android/launcher3/views/OptionsPopupView.java#L271
val intent = Intent(Intent.ACTION_SET_WALLPAPER)
@ -28,10 +57,13 @@ class SettingsFragmentLauncher : PreferenceFragmentCompat() {
startActivity(intent)
true
}
val chooseHomeScreen = findPreference<androidx.preference.Preference>(LauncherPreferences.general().keys().chooseHomeScreen())
val chooseHomeScreen = findPreference<androidx.preference.Preference>(
LauncherPreferences.general().keys().chooseHomeScreen()
)
chooseHomeScreen?.setOnPreferenceClickListener {
setDefaultHomeScreen(requireContext(), checkDefault = false)
true
}
updateVisibility()
}
}

View file

@ -139,4 +139,5 @@
<string name="ic_menu_alt">Mehr Optionen</string>
<string name="list_other_expand_notifications_panel">Benachrichtigungen</string>
<string name="alert_cant_expand_notifications_panel">Fehler: Die Funktion \"Benachrichtigungen\" wird von deinem Gerät leider nicht unterstützt.</string>
<string name="settings_clock_show_seconds">Sekunden anzeigen</string>
</resources>

View file

@ -77,6 +77,7 @@
-->
<string name="settings_clock_font_key" translatable="false">clock.font</string>
<string name="settings_clock_time_visible_key" translatable="false">clock.time_visible</string>
<string name="settings_clock_show_seconds_key" translatable="false">clock.show_seconds</string>
<string name="settings_clock_date_visible_key" translatable="false">clock.date_visible</string>
<string name="settings_clock_localized_key" translatable="false">clock.date_localized</string>
<string name="settings_clock_flip_date_time_key" translatable="false">clock.date_time_flip</string>

View file

@ -93,6 +93,7 @@
<string name="settings_clock_time_visible">Show time</string>
<string name="settings_clock_date_visible">Show date</string>
<string name="settings_clock_localized">Use localized date format</string>
<string name="settings_clock_show_seconds">Show seconds</string>
<string name="settings_clock_flip_date_time">Flip date and time</string>
<string name="settings_theme_wallpaper">Choose a wallpaper</string>

View file

@ -61,6 +61,10 @@
android:key="@string/settings_clock_time_visible_key"
android:defaultValue="true"
android:title="@string/settings_clock_time_visible" />
<SwitchPreference
android:key="@string/settings_clock_show_seconds_key"
android:defaultValue="true"
android:title="@string/settings_clock_show_seconds" />
<SwitchPreference
android:key="@string/settings_clock_date_visible_key"
android:defaultValue="true"