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

Commit 4689cd95 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu Committed by Android (Google) Code Review
Browse files

Merge "CalendarView Material - throw exception if date is out of range"

parents 8a6b090f 95331038
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -789,14 +789,14 @@ class CalendarViewLegacyDelegate extends CalendarView.AbstractCalendarViewDelega
     * @param forceScroll Whether to recenter even if the time is already
     *            visible.
     *
     * @throws IllegalArgumentException of the provided date is before the
     *        range start of after the range end.
     * @throws IllegalArgumentException if the provided date is before the
     *         range start or after the range end.
     */
    private void goTo(Calendar date, boolean animate, boolean setSelected,
            boolean forceScroll) {
        if (date.before(mMinDate) || date.after(mMaxDate)) {
            throw new IllegalArgumentException("Time not between " + mMinDate.getTime()
                    + " and " + mMaxDate.getTime());
            throw new IllegalArgumentException("timeInMillis must be between the values of "
                    + "getMinDate() and getMaxDate()");
        }
        // Find the first and last entirely visible weeks
        int firstFullyVisiblePosition = mListView.getFirstVisiblePosition();
+15 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.widget;

import static android.os.Build.VERSION_CODES.N_MR1;

import android.graphics.Rect;
import com.android.internal.R;
import com.android.internal.widget.ViewPager;
@@ -291,8 +293,21 @@ class DayPickerView extends ViewGroup {
     * @param timeInMillis the target day in milliseconds
     * @param animate whether to smooth scroll to the new position
     * @param setSelected whether to set the specified day as selected
     *
     * @throws IllegalArgumentException as of {@link android.os.Build.VERSION_CODES#N_MR1} if the
     *         provided timeInMillis is before the range start or after the range end.
     */
    private void setDate(long timeInMillis, boolean animate, boolean setSelected) {
        getTempCalendarForTime(timeInMillis);

        final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
        if (targetSdkVersion >= N_MR1) {
            if (mTempCalendar.before(mMinDate) || mTempCalendar.after(mMaxDate)) {
                throw new IllegalArgumentException("timeInMillis must be between the values of "
                        + "getMinDate() and getMaxDate()");
            }
        }

        if (setSelected) {
            mSelectedDay.setTimeInMillis(timeInMillis);
        }
@@ -302,7 +317,6 @@ class DayPickerView extends ViewGroup {
            mViewPager.setCurrentItem(position, animate);
        }

        mTempCalendar.setTimeInMillis(timeInMillis);
        mAdapter.setSelectedDay(mTempCalendar);
    }