diff options
| author | Andrei Stingaceanu <stg@google.com> | 2016-06-28 15:56:44 +0100 |
|---|---|---|
| committer | Andrei Stingaceanu <stg@google.com> | 2016-07-08 15:22:56 +0100 |
| commit | 95331038c3eea07af17cb8c64574b6516612548c (patch) | |
| tree | b2bb7b905b37e3ed76c804a97d303f98b675aac3 /core/java/android/widget/DayPickerView.java | |
| parent | 219d9ba4fae554974fc0d2370f8b4556878307a3 (diff) | |
CalendarView Material - throw exception if date is out of range
Similar to CalendarViewLegacyDelegate#goTo
Bug: 28019187
Change-Id: Id21dcd208a594b98dc89caf59d36b32bdf9484be
Diffstat (limited to 'core/java/android/widget/DayPickerView.java')
| -rw-r--r-- | core/java/android/widget/DayPickerView.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/core/java/android/widget/DayPickerView.java b/core/java/android/widget/DayPickerView.java index 7e950f785600..0c02a2ba61fa 100644 --- a/core/java/android/widget/DayPickerView.java +++ b/core/java/android/widget/DayPickerView.java @@ -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); } |
