Merge change 7012 into donut
* changes: Fix couple of issues in DatePicker The NumberPicker's listener needs to be invoked only if the current value changes when validating input. This removes the some unwanted duplicate calls to onChanged. Adjust day for month and leap years. note that updateDaySpinner directly sets the value on day picker and doesn't invoke the listener twice
This commit is contained in:
@@ -110,6 +110,8 @@ public class DatePicker extends FrameLayout {
|
||||
* subtract by one to ensure our internal state is always 0-11
|
||||
*/
|
||||
mMonth = newVal - 1;
|
||||
// Adjust max day of the month
|
||||
adjustMaxDay();
|
||||
if (mOnDateChangedListener != null) {
|
||||
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
|
||||
}
|
||||
@@ -121,9 +123,12 @@ public class DatePicker extends FrameLayout {
|
||||
mYearPicker.setOnChangeListener(new OnChangedListener() {
|
||||
public void onChanged(NumberPicker picker, int oldVal, int newVal) {
|
||||
mYear = newVal;
|
||||
// Adjust max day for leap years if needed
|
||||
adjustMaxDay();
|
||||
if (mOnDateChangedListener != null) {
|
||||
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
|
||||
}
|
||||
updateDaySpinner();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -318,4 +323,14 @@ public class DatePicker extends FrameLayout {
|
||||
public int getDayOfMonth() {
|
||||
return mDay;
|
||||
}
|
||||
|
||||
private void adjustMaxDay(){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, mYear);
|
||||
cal.set(Calendar.MONTH, mMonth);
|
||||
int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
if (mDay > max) {
|
||||
mDay = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,9 +243,11 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
|
||||
private void validateCurrentView(CharSequence str) {
|
||||
int val = getSelectedPos(str.toString());
|
||||
if ((val >= mStart) && (val <= mEnd)) {
|
||||
mPrevious = mCurrent;
|
||||
mCurrent = val;
|
||||
notifyChange();
|
||||
if (mCurrent != val) {
|
||||
mPrevious = mCurrent;
|
||||
mCurrent = val;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user