Search in sources :

Example 1 with RadialPickerLayout

use of com.sleepbot.datetimepicker.time.RadialPickerLayout 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

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