use of android.app.TimePickerDialog.OnTimeSetListener 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.OnTimeSetListener in project android-app-common-tasks by multidots.
the class Common method showTimePickerDialog.
/**
* show timepicker
*
* @param mContext
* @param mTextView formar of the time
* @return show timepicker
*/
public static void showTimePickerDialog(final Context mContext, final TextView mTextView) {
new TimePickerDialog(mContext, new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm a");
dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateTime.set(Calendar.MINUTE, minute);
mTextView.setText(timeFormatter.format(dateTime.getTime()));
}
}, dateTime.get(Calendar.HOUR_OF_DAY), dateTime.get(Calendar.MINUTE), false).show();
}
Aggregations