7 package com.google.appinventor.components.runtime;
20 import android.app.Dialog;
21 import android.app.TimePickerDialog;
22 import android.text.format.DateFormat;
23 import android.os.Handler;
25 import java.util.Calendar;
41 @DesignerComponent(version = YaVersion.TIMEPICKER_COMPONENT_VERSION,
42 category = ComponentCategory.USERINTERFACE,
43 description =
"<p>A button that, when clicked on, launches a popup" +
44 " dialog to allow the user to select a time.</p>")
49 private int minute = 0;
50 private TimePickerDialog time;
51 private boolean customTime =
false;
53 private Calendar instant;
54 private Handler androidUIHandler;
64 final Calendar c = Calendar.getInstance();
65 hour = c.get(Calendar.HOUR_OF_DAY);
66 minute = c.get(Calendar.MINUTE);
67 time =
new TimePickerDialog(this.container.
$context(),
68 timePickerListener, hour, minute, DateFormat.is24HourFormat(this.container.
$context()));
71 androidUIHandler =
new Handler();
83 description =
"The hour of the last time set using the time picker." +
84 " The hour is in a 24 hour format. If the last time set was 11:53 pm" +
85 ", this property will return 23.",
98 description =
"The minute of the last time set using the time picker",
109 description =
"The instant of the last time set using the time picker",
121 @
SimpleFunction(description=
"Set the time to be shown in the Time Picker popup. Current time is shown by default.")
123 if ((hour < 0) || (hour > 23)) {
125 }
else if ((minute < 0) || (minute > 59)) {
128 time.updateTime(hour, minute);
140 @
SimpleFunction(description=
"Set the time from the instant to be shown in the Time Picker dialog. " +
141 "Current time is shown by default.")
145 time.updateTime(hour, minute);
161 Calendar c = Calendar.getInstance();
162 int h = c.get(Calendar.HOUR_OF_DAY);
163 int m = c.get(Calendar.MINUTE);
164 time.updateTime(h, m);
172 private TimePickerDialog.OnTimeSetListener timePickerListener =
173 new TimePickerDialog.OnTimeSetListener() {
174 public void onTimeSet(android.widget.TimePicker view,
int selectedHour,
175 int selectedMinute) {
176 if (view.isShown()) {
178 minute = selectedMinute;
184 androidUIHandler.post(
new Runnable() {
196 @SimpleEvent(description=
"This event is run when a user has set the time in the popup dialog.")