use of com.sleepbot.datetimepicker.time.TimePickerDialog in project datetimepicker by flavienlaurent.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Calendar calendar = Calendar.getInstance();
final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), isVibrate());
final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, false);
findViewById(R.id.dateButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
datePickerDialog.setVibrate(isVibrate());
datePickerDialog.setYearRange(1985, 2028);
datePickerDialog.setCloseOnSingleTapDay(isCloseOnSingleTapDay());
datePickerDialog.show(getSupportFragmentManager(), DATEPICKER_TAG);
}
});
findViewById(R.id.timeButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timePickerDialog.setVibrate(isVibrate());
timePickerDialog.setCloseOnSingleTapMinute(isCloseOnSingleTapMinute());
timePickerDialog.show(getSupportFragmentManager(), TIMEPICKER_TAG);
}
});
if (savedInstanceState != null) {
DatePickerDialog dpd = (DatePickerDialog) getSupportFragmentManager().findFragmentByTag(DATEPICKER_TAG);
if (dpd != null) {
dpd.setOnDateSetListener(this);
}
TimePickerDialog tpd = (TimePickerDialog) getSupportFragmentManager().findFragmentByTag(TIMEPICKER_TAG);
if (tpd != null) {
tpd.setOnTimeSetListener(this);
}
}
}
use of com.sleepbot.datetimepicker.time.TimePickerDialog in project AisenWeiBo by wangdan.
the class PublishStatusFragment method setTiming.
// 设置定时发布
private void setTiming() {
final Calendar calendar = Calendar.getInstance();
if (getPublishBean().getTiming() > 0)
calendar.setTimeInMillis(getPublishBean().getTiming());
View contentView = View.inflate(getActivity(), R.layout.lay_publish_timing, null);
final TextView btnDate = (TextView) contentView.findViewById(R.id.txtDate);
final TextView btnTime = (TextView) contentView.findViewById(R.id.txtTime);
btnTime.setText(DateUtils.formatDate(calendar.getTimeInMillis(), getString(R.string.publish_date_format_hm)));
DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
Logger.v(TAG, String.format("onDateSet:yeat=%d, month = %d, day = %d", year, month, day));
if (checkTiming(year, month, day, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE))) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
Calendar c = Calendar.getInstance();
if (month == c.get(Calendar.MONTH) && day == c.get(Calendar.DAY_OF_MONTH)) {
btnDate.setText(R.string.publish_today);
} else {
btnDate.setText(DateUtils.formatDate(calendar.getTimeInMillis(), getString(R.string.publish_date_format_md)));
}
btnTime.performClick();
}
}
};
TimePickerDialog.OnTimeSetListener onTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
Logger.v(TAG, String.format("onTimeSet:hourOfDay = %d, minute = %d", hourOfDay, minute));
if (checkTiming(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute)) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
btnTime.setText(DateUtils.formatDate(calendar.getTimeInMillis(), getString(R.string.publish_date_format_hm)));
}
}
};
final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(onDateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), true);
final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(onTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, false);
OnClickListener timingOnClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
// 设置日期
if (v.getId() == R.id.txtDate) {
datePickerDialog.setVibrate(false);
datePickerDialog.setYearRange(calendar.get(Calendar.YEAR), calendar.get(Calendar.YEAR));
datePickerDialog.setCloseOnSingleTapDay(false);
datePickerDialog.show(getFragmentManager(), "DatePickerDialog");
} else // 设置时间
if (v.getId() == R.id.txtTime) {
timePickerDialog.setVibrate(false);
timePickerDialog.setStartTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
timePickerDialog.setCloseOnSingleTapMinute(false);
timePickerDialog.show(getFragmentManager(), "TimePickerDialog");
}
}
};
btnDate.setOnClickListener(timingOnClickListener);
btnTime.setOnClickListener(timingOnClickListener);
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.publish_timing_set_title).setView(contentView).setCancelable(false).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// FIXME
// getPublishBean().setTiming(System.currentTimeMillis() + 15 * 1000);
calendar.set(Calendar.SECOND, 0);
getPublishBean().setTiming(calendar.getTimeInMillis() / 1000 * 1000);
getActivity().invalidateOptionsMenu();
setTimingHint();
}
}).show();
}
Aggregations