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

Commit e565e525 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

DayPickerView - clamp date to min/max

Besides clamping @ setMinDate() and setMaxDate() also
clamp @ setDate().

Bug: 36636681
Bug: 62485314
Test: cts-tradefed run cts-dev -m CtsWidgetTestCases -t
      android.widget.cts.CalendarViewTest#testMinMaxRangeClampingMaterial

Change-Id: I455cd43e7228e10d58b5f886dcab8332bca72de7
parent c7ea7eff
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -293,9 +293,19 @@ class DayPickerView extends ViewGroup {
     * @param setSelected whether to set the specified day as selected
     */
    private void setDate(long timeInMillis, boolean animate, boolean setSelected) {
        boolean dateClamped = false;
        // Clamp the target day in milliseconds to the min or max if outside the range.
        if (timeInMillis < mMinDate.getTimeInMillis()) {
            timeInMillis = mMinDate.getTimeInMillis();
            dateClamped = true;
        } else if (timeInMillis > mMaxDate.getTimeInMillis()) {
            timeInMillis = mMaxDate.getTimeInMillis();
            dateClamped = true;
        }

        getTempCalendarForTime(timeInMillis);

        if (setSelected) {
        if (setSelected || dateClamped) {
            mSelectedDay.setTimeInMillis(timeInMillis);
        }

@@ -353,13 +363,6 @@ class DayPickerView extends ViewGroup {
    public void onRangeChanged() {
        mAdapter.setRange(mMinDate, mMaxDate);

        // Clamp the selected day to the new min/max.
        if (mSelectedDay.before(mMinDate)) {
            mSelectedDay.setTimeInMillis(mMinDate.getTimeInMillis());
        } else if (mSelectedDay.after(mMaxDate)) {
            mSelectedDay.setTimeInMillis(mMaxDate.getTimeInMillis());
        }

        // Changing the min/max date changes the selection position since we
        // don't really have stable IDs. Jumps immediately to the new position.
        setDate(mSelectedDay.getTimeInMillis(), false, false);