summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorAndrei Stingaceanu <stg@google.com>2017-06-06 17:30:45 +0100
committerAndrei Stingaceanu <stg@google.com>2017-06-06 17:34:42 +0100
commitcf5a420ead56916cb3e8886574e1447cf17c8e19 (patch)
tree12477017ef4e7a48bcbccb9b042c7a5128334967 /core/java
parent1ac325e4d5d0e03271b4c67b56117d39bcdcfaeb (diff)
Fix unexpected DatePicker validation
Remove throwing an error and instead clamp the selected date to min/max when changing ranges. Bug: 36636681 Test: manually verified that the case in the bug does not happen again Change-Id: If540f58d21375d2320df5215504d4569e5c2be2e
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/widget/DayPickerView.java21
1 files changed, 7 insertions, 14 deletions
diff --git a/core/java/android/widget/DayPickerView.java b/core/java/android/widget/DayPickerView.java
index cfd1445ea3f8..1e8207a2e7b3 100644
--- a/core/java/android/widget/DayPickerView.java
+++ b/core/java/android/widget/DayPickerView.java
@@ -16,8 +16,6 @@
package android.widget;
-import static android.os.Build.VERSION_CODES.O;
-
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -293,22 +291,10 @@ 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 if the build version is greater than
- * {@link android.os.Build.VERSION_CODES#N_MR1} and 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 >= O) {
- 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);
}
@@ -367,6 +353,13 @@ 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);