Merge "Use different version of CLDR data in DatePicker" into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
9e5b1a4902
@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -33,6 +34,7 @@ import com.android.internal.R;
|
|||||||
import java.text.DateFormatSymbols;
|
import java.text.DateFormatSymbols;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A view for selecting a month / year / day based on a calendar like layout.
|
* A view for selecting a month / year / day based on a calendar like layout.
|
||||||
@@ -48,6 +50,9 @@ public class DatePicker extends FrameLayout {
|
|||||||
private static final int DEFAULT_START_YEAR = 1900;
|
private static final int DEFAULT_START_YEAR = 1900;
|
||||||
private static final int DEFAULT_END_YEAR = 2100;
|
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 */
|
/* UI Components */
|
||||||
private final NumberPicker mDayPicker;
|
private final NumberPicker mDayPicker;
|
||||||
private final NumberPicker mMonthPicker;
|
private final NumberPicker mMonthPicker;
|
||||||
@@ -62,6 +67,10 @@ public class DatePicker extends FrameLayout {
|
|||||||
private int mMonth;
|
private int mMonth;
|
||||||
private int mYear;
|
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.
|
* 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 = (NumberPicker) findViewById(R.id.month);
|
||||||
mMonthPicker.setFormatter(NumberPicker.TWO_DIGIT_FORMATTER);
|
mMonthPicker.setFormatter(NumberPicker.TWO_DIGIT_FORMATTER);
|
||||||
DateFormatSymbols dfs = new DateFormatSymbols();
|
final String[] months = getShortMonths();
|
||||||
String[] months = dfs.getShortMonths();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the user is in a locale where the month names are numeric,
|
* 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++) {
|
for (int i = 0; i < months.length; i++) {
|
||||||
months[i] = String.valueOf(i + 1);
|
months[i] = String.valueOf(i + 1);
|
||||||
}
|
}
|
||||||
mMonthPicker.setRange(1, 12);
|
mMonthPicker.setRange(1, NUMBER_OF_MONTHS);
|
||||||
} else {
|
} else {
|
||||||
mMonthPicker.setRange(1, 12, months);
|
mMonthPicker.setRange(1, NUMBER_OF_MONTHS, months);
|
||||||
}
|
}
|
||||||
|
|
||||||
mMonthPicker.setSpeed(200);
|
mMonthPicker.setSpeed(200);
|
||||||
@@ -246,11 +254,30 @@ public class DatePicker extends FrameLayout {
|
|||||||
mMonth = monthOfYear;
|
mMonth = monthOfYear;
|
||||||
mDay = dayOfMonth;
|
mDay = dayOfMonth;
|
||||||
updateSpinners();
|
updateSpinners();
|
||||||
reorderPickers(new DateFormatSymbols().getShortMonths());
|
reorderPickers(getShortMonths());
|
||||||
notifyDateChanged();
|
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 static class SavedState extends BaseSavedState {
|
||||||
|
|
||||||
private final int mYear;
|
private final int mYear;
|
||||||
|
|||||||
Reference in New Issue
Block a user