use of android.app.TimePickerDialog in project ttdj by soonphe.
the class ToolDateTimePicker method show.
public void show(Calendar calendar, final DateSelCallBack callBack) {
if (calendar == null) {
calendar = Calendar.getInstance();
}
switch(chooseType) {
case DATE:
new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
Calendar calendar = Calendar.getInstance();
calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
String date = formatDateTime(calendar.getTime(), DF_YYYY_MM_DD);
targetView.setText(date);
callBack.dateChange(calendar);
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)).show();
break;
case TIME:
new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
targetView.setText(formatDateTime(calendar.getTime(), DF_HH_MM_SS));
}
}, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
break;
default:
LinearLayout dateTimeLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.view_datetime, null);
datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
initDateTimePicker(datePicker, timePicker);
timePicker.setIs24HourView(true);
timePicker.setOnTimeChangedListener(mOnTimeChangedListener);
dialog = new AlertDialog.Builder(context).setTitle(nowDateTime).setView(dateTimeLayout).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
targetView.setText(nowDateTime);
}
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
targetView.setText("");
}
}).show();
mOnDateChangedListener.onDateChanged(null, 0, 0, 0);
break;
}
}
use of android.app.TimePickerDialog in project ttdj by soonphe.
the class ToolDateTimePicker method show.
public void show() {
Calendar c = Calendar.getInstance();
switch(chooseType) {
case DATE:
new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
Calendar calendar = Calendar.getInstance();
calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
targetView.setText(formatDateTime(calendar.getTime(), DF_YYYY_MM_DD));
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE)).show();
break;
case TIME:
new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
targetView.setText(formatDateTime(calendar.getTime(), DF_HH_MM_SS));
}
}, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
break;
default:
LinearLayout dateTimeLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.view_datetime, null);
datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
initDateTimePicker(datePicker, timePicker);
timePicker.setIs24HourView(true);
timePicker.setOnTimeChangedListener(mOnTimeChangedListener);
dialog = new AlertDialog.Builder(context).setTitle(nowDateTime).setView(dateTimeLayout).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
targetView.setText(nowDateTime);
}
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
targetView.setText("");
}
}).show();
mOnDateChangedListener.onDateChanged(null, 0, 0, 0);
break;
}
}
use of android.app.TimePickerDialog in project opacclient by opacapp.
the class SnoozeDatePickerActivity method onDateSet.
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
dt = // Joda time has 1-based months
dt.withYear(year).withMonthOfYear(monthOfYear + 1).withDayOfMonth(dayOfMonth);
new TimePickerDialog(this, R.style.Theme_AppCompat_Light_Dialog, this, dt.getHourOfDay(), dt.getMinuteOfHour(), DateFormat.is24HourFormat(this)).show();
}
use of android.app.TimePickerDialog in project AndFrameWorks by scwang90.
the class AfDialogBuilder method selectDateTime.
/**
* 选择日期时间
* @param title 标题
* @param value 默认时间
* @param listener 监听器
*/
@Override
public Dialog selectDateTime(final CharSequence title, final Date value, final OnDateTimeSetListener listener) {
final Calendar calender = Calendar.getInstance();
calender.setTime(value);
int year = calender.get(Calendar.YEAR);
final int month = calender.get(Calendar.MONTH);
final int day = calender.get(Calendar.DAY_OF_MONTH);
final AlertDialog tDialog = new DatePickerDialog(mContext, new SafeListener((view, year1, month1, day1) -> {
int hour = calender.get(Calendar.HOUR_OF_DAY);
int minute = calender.get(Calendar.MINUTE);
Dialog tDialog1 = new TimePickerDialog(mContext, new SafeListener((OnTimeSetListener) (view1, hour1, minute1) -> listener.onDateTimeSet(year1, month1, day1, hour1, minute1)), hour, minute, true) {
@Override
public void show() {
super.show();
if (listener instanceof OnDateTimeSetVerifyListener) {
getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
try {
TimePicker picker = AfReflecter.getMemberByType(this, TimePicker.class);
if (picker == null) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
} else if (((OnDateTimeSetVerifyListener) listener).onPreTimeSet(picker, picker.getCurrentHour(), picker.getCurrentMinute())) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
}
}
};
;
if (title != null && title.length() > 0) {
tDialog1.setTitle(title);
}
tDialog1.show();
tDialog1.setCancelable(true);
}), year, month, day) {
@Override
public void show() {
super.show();
if (listener instanceof OnDateTimeSetVerifyListener) {
getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
try {
DatePicker picker = AfReflecter.getMemberByType(this, DatePicker.class);
if (picker == null) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
} else if (((OnDateTimeSetVerifyListener) listener).onPreDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth())) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
}
}
};
if (title != null && title.length() > 0) {
tDialog.setTitle(title);
}
tDialog.show();
tDialog.setCancelable(true);
return tDialog;
}
use of android.app.TimePickerDialog in project robolectric by robolectric.
the class ShadowTimePickerDialogTest method testGettersReturnInitialConstructorValues.
@Test
public void testGettersReturnInitialConstructorValues() {
TimePickerDialog timePickerDialog = new TimePickerDialog(ApplicationProvider.getApplicationContext(), 0, null, 6, 55, true);
ShadowTimePickerDialog shadow = shadowOf(timePickerDialog);
assertThat(shadow.getHourOfDay()).isEqualTo(6);
assertThat(shadow.getMinute()).isEqualTo(55);
assertThat(shadow.getIs24HourView()).isEqualTo(true);
}
Aggregations