Search in sources :

Example 51 with TimePickerDialog

use of android.app.TimePickerDialog in project bookish-tribble by Hestvik-Dymbe.

the class AddTask method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_task);
    mDisplayDate = (TextView) findViewById(R.id.dateView);
    mDisplayTime = (TextView) findViewById(R.id.timeView);
    addButton = (Button) findViewById(R.id.add_button);
    mDisplayDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH);
            int day = cal.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog dialog = new DatePickerDialog(AddTask.this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, mDateSetListener, year, month, day);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.show();
        }
    });
    mDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
            month = month + 1;
            Log.d(TAG, "onDateSet: mm/dd/yyy: " + month + "/" + day + "/" + year);
            String date = day + "/" + month + "/" + year;
            mDisplayDate.setText(date);
        }
    };
    mDisplayTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Calendar mcurrentTime = Calendar.getInstance();
            int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
            int minute = mcurrentTime.get(Calendar.MINUTE);
            TimePickerDialog mTimePicker;
            mTimePicker = new TimePickerDialog(AddTask.this, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    mDisplayTime.setText(selectedHour + ":" + selectedMinute);
                }
            }, hour, minute, // Yes 24 hour time
            true);
            mTimePicker.setTitle("Select Time");
            mTimePicker.show();
        }
    });
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            buttonPress();
        }
    });
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) TextView(android.widget.TextView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) DatePicker(android.widget.DatePicker)

Example 52 with TimePickerDialog

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

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 53 with TimePickerDialog

use of android.app.TimePickerDialog in project open-event-orga-app by fossasia.

the class DateBindings method bindTime.

@BindingAdapter("time")
public static void bindTime(Button button, ObservableField<String> time) {
    String format = DateUtils.FORMAT_24H;
    bindTemporal(button, time, format, zonedDateTime -> new TimePickerDialog(button.getContext(), (picker, hourOfDay, minute) -> setPickedDate(LocalDateTime.of(zonedDateTime.toLocalDate(), LocalTime.of(hourOfDay, minute)), button, format, time), zonedDateTime.getHour(), zonedDateTime.getMinute(), true));
}
Also used : BindingAdapter(android.databinding.BindingAdapter) TimePickerDialog(android.app.TimePickerDialog) LocalTime(org.threeten.bp.LocalTime) LocalDate(org.threeten.bp.LocalDate) ZonedDateTime(org.threeten.bp.ZonedDateTime) Timber(timber.log.Timber) AlertDialog(android.app.AlertDialog) DatePickerDialog(android.app.DatePickerDialog) DateUtils(org.fossasia.openevent.app.utils.DateUtils) Function(org.fossasia.openevent.app.common.Function) LocalDateTime(org.threeten.bp.LocalDateTime) Button(android.widget.Button) DateTimeParseException(org.threeten.bp.format.DateTimeParseException) ObservableField(android.databinding.ObservableField) TimePickerDialog(android.app.TimePickerDialog) BindingAdapter(android.databinding.BindingAdapter)

Example 54 with TimePickerDialog

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

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 55 with TimePickerDialog

use of android.app.TimePickerDialog in project fitness-app by seemoo-lab.

the class UploadInteraction method selectTime.

/**
 * Lets the user select time of the alarm to override.
 */
private void selectTime() {
    final int hours;
    final int minutes;
    if (((Alarm) alarms.get(position)).isEmpty()) {
        Calendar calendar = Calendar.getInstance();
        hours = calendar.get(Calendar.HOUR_OF_DAY);
        minutes = calendar.get(Calendar.MINUTE);
    } else {
        hours = ((Alarm) alarms.get(position)).getHours();
        minutes = ((Alarm) alarms.get(position)).getMinutes();
    }
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            TimePickerDialog mTimePickerDialog = new TimePickerDialog(activity, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hour, int minute) {
                    secondsAfterMidnight = hour * 3600 + minute * 60;
                    selectRepeat();
                }
            }, hours, minutes, true);
            mTimePickerDialog.setTitle("Select time:");
            mTimePickerDialog.setButton(TimePickerDialog.BUTTON_NEGATIVE, "", mTimePickerDialog);
            mTimePickerDialog.setCancelable(false);
            mTimePickerDialog.show();
        }
    });
}
Also used : TimePicker(android.widget.TimePicker) Alarm(seemoo.fitbit.information.Alarm) Calendar(java.util.Calendar) 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