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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user