mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
added option to hide seconds
This commit is contained in:
parent
32c3c41266
commit
ac2aa49ca1
7 changed files with 53 additions and 4 deletions
|
@ -100,7 +100,16 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
val timeVisible = LauncherPreferences.clock().timeVisible()
|
val timeVisible = LauncherPreferences.clock().timeVisible()
|
||||||
|
|
||||||
var dateFMT = "yyyy-MM-dd"
|
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()) {
|
if (LauncherPreferences.clock().localized()) {
|
||||||
dateFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, dateFMT)
|
dateFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, dateFMT)
|
||||||
timeFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, timeFMT)
|
timeFMT = android.text.format.DateFormat.getBestDateTimePattern(locale, timeFMT)
|
||||||
|
@ -119,7 +128,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
binding.homeUpperView.isVisible = upperVisible
|
binding.homeUpperView.isVisible = upperVisible
|
||||||
binding.homeLowerView.isVisible = lowerVisible
|
binding.homeLowerView.isVisible = lowerVisible
|
||||||
|
|
||||||
clockTimer = fixedRateTimer("clockTimer", true, 0L, 100) {
|
clockTimer = fixedRateTimer("clockTimer", true, 0L, period) {
|
||||||
this@HomeActivity.runOnUiThread {
|
this@HomeActivity.runOnUiThread {
|
||||||
if (lowerVisible) {
|
if (lowerVisible) {
|
||||||
val t = lowerFormat.format(Date())
|
val t = lowerFormat.format(Date())
|
||||||
|
|
|
@ -36,6 +36,7 @@ import eu.jonahbauer.android.preference.annotations.Preferences;
|
||||||
@Preference(name = "time_visible", type = boolean.class, defaultValue = "true"),
|
@Preference(name = "time_visible", type = boolean.class, defaultValue = "true"),
|
||||||
@Preference(name = "flip_date_time", type = boolean.class, defaultValue = "false"),
|
@Preference(name = "flip_date_time", type = boolean.class, defaultValue = "false"),
|
||||||
@Preference(name = "localized", 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 = {
|
@PreferenceGroup(name = "display", prefix = "settings_display_", suffix = "_key", value = {
|
||||||
@Preference(name = "screen_timeout_disabled", type = boolean.class, defaultValue = "false"),
|
@Preference(name = "screen_timeout_disabled", type = boolean.class, defaultValue = "false"),
|
||||||
|
|
|
@ -2,6 +2,7 @@ package de.jrpie.android.launcher.settings.launcher
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
|
@ -16,10 +17,38 @@ import de.jrpie.android.launcher.setDefaultHomeScreen
|
||||||
*/
|
*/
|
||||||
class SettingsFragmentLauncher : PreferenceFragmentCompat() {
|
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?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.preferences, rootKey)
|
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 {
|
selectWallpaper?.setOnPreferenceClickListener {
|
||||||
// https://github.com/LineageOS/android_packages_apps_Trebuchet/blob/6caab89b21b2b91f0a439e1fd8c4510dcb255819/src/com/android/launcher3/views/OptionsPopupView.java#L271
|
// 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)
|
val intent = Intent(Intent.ACTION_SET_WALLPAPER)
|
||||||
|
@ -28,10 +57,13 @@ class SettingsFragmentLauncher : PreferenceFragmentCompat() {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
val chooseHomeScreen = findPreference<androidx.preference.Preference>(LauncherPreferences.general().keys().chooseHomeScreen())
|
val chooseHomeScreen = findPreference<androidx.preference.Preference>(
|
||||||
|
LauncherPreferences.general().keys().chooseHomeScreen()
|
||||||
|
)
|
||||||
chooseHomeScreen?.setOnPreferenceClickListener {
|
chooseHomeScreen?.setOnPreferenceClickListener {
|
||||||
setDefaultHomeScreen(requireContext(), checkDefault = false)
|
setDefaultHomeScreen(requireContext(), checkDefault = false)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
updateVisibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,4 +139,5 @@
|
||||||
<string name="ic_menu_alt">Mehr Optionen</string>
|
<string name="ic_menu_alt">Mehr Optionen</string>
|
||||||
<string name="list_other_expand_notifications_panel">Benachrichtigungen</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="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>
|
</resources>
|
||||||
|
|
|
@ -77,6 +77,7 @@
|
||||||
-->
|
-->
|
||||||
<string name="settings_clock_font_key" translatable="false">clock.font</string>
|
<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_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_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_localized_key" translatable="false">clock.date_localized</string>
|
||||||
<string name="settings_clock_flip_date_time_key" translatable="false">clock.date_time_flip</string>
|
<string name="settings_clock_flip_date_time_key" translatable="false">clock.date_time_flip</string>
|
||||||
|
|
|
@ -93,6 +93,7 @@
|
||||||
<string name="settings_clock_time_visible">Show time</string>
|
<string name="settings_clock_time_visible">Show time</string>
|
||||||
<string name="settings_clock_date_visible">Show date</string>
|
<string name="settings_clock_date_visible">Show date</string>
|
||||||
<string name="settings_clock_localized">Use localized date format</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_clock_flip_date_time">Flip date and time</string>
|
||||||
|
|
||||||
<string name="settings_theme_wallpaper">Choose a wallpaper</string>
|
<string name="settings_theme_wallpaper">Choose a wallpaper</string>
|
||||||
|
|
|
@ -61,6 +61,10 @@
|
||||||
android:key="@string/settings_clock_time_visible_key"
|
android:key="@string/settings_clock_time_visible_key"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:title="@string/settings_clock_time_visible" />
|
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
|
<SwitchPreference
|
||||||
android:key="@string/settings_clock_date_visible_key"
|
android:key="@string/settings_clock_date_visible_key"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
|
Loading…
Add table
Reference in a new issue