Search in sources :

Example 1 with DatePickerDialog

use of com.fourmob.datetimepicker.date.DatePickerDialog 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);
        }
    }
}
Also used : DatePickerDialog(com.fourmob.datetimepicker.date.DatePickerDialog) Calendar(java.util.Calendar) OnClickListener(android.view.View.OnClickListener) TimePickerDialog(com.sleepbot.datetimepicker.time.TimePickerDialog) View(android.view.View)

Example 2 with DatePickerDialog

use of com.fourmob.datetimepicker.date.DatePickerDialog 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();
}
Also used : DatePickerDialog(com.fourmob.datetimepicker.date.DatePickerDialog) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) RadialPickerLayout(com.sleepbot.datetimepicker.time.RadialPickerLayout) TimePickerDialog(com.sleepbot.datetimepicker.time.TimePickerDialog) View(android.view.View) TextView(android.widget.TextView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView)

Aggregations

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 DatePickerDialog (com.fourmob.datetimepicker.date.DatePickerDialog)2 TimePickerDialog (com.sleepbot.datetimepicker.time.TimePickerDialog)2 Calendar (java.util.Calendar)2 DialogInterface (android.content.DialogInterface)1 TextView (android.widget.TextView)1 RadialPickerLayout (com.sleepbot.datetimepicker.time.RadialPickerLayout)1