|
49 | 49 | import androidx.annotation.RestrictTo; |
50 | 50 | import androidx.annotation.StringRes; |
51 | 51 | import androidx.annotation.StyleRes; |
| 52 | +import androidx.annotation.VisibleForTesting; |
52 | 53 | import androidx.core.view.ViewCompat; |
53 | 54 | import androidx.core.view.accessibility.AccessibilityEventCompat; |
54 | 55 | import com.google.android.material.button.MaterialButton; |
@@ -136,17 +137,34 @@ private static MaterialTimePicker newInstance(@NonNull Builder options) { |
136 | 137 | return fragment; |
137 | 138 | } |
138 | 139 |
|
139 | | - @IntRange(from = 0, to = 60) |
| 140 | + /** Returns the minute in the range [0, 59]. */ |
| 141 | + @IntRange(from = 0, to = 59) |
140 | 142 | public int getMinute() { |
141 | 143 | return time.minute; |
142 | 144 | } |
143 | 145 |
|
| 146 | + /** Sets the minute in the range [0, 59]. */ |
| 147 | + public void setMinute(@IntRange(from = 0, to = 59) int minute) { |
| 148 | + time.setMinute(minute); |
| 149 | + if (activePresenter != null) { |
| 150 | + activePresenter.invalidate(); |
| 151 | + } |
| 152 | + } |
| 153 | + |
144 | 154 | /** Returns the hour of day in the range [0, 23]. */ |
145 | 155 | @IntRange(from = 0, to = 23) |
146 | 156 | public int getHour() { |
147 | 157 | return time.hour % 24; |
148 | 158 | } |
149 | 159 |
|
| 160 | + /** Sets the hour of day in the range [0, 23]. */ |
| 161 | + public void setHour(@IntRange(from = 0, to = 23) int hour) { |
| 162 | + time.setHour(hour); |
| 163 | + if (activePresenter != null) { |
| 164 | + activePresenter.invalidate(); |
| 165 | + } |
| 166 | + } |
| 167 | + |
150 | 168 | @InputMode |
151 | 169 | public int getInputMode() { |
152 | 170 | return inputMode; |
@@ -408,6 +426,11 @@ TimePickerClockPresenter getTimePickerClockPresenter() { |
408 | 426 | return timePickerClockPresenter; |
409 | 427 | } |
410 | 428 |
|
| 429 | + @VisibleForTesting |
| 430 | + void setActivePresenter(@Nullable TimePickerPresenter presenter) { |
| 431 | + activePresenter = presenter; |
| 432 | + } |
| 433 | + |
411 | 434 | /** The supplied listener is called when the user confirms a valid selection. */ |
412 | 435 | public boolean addOnPositiveButtonClickListener(@NonNull OnClickListener listener) { |
413 | 436 | return positiveButtonListeners.add(listener); |
@@ -548,7 +571,7 @@ public Builder setHour(@IntRange(from = 0, to = 23) int hour) { |
548 | 571 |
|
549 | 572 | /** Sets the minute with which to start the time picker. */ |
550 | 573 | @NonNull |
551 | | - public Builder setMinute(@IntRange(from = 0, to = 60) int minute) { |
| 574 | + public Builder setMinute(@IntRange(from = 0, to = 59) int minute) { |
552 | 575 | time.setMinute(minute); |
553 | 576 | return this; |
554 | 577 | } |
|
0 commit comments