Search in sources :

Example 61 with TimePickerDialog

use of android.app.TimePickerDialog in project incubator-weex by apache.

the class DatePickerImpl method pickTime.

public static void pickTime(@NonNull Context context, String value, @NonNull final OnPickListener listener, @Nullable Map<String, Object> extras) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(parseTime(value));
    TimePickerDialog dialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            String h = hourOfDay < 10 ? "0" + hourOfDay : String.valueOf(hourOfDay);
            String m = minute < 10 ? "0" + minute : String.valueOf(minute);
            String result = h + ":" + m;
            listener.onPick(true, result);
        }
    }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            listener.onPick(false, null);
        }
    });
    setButtonText(dialog, DialogInterface.BUTTON_NEGATIVE, String.valueOf(extras != null ? extras.get("cancelTitle") : null));
    setButtonText(dialog, DialogInterface.BUTTON_POSITIVE, String.valueOf(extras != null ? extras.get("confirmTitle") : null));
    dialog.show();
}
Also used : TimePicker(android.widget.TimePicker) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog)

Example 62 with TimePickerDialog

use of android.app.TimePickerDialog in project android_packages_apps_Settings by SudaMod.

the class NightDisplaySettings method onCreateDialog.

@Override
public Dialog onCreateDialog(final int dialogId) {
    if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) {
        final LocalTime initialTime;
        if (dialogId == DIALOG_START_TIME) {
            initialTime = mController.getCustomStartTime();
        } else {
            initialTime = mController.getCustomEndTime();
        }
        final Context context = getContext();
        final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
        return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                final LocalTime time = LocalTime.of(hourOfDay, minute);
                if (dialogId == DIALOG_START_TIME) {
                    mController.setCustomStartTime(time);
                } else {
                    mController.setCustomEndTime(time);
                }
            }
        }, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
    }
    return super.onCreateDialog(dialogId);
}
Also used : Context(android.content.Context) TimePicker(android.widget.TimePicker) LocalTime(java.time.LocalTime) TimePickerDialog(android.app.TimePickerDialog)

Example 63 with TimePickerDialog

use of android.app.TimePickerDialog in project iNaturalistAndroid by inaturalist.

the class TimePickerFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    String currentHour = mDate.getText().toString();
    Calendar c;
    mIsCanceled = false;
    if (currentHour.equals("")) {
        // Use the current hour as the default hour in the picker
        c = Calendar.getInstance();
    } else {
        Date date;
        c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, Integer.valueOf(currentHour.split(":")[0]));
        c.set(Calendar.MINUTE, Integer.valueOf(currentHour.split(":")[1]));
    }
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    // Create a new instance of TimePickerDialog and return it
    TimePickerDialog dialog = new TimePickerDialog(getActivity(), this, hour, minute, true);
    dialog.setOnCancelListener(this);
    dialog.setOnDismissListener(this);
    return dialog;
}
Also used : Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) Date(java.util.Date)

Example 64 with TimePickerDialog

use of android.app.TimePickerDialog in project platform_packages_apps_Settings by BlissRoms.

the class NightDisplaySettings method onCreateDialog.

@Override
public Dialog onCreateDialog(final int dialogId) {
    if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) {
        final LocalTime initialTime;
        if (dialogId == DIALOG_START_TIME) {
            initialTime = mController.getCustomStartTime();
        } else {
            initialTime = mController.getCustomEndTime();
        }
        final Context context = getContext();
        final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
        return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                final LocalTime time = LocalTime.of(hourOfDay, minute);
                if (dialogId == DIALOG_START_TIME) {
                    mController.setCustomStartTime(time);
                } else {
                    mController.setCustomEndTime(time);
                }
            }
        }, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
    }
    return super.onCreateDialog(dialogId);
}
Also used : Context(android.content.Context) TimePicker(android.widget.TimePicker) LocalTime(java.time.LocalTime) TimePickerDialog(android.app.TimePickerDialog)

Example 65 with TimePickerDialog

use of android.app.TimePickerDialog in project cyborg-core by nu-art.

the class DateTimePicker method timePicker.

/**
 * Show only a time picker
 */
public void timePicker() {
    TimePickerDialog timePickerDialog = new TimePickerDialog(activity, new TimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute);
            listener.onDateTimeChanged();
        }
    }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);
    timePickerDialog.show();
}
Also used : TimePicker(android.widget.TimePicker) TimePickerDialog(android.app.TimePickerDialog)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)66 TimePicker (android.widget.TimePicker)30 Calendar (java.util.Calendar)26 View (android.view.View)23 TextView (android.widget.TextView)16 DatePickerDialog (android.app.DatePickerDialog)15 DialogInterface (android.content.DialogInterface)12 Context (android.content.Context)11 AlertDialog (android.app.AlertDialog)9 Button (android.widget.Button)8 CompoundButton (android.widget.CompoundButton)8 Bundle (android.os.Bundle)7 DatePicker (android.widget.DatePicker)6 LocalTime (java.time.LocalTime)6 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)5 Date (java.util.Date)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (android.support.annotation.Nullable)4 LinearLayout (android.widget.LinearLayout)4