Search in sources :

Example 1 with OnTimeSetListener

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;
}
Also used : AlertDialog(android.app.AlertDialog) Builder(android.app.AlertDialog.Builder) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) LinearLayout(android.widget.LinearLayout) OnClickListener(android.content.DialogInterface.OnClickListener) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) Date(java.util.Date) Dialog(android.app.Dialog) AfDensity(com.andframe.util.android.AfDensity) DatePicker(android.widget.DatePicker) Stack(java.util.Stack) SuppressLint(android.annotation.SuppressLint) Calendar(java.util.Calendar) DatePickerDialog(android.app.DatePickerDialog) CheckBox(android.widget.CheckBox) AfActivity(com.andframe.activity.AfActivity) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) OnCancelListener(android.content.DialogInterface.OnCancelListener) OnShowListener(android.content.DialogInterface.OnShowListener) Build(android.os.Build) OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) TargetApi(android.annotation.TargetApi) DialogInterface(android.content.DialogInterface) OnTimeSetListener(android.app.TimePickerDialog.OnTimeSetListener) SafeListener(com.andframe.listener.SafeListener) ProgressDialog(android.app.ProgressDialog) InputType(android.text.InputType) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) AfExceptionHandler(com.andframe.exception.AfExceptionHandler) AlertDialog(android.app.AlertDialog) DialogBuilder(com.andframe.api.DialogBuilder) Gravity(android.view.Gravity) LayoutParams(android.view.ViewGroup.LayoutParams) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) com.andframe.$(com.andframe.$) RelativeLayout(android.widget.RelativeLayout) TimePicker(android.widget.TimePicker) AfReflecter(com.andframe.util.java.AfReflecter) Window(android.view.Window) EditText(android.widget.EditText) TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) SuppressLint(android.annotation.SuppressLint) TimePickerDialog(android.app.TimePickerDialog) Dialog(android.app.Dialog) DatePickerDialog(android.app.DatePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.app.AlertDialog) SafeListener(com.andframe.listener.SafeListener) DatePicker(android.widget.DatePicker)

Example 2 with OnTimeSetListener

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();
}
Also used : TimePicker(android.widget.TimePicker) OnTimeSetListener(android.app.TimePickerDialog.OnTimeSetListener) TimePickerDialog(android.app.TimePickerDialog) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)2 OnTimeSetListener (android.app.TimePickerDialog.OnTimeSetListener)2 TimePicker (android.widget.TimePicker)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 Builder (android.app.AlertDialog.Builder)1 DatePickerDialog (android.app.DatePickerDialog)1 OnDateSetListener (android.app.DatePickerDialog.OnDateSetListener)1 Dialog (android.app.Dialog)1 ProgressDialog (android.app.ProgressDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 OnMultiChoiceClickListener (android.content.DialogInterface.OnMultiChoiceClickListener)1 OnShowListener (android.content.DialogInterface.OnShowListener)1 Build (android.os.Build)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1