From 4f8d4f0d2bcf30c35ed24a6d3d4a93ae9c34de47 Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Thu, 23 Apr 2015 20:28:58 -0400 Subject: [PATCH] Settings: Ensure zen day-of-week formats use current locale. Don't share SimpleDateFormat instances per-process, convert to per-instance to ensure we're always using the current locale. Updated version of: https://android-review.googlesource.com/#/c/147246/ Change-Id: Id464c35035c1de0a7894e5e19b57934f77df9769 --- .../android/settings/notification/ZenModeAutomationSettings.java | 5 +++-- .../settings/notification/ZenModeScheduleDaysSelection.java | 5 +++-- .../android/settings/notification/ZenModeScheduleRuleSettings.java | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java index 6636b33fb0..dab0a0d01e 100644 --- a/src/com/android/settings/notification/ZenModeAutomationSettings.java +++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java @@ -48,10 +48,11 @@ import java.util.List; import java.util.TreeSet; public class ZenModeAutomationSettings extends ZenModeSettingsBase { - private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEE"); static final Config CONFIG = getConditionProviderConfig(); + // per-instance to ensure we're always using the current locale + private final SimpleDateFormat mDayFormat = new SimpleDateFormat("EEE"); private final Calendar mCalendar = Calendar.getInstance(); private ServiceListing mServiceListing; @@ -218,7 +219,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { private String dayString(int day) { mCalendar.set(Calendar.DAY_OF_WEEK, day); - return DAY_FORMAT.format(mCalendar.getTime()); + return mDayFormat.format(mCalendar.getTime()); } private static Config getConditionProviderConfig() { diff --git a/src/com/android/settings/notification/ZenModeScheduleDaysSelection.java b/src/com/android/settings/notification/ZenModeScheduleDaysSelection.java index 6d11ffb1ea..3e88046e41 100644 --- a/src/com/android/settings/notification/ZenModeScheduleDaysSelection.java +++ b/src/com/android/settings/notification/ZenModeScheduleDaysSelection.java @@ -41,8 +41,9 @@ public class ZenModeScheduleDaysSelection extends ScrollView { Calendar.FRIDAY, Calendar.SATURDAY, }; - private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEEE"); + // per-instance to ensure we're always using the current locale + private final SimpleDateFormat mDayFormat = new SimpleDateFormat("EEEE"); private final SparseBooleanArray mDays = new SparseBooleanArray(); private final LinearLayout mLayout; @@ -66,7 +67,7 @@ public class ZenModeScheduleDaysSelection extends ScrollView { final CheckBox checkBox = (CheckBox) inflater.inflate(R.layout.zen_schedule_rule_day, this, false); c.set(Calendar.DAY_OF_WEEK, day); - checkBox.setText(DAY_FORMAT.format(c.getTime())); + checkBox.setText(mDayFormat.format(c.getTime())); checkBox.setChecked(mDays.get(day)); checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override diff --git a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java index f7015d31ca..fef3175261 100644 --- a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java +++ b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java @@ -50,10 +50,11 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase { private static final String KEY_START_TIME = "start_time"; private static final String KEY_END_TIME = "end_time"; - private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEE"); - public static final String ACTION = Settings.ACTION_ZEN_MODE_SCHEDULE_RULE_SETTINGS; + // per-instance to ensure we're always using the current locale + private final SimpleDateFormat mDayFormat = new SimpleDateFormat("EEE"); + private Preference mDays; private TimePickerPreference mStart; private TimePickerPreference mEnd; @@ -147,7 +148,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase { if (sb.length() > 0) { sb.append(mContext.getString(R.string.summary_divider_text)); } - sb.append(DAY_FORMAT.format(c.getTime())); + sb.append(mDayFormat.format(c.getTime())); break; } } -- 2.11.0