本文整理汇总了Java中android.widget.TimePicker类的典型用法代码示例。如果您正苦于以下问题:Java TimePicker类的具体用法?Java TimePicker怎么用?Java TimePicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimePicker类属于android.widget包,在下文中一共展示了TimePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBtnChooseTimeDialogClicked
import android.widget.TimePicker; //导入依赖的package包/类
@OnClick(R.id.btn_choose_time_dialog)
public void onBtnChooseTimeDialogClicked() {
final Calendar calendar = Calendar.getInstance();
TimePickerDialog dialog = new TimePickerDialog(
this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String time = DateFormat.getTimeInstance(DateFormat.SHORT).format(calendar.getTime());
ToastUtils.showShortToast(time);
}
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
false
);
dialog.show();
}
示例2: showTime
import android.widget.TimePicker; //导入依赖的package包/类
private void showTime() {
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);
TimePickerDialog dialog =
new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
}
}, mHour, mMinute, true);
dialog.show();
}
示例3: show
import android.widget.TimePicker; //导入依赖的package包/类
public AlertDialog show(Context context) {
dialog = new AlertDialog.Builder(context).create();
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.dialog_date_time);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
//window.setWindowAnimations(R.style.in_left_out_right_style);
window.setBackgroundDrawableResource(R.color.transparent);
datePicker = (DatePicker) window
.findViewById(R.id.date_time_datePicker1);
datePicker.setCalendarViewShown(false);
timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
but_ok.setOnClickListener(this);
return dialog;
}
示例4: onTimeSet
import android.widget.TimePicker; //导入依赖的package包/类
@SuppressWarnings("WrongConstant")
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
int hour, min;
Calendar datetime = Calendar.getInstance();
String am_pm = "" ;
datetime.set(Calendar.HOUR_OF_DAY, hourOfDay);
datetime.set(Calendar.MINUTE, minute);
if (datetime.get(Calendar.AM_PM) == Calendar.AM)
am_pm = "AM";
else if (datetime.get(Calendar.AM_PM) == Calendar.PM)
am_pm = "PM";
hourOfDay = hourOfDay > 12 ? hourOfDay - 12 : hourOfDay;
hour = hourOfDay > 9 ? hourOfDay : hourOfDay;
min = minute > 9 ? minute : minute;
timeInterface.setTime(hour, min, am_pm);
}
示例5: taskDueTimeOnClickBehavior
import android.widget.TimePicker; //导入依赖的package包/类
@OnClick(R.id.task_due_time_content)
void taskDueTimeOnClickBehavior() {
TimePickerDialog.OnTimeSetListener time = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minuteOfHour) {
dueCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
dueCalendar.set(Calendar.MINUTE, minuteOfHour);
DateFormat sdf = android.text.format.DateFormat.getTimeFormat(getBaseContext());
dueTimeContent.setText(sdf.format(dueCalendar.getTime()));
setTime = true;
}
};
new TimePickerDialog(this, time,
dueCalendar.get(Calendar.HOUR_OF_DAY),
dueCalendar.get(Calendar.MINUTE), true).show();
}
示例6: pickTime
import android.widget.TimePicker; //导入依赖的package包/类
/**
* 弹出时间选择对话框
* <p>
* 参数:
* title:标题
* datetime 指定时间 yyyy-MM-dd HH:mm或者HH:mm
* 返回:
* time:格式:HH:mm
*/
public static void pickTime(IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
String title = param.optString("title");
String date = param.optString("datetime");
final Calendar calendar = Calendar.getInstance();
if (!TextUtils.isEmpty(date)) {
if (date.contains(" ")) {
calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
} else {
calendar.setTime(DateUtil.convertString2Date(date, "HH:mm"));
}
}
DialogUtil.pickTime(webLoader.getPageControl().getActivity(), title, calendar, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String chooseTime = DateUtil.convertDate(calendar.getTime(), "HH:mm");
Map<String, Object> map = new HashMap<>();
map.put("time", chooseTime);
callback.applySuccess(map);
}
});
}
示例7: pickDateTime
import android.widget.TimePicker; //导入依赖的package包/类
/**
* 弹出日期时间选择对话框
* <p>
* 参数:
* title:标题
* datetime 指定时间 yyyy-MM-dd HH:mm
* 返回:
* datetime:格式:yyyy-MM-dd HH:mm
*/
public static void pickDateTime(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
String title1 = param.optString("title1");
String title2 = param.optString("title2");
String date = param.optString("datetime");
final Calendar calendar = Calendar.getInstance();
if (!TextUtils.isEmpty(date)) {
calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
}
DialogUtil.pickDateTime(webLoader.getPageControl().getActivity(), title1, title2, calendar, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd HH:mm");
Map<String, Object> map = new HashMap<>();
map.put("datetime", chooseDate);
callback.applySuccess(map);
}
});
}
示例8: onCreate
import android.widget.TimePicker; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event);
mImageView = (ImageView) findViewById(R.id.imageView);
mEventName = (EditText) findViewById(R.id.enter_event_name);
mEventDescription = (EditText) findViewById(R.id.enter_event_desc);
mCreateEvent = (Button) findViewById(R.id.create_event);
mdate = (DatePicker) findViewById(R.id.enter_event_date);
mTime = (TimePicker) findViewById(R.id.enter_event_time);
mCreateEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loading= ProgressDialog.show(CreateEventActivity.this,"Creating Event...","Please wait...",false,false);
createEvent();
}
});
if (isStoragePermissionGranted()){
accessPic();
}
}
示例9: onTimeSet
import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
editor.putLong("notificationPeriod", calendar.getTimeInMillis());
editor.commit();
Intent intent = new Intent(NotificationActivity.this, NotificationReceiver.class);
intent.setAction(NotificationReceiver.ACTION_NOTIFICATION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(NotificationActivity.this, 0, intent, 0);
AlarmManager manager = (AlarmManager) NotificationActivity.this.getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 60000, pendingIntent);
Toast.makeText(NotificationActivity.this, DateUtils.formatDateTime(NotificationActivity.this, calendar.getTimeInMillis(), DateUtils.FORMAT_SHOW_TIME), Toast.LENGTH_LONG).show();
}
示例10: onTimeSet
import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
this.hour = hourOfDay;
this.minute = minute;
// Create calendar
Calendar selectedCalendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
selectedCalendar.set(Calendar.YEAR,year);
selectedCalendar.set(Calendar.MONTH,month);
selectedCalendar.set(Calendar.DAY_OF_MONTH,day);
selectedCalendar.set(Calendar.HOUR_OF_DAY,hour);
selectedCalendar.set(Calendar.MINUTE,0);
selectedCalendar.set(Calendar.SECOND,0);
selectedCalendar.set(Calendar.MILLISECOND,0);
//
Calendar now = Calendar.getInstance(TimeZone.getTimeZone("CET"));
if (selectedCalendar.getTimeInMillis() > now.getTimeInMillis()){
selectedCalendar.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY));
}
if (listener != null) {
listener.onDateTimeSet(selectedCalendar);
} else {
Log.w("DatePickerFragment","There is no listener");
}
}
示例11: testSettingPmTimeDisplays24HourTime
import android.widget.TimePicker; //导入依赖的package包/类
@Test
public void testSettingPmTimeDisplays24HourTime() {
onListItem(1).perform(click());
onView(withId(R.id.fragment_note_deadline_button)).check(matches(allOf(withText(R.string.deadline_button_hint), isDisplayed())));
onView(withId(R.id.fragment_note_deadline_button)).perform(click());
/* Set date. */
onView(withId(R.id.dialog_timestamp_date_picker)).perform(click());
onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1));
onView(withText(R.string.ok)).perform(click());
/* Set time. */
onView(withId(R.id.dialog_timestamp_time_picker)).perform(scrollTo(), click());
onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(15, 15));
onView(withText(R.string.ok)).perform(click());
onView(withText(R.string.set)).perform(click());
onView(withId(R.id.fragment_note_deadline_button)).check(matches(allOf(withText(userDateTime("<2014-04-01 Tue 15:15>")), isDisplayed())));
}
示例12: testSchedulingNote
import android.widget.TimePicker; //导入依赖的package包/类
@Test
public void testSchedulingNote() {
defaultSetUp();
onView(withId(R.id.drawer_layout)).perform(open());
onView(withText("Scheduled")).perform(click());
onView(allOf(withId(android.R.id.list), isDisplayed())).check(matches(listViewItemCount(2)));
onView(allOf(withText(endsWith("Note C.")), isDisplayed())).perform(longClick());
onView(withId(R.id.query_cab_edit)).perform(click());
onView(withText(R.string.schedule)).perform(click());
onView(withId(R.id.dialog_timestamp_date_picker)).perform(click());
onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1));
onView(withText(R.string.ok)).perform(click());
onView(withId(R.id.dialog_timestamp_time_picker)).perform(scrollTo(), click());
onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(9, 15));
onView(withText(R.string.ok)).perform(click());
onView(withText(R.string.set)).perform(click());
onView(allOf(withId(android.R.id.list), isDisplayed())).check(matches(listViewItemCount(2)));
onView(withText(userDateTime("<2014-04-01 Tue 09:15>"))).check(matches(isDisplayed()));
}
示例13: onTimeSet
import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
if (calSet.compareTo(calNow) <= 0) {
// Today Set time passed, count to tomorrow
calSet.add(Calendar.DATE, 1);
}
setAlarm(calSet);
}
示例14: reminderTimePickerDialog
import android.widget.TimePicker; //导入依赖的package包/类
public void reminderTimePickerDialog() {
final Calendar calendar = Calendar.getInstance();
int mHour = calendar.get(Calendar.HOUR_OF_DAY);
int mMinute = calendar.get(Calendar.MINUTE);
final SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("hh:mm a", Locale.US);
final ToodooTimePickerDialog timePickerDialog = new ToodooTimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
reminderCalendar.set(Calendar.HOUR_OF_DAY, hour);
reminderCalendar.set(Calendar.MINUTE, minute);
selectedReminderValue = reminderCalendar.getTime();
reminderTimeValue = simpleTimeFormat.format(selectedReminderValue);
selectedReminder = reminderDateValue + " @ " + reminderTimeValue;
ToodooOptionsModel ToodooOptionsModel = toodooOptionsList.get(2);
ToodooOptionsModel.setOptionValue(selectedReminder);
mAdapter.notifyDataSetChanged();
}
}, mHour, mMinute, true);
timePickerDialog.show();
}
示例15: showTimePickerDialog
import android.widget.TimePicker; //导入依赖的package包/类
/**
* Shows time picker dialog and handles the time selected by user
* @param viewWhoIsCallingIt View whose time time needs to be updated after user selects time
* @param prefKey Preference for the key needed to be updated after user selects time
*/
private void showTimePickerDialog(final KeyValueView viewWhoIsCallingIt, final String prefKey) {
int time[] = TimeUtils.getCurrentTimeAsHourAndMinutes();
TimePickerDialog timePickerDialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
String selectedHour = i < 10 ? "0" + i: "" + i;
String selectedMinute = i1 < 10 ? "0" +i1: "" + i1;
String timeString = selectedHour + ":" + selectedMinute;
PreferenceHelper.putString(context, prefKey, timeString);
// We also backup the time here
// To get the prefKey for backup, its "last_" + prefKey
PreferenceHelper.putString(context, "last_" + prefKey, timeString);
viewWhoIsCallingIt.setValue(timeString);
addNextDayIfNecessary();
doCurrentAutoFunctions(true);
}
}, time[0], time[1], false);
timePickerDialog.show();
}