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

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

CalendarView Material - throw exception if date is out of range

Similar to CalendarViewLegacyDelegate#goTo

Bug: 28019187
Change-Id: Id21dcd208a594b98dc89caf59d36b32bdf9484be
parent 219d9ba4
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line 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
     * @param forceScroll Whether to recenter even if the time is already
     *            visible.
     *            visible.
     *
     *
     * @throws IllegalArgumentException of the provided date is before the
     * @throws IllegalArgumentException if the provided date is before the
     *        range start of after the range end.
     *         range start or after the range end.
     */
     */
    private void goTo(Calendar date, boolean animate, boolean setSelected,
    private void goTo(Calendar date, boolean animate, boolean setSelected,
            boolean forceScroll) {
            boolean forceScroll) {
        if (date.before(mMinDate) || date.after(mMaxDate)) {
        if (date.before(mMinDate) || date.after(mMaxDate)) {
            throw new IllegalArgumentException("Time not between " + mMinDate.getTime()
            throw new IllegalArgumentException("timeInMillis must be between the values of "
                    + " and " + mMaxDate.getTime());
                    + "getMinDate() and getMaxDate()");
        }
        }
        // Find the first and last entirely visible weeks
        // Find the first and last entirely visible weeks
        int firstFullyVisiblePosition = mListView.getFirstVisiblePosition();
        int firstFullyVisiblePosition = mListView.getFirstVisiblePosition();
+15 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.widget;
package android.widget;


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

import android.graphics.Rect;
import android.graphics.Rect;
import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.widget.ViewPager;
import com.android.internal.widget.ViewPager;
@@ -291,8 +293,21 @@ class DayPickerView extends ViewGroup {
     * @param timeInMillis the target day in milliseconds
     * @param timeInMillis the target day in milliseconds
     * @param animate whether to smooth scroll to the new position
     * @param animate whether to smooth scroll to the new position
     * @param setSelected whether to set the specified day as selected
     * @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) {
    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) {
        if (setSelected) {
            mSelectedDay.setTimeInMillis(timeInMillis);
            mSelectedDay.setTimeInMillis(timeInMillis);
        }
        }
@@ -302,7 +317,6 @@ class DayPickerView extends ViewGroup {
            mViewPager.setCurrentItem(position, animate);
            mViewPager.setCurrentItem(position, animate);
        }
        }


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