Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa8904a6 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

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
parents 00d3e361 2bf761c2
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -243,10 +243,12 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
    private void validateCurrentView(CharSequence str) {
        int val = getSelectedPos(str.toString());
        if ((val >= mStart) && (val <= mEnd)) {
            if (mCurrent != val) {
                mPrevious = mCurrent;
                mCurrent = val;
                notifyChange();
            }
        }
        updateView();
    }