Constrain input hour and minute to valid range am: f0ac2ba9f4
am: a2c9a8c274
Change-Id: Ifc3701f407620892909d8228a330d4b7e0af101c
This commit is contained in:
@@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package android.widget;
|
package android.widget;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
|
|
||||||
|
import android.annotation.IntRange;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.annotation.Widget;
|
import android.annotation.Widget;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.Parcelable.Creator;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.MathUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import com.android.internal.R;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@ public class TimePicker extends FrameLayout {
|
|||||||
* @param hour the hour to set, in the range (0-23)
|
* @param hour the hour to set, in the range (0-23)
|
||||||
* @see #getHour()
|
* @see #getHour()
|
||||||
*/
|
*/
|
||||||
public void setHour(int hour) {
|
public void setHour(@IntRange(from = 0, to = 23) int hour) {
|
||||||
mDelegate.setHour(hour);
|
mDelegate.setHour(MathUtils.constrain(hour, 0, 23));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,13 +117,13 @@ public class TimePicker extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the currently selected minute..
|
* Sets the currently selected minute.
|
||||||
*
|
*
|
||||||
* @param minute the minute to set, in the range (0-59)
|
* @param minute the minute to set, in the range (0-59)
|
||||||
* @see #getMinute()
|
* @see #getMinute()
|
||||||
*/
|
*/
|
||||||
public void setMinute(int minute) {
|
public void setMinute(@IntRange(from = 0, to = 59) int minute) {
|
||||||
mDelegate.setMinute(minute);
|
mDelegate.setMinute(MathUtils.constrain(minute, 0, 59));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,8 +137,9 @@ public class TimePicker extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current hour.
|
* Sets the currently selected hour using 24-hour time.
|
||||||
*
|
*
|
||||||
|
* @param currentHour the hour to set, in the range (0-23)
|
||||||
* @deprecated Use {@link #setHour(int)}
|
* @deprecated Use {@link #setHour(int)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -147,33 +148,34 @@ public class TimePicker extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current hour in the range (0-23)
|
* @return the currently selected hour, in the range (0-23)
|
||||||
* @deprecated Use {@link #getHour()}
|
* @deprecated Use {@link #getHour()}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Integer getCurrentHour() {
|
public Integer getCurrentHour() {
|
||||||
return mDelegate.getHour();
|
return getHour();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current minute (0-59).
|
* Sets the currently selected minute.
|
||||||
*
|
*
|
||||||
|
* @param currentMinute the minute to set, in the range (0-59)
|
||||||
* @deprecated Use {@link #setMinute(int)}
|
* @deprecated Use {@link #setMinute(int)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setCurrentMinute(@NonNull Integer currentMinute) {
|
public void setCurrentMinute(@NonNull Integer currentMinute) {
|
||||||
mDelegate.setMinute(currentMinute);
|
setMinute(currentMinute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current minute
|
* @return the currently selected minute, in the range (0-59)
|
||||||
* @deprecated Use {@link #getMinute()}
|
* @deprecated Use {@link #getMinute()}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Integer getCurrentMinute() {
|
public Integer getCurrentMinute() {
|
||||||
return mDelegate.getMinute();
|
return getMinute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,10 +258,10 @@ public class TimePicker extends FrameLayout {
|
|||||||
* for the real behavior.
|
* for the real behavior.
|
||||||
*/
|
*/
|
||||||
interface TimePickerDelegate {
|
interface TimePickerDelegate {
|
||||||
void setHour(int hour);
|
void setHour(@IntRange(from = 0, to = 23) int hour);
|
||||||
int getHour();
|
int getHour();
|
||||||
|
|
||||||
void setMinute(int minute);
|
void setMinute(@IntRange(from = 0, to = 59) int minute);
|
||||||
int getMinute();
|
int getMinute();
|
||||||
|
|
||||||
void setIs24Hour(boolean is24Hour);
|
void setIs24Hour(boolean is24Hour);
|
||||||
|
|||||||
Reference in New Issue
Block a user