Use different version of CLDR data in DatePicker
The ICU CLDR data doesn't use the month abbreviations that are appropriate for the DatePicker, so use the framework copy of the CLDR data. Bug: 2641810 Note: cherry-picked from Honeycomb Change-Id: I3c045dbfb751b8b7ce6361b5a67407206fc64db1
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.format.DateFormat;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -33,6 +34,7 @@ import com.android.internal.R;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A view for selecting a month / year / day based on a calendar like layout.
|
||||
@@ -47,7 +49,10 @@ public class DatePicker extends FrameLayout {
|
||||
|
||||
private static final int DEFAULT_START_YEAR = 1900;
|
||||
private static final int DEFAULT_END_YEAR = 2100;
|
||||
|
||||
|
||||
// This ignores Undecimber, but we only support real Gregorian calendars.
|
||||
private static final int NUMBER_OF_MONTHS = 12;
|
||||
|
||||
/* UI Components */
|
||||
private final NumberPicker mDayPicker;
|
||||
private final NumberPicker mMonthPicker;
|
||||
@@ -62,6 +67,10 @@ public class DatePicker extends FrameLayout {
|
||||
private int mMonth;
|
||||
private int mYear;
|
||||
|
||||
private Object mMonthUpdateLock = new Object();
|
||||
private volatile Locale mMonthLocale;
|
||||
private String[] mShortMonths;
|
||||
|
||||
/**
|
||||
* The callback used to indicate the user changes the date.
|
||||
*/
|
||||
@@ -102,8 +111,7 @@ public class DatePicker extends FrameLayout {
|
||||
});
|
||||
mMonthPicker = (NumberPicker) findViewById(R.id.month);
|
||||
mMonthPicker.setFormatter(NumberPicker.TWO_DIGIT_FORMATTER);
|
||||
DateFormatSymbols dfs = new DateFormatSymbols();
|
||||
String[] months = dfs.getShortMonths();
|
||||
final String[] months = getShortMonths();
|
||||
|
||||
/*
|
||||
* If the user is in a locale where the month names are numeric,
|
||||
@@ -114,9 +122,9 @@ public class DatePicker extends FrameLayout {
|
||||
for (int i = 0; i < months.length; i++) {
|
||||
months[i] = String.valueOf(i + 1);
|
||||
}
|
||||
mMonthPicker.setRange(1, 12);
|
||||
mMonthPicker.setRange(1, NUMBER_OF_MONTHS);
|
||||
} else {
|
||||
mMonthPicker.setRange(1, 12, months);
|
||||
mMonthPicker.setRange(1, NUMBER_OF_MONTHS, months);
|
||||
}
|
||||
|
||||
mMonthPicker.setSpeed(200);
|
||||
@@ -246,11 +254,30 @@ public class DatePicker extends FrameLayout {
|
||||
mMonth = monthOfYear;
|
||||
mDay = dayOfMonth;
|
||||
updateSpinners();
|
||||
reorderPickers(new DateFormatSymbols().getShortMonths());
|
||||
reorderPickers(getShortMonths());
|
||||
notifyDateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getShortMonths() {
|
||||
final Locale currentLocale = Locale.getDefault();
|
||||
if (currentLocale.equals(mMonthLocale) && mShortMonths != null) {
|
||||
return mShortMonths;
|
||||
} else {
|
||||
synchronized (mMonthUpdateLock) {
|
||||
if (!currentLocale.equals(mMonthLocale)) {
|
||||
mShortMonths = new String[NUMBER_OF_MONTHS];
|
||||
for (int i = 0; i < NUMBER_OF_MONTHS; i++) {
|
||||
mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i,
|
||||
DateUtils.LENGTH_MEDIUM);
|
||||
}
|
||||
mMonthLocale = currentLocale;
|
||||
}
|
||||
}
|
||||
return mShortMonths;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
|
||||
private final int mYear;
|
||||
|
||||
Reference in New Issue
Block a user