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:
@@ -39,18 +39,12 @@
|
|||||||
<item>All</item>
|
<item>All</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- There is a setting to control the format of dates displayed throughout the system. This is in the Date & Time Settings screen. Unfortunately, these cannot be changed at all. --> <skip />
|
<!-- There is a setting to control the format of dates displayed throughout the system. This is in the Date & Time Settings screen. These will be adjusted to use punctuation appropriate to the user's locale. -->
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
<string-array name="date_format_values" translatable="false">
|
||||||
<string-array name="date_format_values">
|
<!-- The blank item means to use whatever the locale calls for. -->
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
<item></item>
|
||||||
<item>MM-dd-yyyy</item>
|
<item>MM-dd-yyyy</item>
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
|
||||||
<item>dd-MM-yyyy</item>
|
<item>dd-MM-yyyy</item>
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
|
||||||
<item>MMM d, yyyy</item>
|
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
|
||||||
<item>d-MMM-yyyy</item>
|
|
||||||
<!-- Do not translate. This is fed directly to the formatter. -->
|
|
||||||
<item>yyyy-MM-dd</item>
|
<item>yyyy-MM-dd</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
@@ -243,6 +243,10 @@
|
|||||||
<!-- Do not translate. Used as the value for a setting. -->
|
<!-- Do not translate. Used as the value for a setting. -->
|
||||||
<string name="default_date_format"><xliff:g id="default_date_format">MM/dd/yyyy</xliff:g></string>
|
<string name="default_date_format"><xliff:g id="default_date_format">MM/dd/yyyy</xliff:g></string>
|
||||||
|
|
||||||
|
<!-- The option in the date-format picker for using the normal format
|
||||||
|
called for by the user's locale. -->
|
||||||
|
<string name="normal_date_format">Normal (<xliff:g id="date" example="12-31-2009">%s</xliff:g>)</string>
|
||||||
|
|
||||||
<!-- Label of preview text when tweaking font size -->
|
<!-- Label of preview text when tweaking font size -->
|
||||||
<string name="display_preview_label">Preview:</string>
|
<string name="display_preview_label">Preview:</string>
|
||||||
<!-- Label for chosen font size -->
|
<!-- Label for chosen font size -->
|
||||||
|
@@ -87,19 +87,25 @@ public class DateTimeSettings
|
|||||||
mDatePref = findPreference("date");
|
mDatePref = findPreference("date");
|
||||||
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
|
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
|
||||||
|
|
||||||
int currentFormatIndex = -1;
|
|
||||||
String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
|
String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
|
||||||
String [] formattedDates = new String[dateFormats.length];
|
String [] formattedDates = new String[dateFormats.length];
|
||||||
String currentFormat = getDateFormat();
|
String currentFormat = getDateFormat();
|
||||||
// Initialize if DATE_FORMAT is not set in the system settings
|
// Initialize if DATE_FORMAT is not set in the system settings
|
||||||
// This can happen after a factory reset (or data wipe)
|
// This can happen after a factory reset (or data wipe)
|
||||||
if (currentFormat == null) {
|
if (currentFormat == null) {
|
||||||
currentFormat = getResources().getString(R.string.default_date_format);
|
currentFormat = "";
|
||||||
setDateFormat(currentFormat);
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < formattedDates.length; i++) {
|
for (int i = 0; i < formattedDates.length; i++) {
|
||||||
formattedDates[i] = DateFormat.format(dateFormats[i], mDummyDate).toString();
|
String formatted =
|
||||||
if (currentFormat.equals(dateFormats[i])) currentFormatIndex = i;
|
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);
|
mDateFormat.setEntries(formattedDates);
|
||||||
@@ -314,6 +320,10 @@ public class DateTimeSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setDateFormat(String format) {
|
private void setDateFormat(String format) {
|
||||||
|
if (format.length() == 0) {
|
||||||
|
format = null;
|
||||||
|
}
|
||||||
|
|
||||||
Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format);
|
Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user