Skip to content

Commit

Permalink
[MaterialTimePicker] Add setters for hour and minute
Browse files Browse the repository at this point in the history
Resolves #2515

PiperOrigin-RevId: 428563049
  • Loading branch information
paulfthomas authored and raajkumars committed Feb 15, 2022
1 parent 6bf92e1 commit 85a4405
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Expand Up @@ -49,6 +49,7 @@
import androidx.annotation.RestrictTo;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityEventCompat;
import com.google.android.material.button.MaterialButton;
Expand Down Expand Up @@ -136,17 +137,34 @@ private static MaterialTimePicker newInstance(@NonNull Builder options) {
return fragment;
}

@IntRange(from = 0, to = 60)
/** Returns the minute in the range [0, 59]. */
@IntRange(from = 0, to = 59)
public int getMinute() {
return time.minute;
}

/** Sets the minute in the range [0, 59]. */
public void setMinute(@IntRange(from = 0, to = 59) int minute) {
time.setMinute(minute);
if (activePresenter != null) {
activePresenter.invalidate();
}
}

/** Returns the hour of day in the range [0, 23]. */
@IntRange(from = 0, to = 23)
public int getHour() {
return time.hour % 24;
}

/** Sets the hour of day in the range [0, 23]. */
public void setHour(@IntRange(from = 0, to = 23) int hour) {
time.setHour(hour);
if (activePresenter != null) {
activePresenter.invalidate();
}
}

@InputMode
public int getInputMode() {
return inputMode;
Expand Down Expand Up @@ -408,6 +426,11 @@ TimePickerClockPresenter getTimePickerClockPresenter() {
return timePickerClockPresenter;
}

@VisibleForTesting
void setActivePresenter(@Nullable TimePickerPresenter presenter) {
activePresenter = presenter;
}

/** The supplied listener is called when the user confirms a valid selection. */
public boolean addOnPositiveButtonClickListener(@NonNull OnClickListener listener) {
return positiveButtonListeners.add(listener);
Expand Down Expand Up @@ -548,7 +571,7 @@ public Builder setHour(@IntRange(from = 0, to = 23) int hour) {

/** Sets the minute with which to start the time picker. */
@NonNull
public Builder setMinute(@IntRange(from = 0, to = 60) int minute) {
public Builder setMinute(@IntRange(from = 0, to = 59) int minute) {
time.setMinute(minute);
return this;
}
Expand Down
Expand Up @@ -91,7 +91,7 @@ public void setHour(int hour) {
this.hour = hour % 12 + (period == PM ? 12 : 0);
}

public void setMinute(@IntRange(from = 0, to = 60) int minute) {
public void setMinute(@IntRange(from = 0, to = 59) int minute) {
this.minute = minute % 60;
}

Expand Down
Expand Up @@ -18,7 +18,7 @@

interface TimePickerPresenter {

/** Do any final intialization */
/** Do any final initialization */
void initialize();

/** Refresh the data in the view based on the model */
Expand Down

0 comments on commit 85a4405

Please sign in to comment.