summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/DatePicker.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-03-18 14:41:50 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2011-03-18 14:41:54 -0700
commitf583dd37643f495642cd64e9b8e6a0a9e0836ff1 (patch)
tree678a24c4cf7cf2e1e9fbf2c42e8fde9b42c1e041 /core/java/android/widget/DatePicker.java
parentb18a047de574f188b2c7633164f15ab3c9e40b5b (diff)
downloadframeworks_base-f583dd37643f495642cd64e9b8e6a0a9e0836ff1.zip
frameworks_base-f583dd37643f495642cd64e9b8e6a0a9e0836ff1.tar.gz
frameworks_base-f583dd37643f495642cd64e9b8e6a0a9e0836ff1.tar.bz2
DatePicker does not respect the user preference of date format
bug:4124142 The DatePicker was not properly interpreting the current date format and was ingoring user preferences for the date format rather it was using the locale default all the time. Change-Id: I195c2ad975dc4e9adc5b6eb70c33c909a1553113
Diffstat (limited to 'core/java/android/widget/DatePicker.java')
-rw-r--r--core/java/android/widget/DatePicker.java82
1 files changed, 18 insertions, 64 deletions
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index 1d442db..7210e21 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -410,74 +410,28 @@ public class DatePicker extends FrameLayout {
}
/**
- * Reorders the spinners according to the date format in the current
- * {@link Locale}.
+ * Reorders the spinners according to the date format that is
+ * explicitly set by the user and if no such is set fall back
+ * to the current locale's default format.
*/
private void reorderSpinners() {
- java.text.DateFormat format;
- String order;
-
- /*
- * If the user is in a locale where the medium date format is still
- * numeric (Japanese and Czech, for example), respect the date format
- * order setting. Otherwise, use the order that the locale says is
- * appropriate for a spelled-out date.
- */
-
- if (getShortMonths()[0].startsWith("1")) {
- format = DateFormat.getDateFormat(getContext());
- } else {
- format = DateFormat.getMediumDateFormat(getContext());
- }
-
- if (format instanceof SimpleDateFormat) {
- order = ((SimpleDateFormat) format).toPattern();
- } else {
- // Shouldn't happen, but just in case.
- order = new String(DateFormat.getDateFormatOrder(getContext()));
- }
-
- /*
- * Remove the 3 spinners from their parent and then add them back in the
- * required order.
- */
- LinearLayout parent = mSpinners;
- parent.removeAllViews();
-
- boolean quoted = false;
- boolean didDay = false, didMonth = false, didYear = false;
-
- for (int i = 0; i < order.length(); i++) {
- char c = order.charAt(i);
-
- if (c == '\'') {
- quoted = !quoted;
- }
-
- if (!quoted) {
- if (c == DateFormat.DATE && !didDay) {
- parent.addView(mDaySpinner);
- didDay = true;
- } else if ((c == DateFormat.MONTH || c == 'L') && !didMonth) {
- parent.addView(mMonthSpinner);
- didMonth = true;
- } else if (c == DateFormat.YEAR && !didYear) {
- parent.addView(mYearSpinner);
- didYear = true;
- }
+ mSpinners.removeAllViews();
+ char[] order = DateFormat.getDateFormatOrder(getContext());
+ for (int i = 0; i < order.length; i++) {
+ switch (order[i]) {
+ case DateFormat.DATE:
+ mSpinners.addView(mDaySpinner);
+ break;
+ case DateFormat.MONTH:
+ mSpinners.addView(mMonthSpinner);
+ break;
+ case DateFormat.YEAR:
+ mSpinners.addView(mYearSpinner);
+ break;
+ default:
+ throw new IllegalArgumentException();
}
}
-
- // Shouldn't happen, but just in case.
- if (!didMonth) {
- parent.addView(mMonthSpinner);
- }
- if (!didDay) {
- parent.addView(mDaySpinner);
- }
- if (!didYear) {
- parent.addView(mYearSpinner);
- }
}
/**