Merge "Fix unexpected DatePicker validation" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cd603221e1
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package android.widget;
|
package android.widget;
|
||||||
|
|
||||||
import static android.os.Build.VERSION_CODES.O;
|
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
@@ -293,22 +291,10 @@ 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 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) {
|
private void setDate(long timeInMillis, boolean animate, boolean setSelected) {
|
||||||
getTempCalendarForTime(timeInMillis);
|
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) {
|
if (setSelected) {
|
||||||
mSelectedDay.setTimeInMillis(timeInMillis);
|
mSelectedDay.setTimeInMillis(timeInMillis);
|
||||||
}
|
}
|
||||||
@@ -367,6 +353,13 @@ class DayPickerView extends ViewGroup {
|
|||||||
public void onRangeChanged() {
|
public void onRangeChanged() {
|
||||||
mAdapter.setRange(mMinDate, mMaxDate);
|
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
|
// Changing the min/max date changes the selection position since we
|
||||||
// don't really have stable IDs. Jumps immediately to the new position.
|
// don't really have stable IDs. Jumps immediately to the new position.
|
||||||
setDate(mSelectedDay.getTimeInMillis(), false, false);
|
setDate(mSelectedDay.getTimeInMillis(), false, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user