From 188ca778702938d87313592175a3c2ff86bd3218 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 11 Jun 2009 18:16:15 -0700 Subject: [PATCH] Make the Settings side of the date format settings more locale-aware. Remove the two formats that have a spelled-out month, since applications using this setting are trying to format numeric dates. Do not forcibly set the setting the first time you go into Date & Time -- let the setting remain null if it was null before. Add a choice corresponding to null to the list of format options. It will look like "Normal (12-31-2009)" in the list, and will cause the system to use whatever numeric format the locale calls for. For the other choices, feed them to the locale-aware formatter so they will appear with the punctuation that the locale calls for. --- res/values/arrays.xml | 14 ++++--------- res/values/strings.xml | 4 ++++ .../android/settings/DateTimeSettings.java | 20 ++++++++++++++----- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 4a60c36e193..06bf7879b1f 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -39,18 +39,12 @@ All - - - - + + + + MM-dd-yyyy - dd-MM-yyyy - - MMM d, yyyy - - d-MMM-yyyy - yyyy-MM-dd diff --git a/res/values/strings.xml b/res/values/strings.xml index 3b91ef66fbd..d2ca51b57f8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -243,6 +243,10 @@ MM/dd/yyyy + + Normal (%s) + Preview: diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java index d6e85c4e537..5b38651ce85 100644 --- a/src/com/android/settings/DateTimeSettings.java +++ b/src/com/android/settings/DateTimeSettings.java @@ -87,19 +87,25 @@ public class DateTimeSettings mDatePref = findPreference("date"); mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT); - int currentFormatIndex = -1; String [] dateFormats = getResources().getStringArray(R.array.date_format_values); String [] formattedDates = new String[dateFormats.length]; String currentFormat = getDateFormat(); // Initialize if DATE_FORMAT is not set in the system settings // This can happen after a factory reset (or data wipe) if (currentFormat == null) { - currentFormat = getResources().getString(R.string.default_date_format); - setDateFormat(currentFormat); + currentFormat = ""; } for (int i = 0; i < formattedDates.length; i++) { - formattedDates[i] = DateFormat.format(dateFormats[i], mDummyDate).toString(); - if (currentFormat.equals(dateFormats[i])) currentFormatIndex = i; + String formatted = + DateFormat.getDateFormatForSetting(this, dateFormats[i]). + format(mDummyDate.getTime()); + + if (dateFormats[i].length() == 0) { + formattedDates[i] = getResources(). + getString(R.string.normal_date_format, formatted); + } else { + formattedDates[i] = formatted; + } } mDateFormat.setEntries(formattedDates); @@ -314,6 +320,10 @@ public class DateTimeSettings } private void setDateFormat(String format) { + if (format.length() == 0) { + format = null; + } + Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format); }