From db389943253d58fda7c81c09442a35204edd918b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Thu, 20 Aug 2015 22:32:14 +0200 Subject: [PATCH 1/3] Time picker should use system 12/24h format ...if setting TIMESTAMPS_24H is not set. --- .../java/com/moez/QKSMS/ui/settings/SettingsFragment.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index c105fad7..cd1c403e 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -22,6 +22,7 @@ import android.preference.Preference; import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; +import android.text.format.DateFormat; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -732,8 +733,8 @@ public class SettingsFragment extends PreferenceFragment implements int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); - - return new TimePickerDialog(getActivity(), this, hour, minute, false); + boolean isUsing24HourTime = mPrefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(getActivity())); + return new TimePickerDialog(getActivity(), this, hour, minute, isUsing24HourTime); } public void onTimeSet(TimePicker view, int hourOfDay, int minute) { From 61ab77fe4b07f7f636a3361c23913ad899422da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Thu, 20 Aug 2015 22:50:30 +0200 Subject: [PATCH 2/3] Timestamps should follow system 12/24h format ...unless the setting TIMESTAMPS_24H is set. --- .../main/java/com/moez/QKSMS/common/utils/DateFormatter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java index 7826be4c..4eafa979 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java @@ -3,6 +3,7 @@ package com.moez.QKSMS.common.utils; import android.content.Context; import android.content.SharedPreferences; import android.text.format.DateUtils; +import android.text.format.DateFormat; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; @@ -54,7 +55,7 @@ public abstract class DateFormatter { public static SimpleDateFormat accountFor24HourTime(Context context, SimpleDateFormat input) { //pass in 12 hour time. If needed, change to 24 hr. SharedPreferences prefs = MainActivity.getPrefs(context); - boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, false); + boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(getActivity())); if (isUsing24HourTime) { return new SimpleDateFormat(input.toPattern().replace('h', 'H').replaceAll(" a", "")); From 52fb5f9fb0da9fa9ebb0715959cb7cd31ea9a0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Thu, 20 Aug 2015 23:09:10 +0200 Subject: [PATCH 3/3] Replace getActivity() with context After some research, I found out that DateFormat.is24HourFormat actually accepts Context. --- .../main/java/com/moez/QKSMS/common/utils/DateFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java index 4eafa979..16700b04 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/DateFormatter.java @@ -55,7 +55,7 @@ public abstract class DateFormatter { public static SimpleDateFormat accountFor24HourTime(Context context, SimpleDateFormat input) { //pass in 12 hour time. If needed, change to 24 hr. SharedPreferences prefs = MainActivity.getPrefs(context); - boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(getActivity())); + boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(context)); if (isUsing24HourTime) { return new SimpleDateFormat(input.toPattern().replace('h', 'H').replaceAll(" a", ""));