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.
This commit is contained in:
Eric Fischer
2009-06-11 18:16:15 -07:00
parent 1617706d25
commit 188ca77870
3 changed files with 23 additions and 15 deletions

View File

@@ -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);
}