Skip to content

Commit 40cfb07

Browse files
committed
[TimePicker] Prevent setting wrong time while the clock is animating
PiperOrigin-RevId: 650636506
1 parent c714328 commit 40cfb07

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/java/com/google/android/material/timepicker/TimePickerClockPresenter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ class TimePickerClockPresenter
4747
OnActionUpListener,
4848
TimePickerPresenter {
4949

50-
private static final String[] HOUR_CLOCK_VALUES =
51-
{"12", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
50+
private static final String[] HOUR_CLOCK_VALUES = {
51+
"12", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"
52+
};
5253

5354
private static final String[] HOUR_CLOCK_24_VALUES = {
5455
"00", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
5556
"17", "18", "19", "20", "21", "22", "23"
5657
};
5758

58-
private static final String[] MINUTE_CLOCK_VALUES =
59-
{"00", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55"};
59+
private static final String[] MINUTE_CLOCK_VALUES = {
60+
"00", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55"
61+
};
6062

6163
private static final int DEGREES_PER_HOUR = 30;
6264
private static final int DEGREES_PER_MINUTE = 6;
@@ -112,7 +114,8 @@ private String[] getHourClockValues() {
112114

113115
@Override
114116
public void onRotate(float rotation, boolean animating) {
115-
if (broadcasting) {
117+
// Do not update the displayed and actual time during an animation
118+
if (broadcasting || animating) {
116119
return;
117120
}
118121

@@ -138,11 +141,8 @@ public void onRotate(float rotation, boolean animating) {
138141
hourRotation = getHourRotation();
139142
}
140143

141-
// Do not update the display during an animation
142-
if (!animating) {
143-
updateTime();
144-
performHapticFeedback(prevHour, prevMinute);
145-
}
144+
updateTime();
145+
performHapticFeedback(prevHour, prevMinute);
146146
}
147147

148148
private void performHapticFeedback(int prevHour, int prevMinute) {

0 commit comments

Comments
 (0)