Merge "Use different version of CLDR data in DatePicker" into gingerbread

This commit is contained in:
Svetoslav Ganov
2011-02-24 23:56:52 -08:00
committed by Android (Google) Code Review

View File

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