Search in sources :

Example 21 with TimePickerDialog

use of android.app.TimePickerDialog in project ttdj by soonphe.

the class ToolDateTimePicker method show.

public void show(Calendar calendar, final DateSelCallBack callBack) {
    if (calendar == null) {
        calendar = Calendar.getInstance();
    }
    switch(chooseType) {
        case DATE:
            new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
                    String date = formatDateTime(calendar.getTime(), DF_YYYY_MM_DD);
                    targetView.setText(date);
                    callBack.dateChange(calendar);
                }
            }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)).show();
            break;
        case TIME:
            new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
                    targetView.setText(formatDateTime(calendar.getTime(), DF_HH_MM_SS));
                }
            }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
            break;
        default:
            LinearLayout dateTimeLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.view_datetime, null);
            datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
            timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
            initDateTimePicker(datePicker, timePicker);
            timePicker.setIs24HourView(true);
            timePicker.setOnTimeChangedListener(mOnTimeChangedListener);
            dialog = new AlertDialog.Builder(context).setTitle(nowDateTime).setView(dateTimeLayout).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    targetView.setText(nowDateTime);
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    targetView.setText("");
                }
            }).show();
            mOnDateChangedListener.onDateChanged(null, 0, 0, 0);
            break;
    }
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) DatePicker(android.widget.DatePicker) LinearLayout(android.widget.LinearLayout)

Example 22 with TimePickerDialog

use of android.app.TimePickerDialog in project ttdj by soonphe.

the class ToolDateTimePicker method show.

public void show() {
    Calendar c = Calendar.getInstance();
    switch(chooseType) {
        case DATE:
            new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
                    targetView.setText(formatDateTime(calendar.getTime(), DF_YYYY_MM_DD));
                }
            }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE)).show();
            break;
        case TIME:
            new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
                    targetView.setText(formatDateTime(calendar.getTime(), DF_HH_MM_SS));
                }
            }, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
            break;
        default:
            LinearLayout dateTimeLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.view_datetime, null);
            datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
            timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
            initDateTimePicker(datePicker, timePicker);
            timePicker.setIs24HourView(true);
            timePicker.setOnTimeChangedListener(mOnTimeChangedListener);
            dialog = new AlertDialog.Builder(context).setTitle(nowDateTime).setView(dateTimeLayout).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    targetView.setText(nowDateTime);
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    targetView.setText("");
                }
            }).show();
            mOnDateChangedListener.onDateChanged(null, 0, 0, 0);
            break;
    }
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) DatePicker(android.widget.DatePicker) LinearLayout(android.widget.LinearLayout)

Example 23 with TimePickerDialog

use of android.app.TimePickerDialog in project opacclient by opacapp.

the class SnoozeDatePickerActivity method onDateSet.

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    dt = // Joda time has 1-based months
    dt.withYear(year).withMonthOfYear(monthOfYear + 1).withDayOfMonth(dayOfMonth);
    new TimePickerDialog(this, R.style.Theme_AppCompat_Light_Dialog, this, dt.getHourOfDay(), dt.getMinuteOfHour(), DateFormat.is24HourFormat(this)).show();
}
Also used : TimePickerDialog(android.app.TimePickerDialog)

Example 24 with TimePickerDialog

use of android.app.TimePickerDialog 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 25 with TimePickerDialog

use of android.app.TimePickerDialog in project robolectric by robolectric.

the class ShadowTimePickerDialogTest method testGettersReturnInitialConstructorValues.

@Test
public void testGettersReturnInitialConstructorValues() {
    TimePickerDialog timePickerDialog = new TimePickerDialog(ApplicationProvider.getApplicationContext(), 0, null, 6, 55, true);
    ShadowTimePickerDialog shadow = shadowOf(timePickerDialog);
    assertThat(shadow.getHourOfDay()).isEqualTo(6);
    assertThat(shadow.getMinute()).isEqualTo(55);
    assertThat(shadow.getIs24HourView()).isEqualTo(true);
}
Also used : TimePickerDialog(android.app.TimePickerDialog) Test(org.junit.Test)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)64 TimePicker (android.widget.TimePicker)27 Calendar (java.util.Calendar)25 View (android.view.View)20 DatePickerDialog (android.app.DatePickerDialog)15 TextView (android.widget.TextView)14 Context (android.content.Context)11 DialogInterface (android.content.DialogInterface)11 AlertDialog (android.app.AlertDialog)9 Button (android.widget.Button)8 CompoundButton (android.widget.CompoundButton)7 Bundle (android.os.Bundle)6 DatePicker (android.widget.DatePicker)6 LocalTime (java.time.LocalTime)6 FrameLayout (android.widget.FrameLayout)5 SuppressLint (android.annotation.SuppressLint)4 Intent (android.content.Intent)4 LinearLayout (android.widget.LinearLayout)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4