From 6e4bc72cd8e3c587ae994555d4a34e80766752bc Mon Sep 17 00:00:00 2001 From: Klaus-Hendrik Wolf Date: Thu, 14 Mar 2024 16:54:17 +0100 Subject: [PATCH 1/2] Fix #225 24-hour binary clock Obeys the users wish to display a 24h binary clock. --- .../java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt | 3 +++ .../java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt index 3e393f8e..c8edfef7 100644 --- a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt +++ b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt @@ -89,4 +89,7 @@ class BinaryClockView(context: Context, attrs: AttributeSet) : setMeasuredDimension(w, h) } + fun setTo24h(use24h: Boolean = true) { + is24Hour = use24h + } } diff --git a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt index cd6b2fa0..8ed65f00 100644 --- a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt +++ b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt @@ -206,6 +206,10 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener { homeFragmentContent.homeFragmentTime.setOnClickListener(launchShowAlarms) homeFragmentContent.homeFragmentAnalogTime.setOnClickListener(launchShowAlarms) homeFragmentContent.homeFragmentBinTime.setOnClickListener(launchShowAlarms) + homeFragmentContent.homeFragmentBinTime.setTo24h( + context?.getSharedPreferences(getString(R.string.prefs_settings), Context.MODE_PRIVATE) + ?.getInt(getString(R.string.prefs_settings_key_time_format), 0) == 1 + ) homeFragmentContent.homeFragmentDate.setOnClickListener { try { From bec2c9c1ed1c9963599976ac7e28908adb1fbf2b Mon Sep 17 00:00:00 2001 From: Joshua Kuestersteffen Date: Sat, 23 Mar 2024 12:41:26 -0500 Subject: [PATCH 2/2] Update binary clock to change format according to system settings too --- .../slimlauncher/ui/main/BinaryClockView.kt | 16 ++++++++++++++-- .../sduduzog/slimlauncher/ui/main/ClockView.kt | 2 +- .../slimlauncher/ui/main/HomeFragment.kt | 4 ---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt index c8edfef7..34e589e7 100644 --- a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt +++ b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/BinaryClockView.kt @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.graphics.RectF +import android.text.format.DateFormat import android.util.AttributeSet import com.sduduzog.slimlauncher.R import java.util.Calendar @@ -89,7 +90,18 @@ class BinaryClockView(context: Context, attrs: AttributeSet) : setMeasuredDimension(w, h) } - fun setTo24h(use24h: Boolean = true) { - is24Hour = use24h + + override fun updateClock() { + super.updateClock() + + val timeFormat = context.getSharedPreferences( + context.getString(R.string.prefs_settings), + Context.MODE_PRIVATE + )?.getInt(context.getString(R.string.prefs_settings_key_time_format), 0) + is24Hour = when (timeFormat) { + 1 -> true + 2 -> false + else -> DateFormat.is24HourFormat(context) + } } } diff --git a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/ClockView.kt b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/ClockView.kt index 936cbb57..062d973e 100644 --- a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/ClockView.kt +++ b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/ClockView.kt @@ -24,7 +24,7 @@ abstract class ClockView(context: Context, attrs: AttributeSet) : View(context, return paint } - fun updateClock() { + open fun updateClock() { requestLayout() invalidate() } diff --git a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt index 8ed65f00..cd6b2fa0 100644 --- a/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt +++ b/app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt @@ -206,10 +206,6 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener { homeFragmentContent.homeFragmentTime.setOnClickListener(launchShowAlarms) homeFragmentContent.homeFragmentAnalogTime.setOnClickListener(launchShowAlarms) homeFragmentContent.homeFragmentBinTime.setOnClickListener(launchShowAlarms) - homeFragmentContent.homeFragmentBinTime.setTo24h( - context?.getSharedPreferences(getString(R.string.prefs_settings), Context.MODE_PRIVATE) - ?.getInt(getString(R.string.prefs_settings_key_time_format), 0) == 1 - ) homeFragmentContent.homeFragmentDate.setOnClickListener { try {