Java Code Examples for android.app.TimePickerDialog#show()

The following examples show how to use android.app.TimePickerDialog#show() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CVDatePreference.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    if (positiveResult) {
        v.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
        cv.put(getKey(), v.getTimeInMillis());
        if (ul != null) {
            ul.onUpdateValue(this);
        }
        if (dt) {
            TimePickerDialog tpd = new TimePickerDialog(getContext(), this,
                    v.get(Calendar.HOUR_OF_DAY), v.get(Calendar.MINUTE), true);
            tpd.setTitle(getTitle());
            tpd.setCancelable(true);
            tpd.show();
        }
    }
}
 
Example 2
Source File: TimePickerListener.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onClick(View v)
{
    if(edittext == null) {
        return;
    }

    String[] time;

    if(edittext.getText().toString().equals("")) {
        Calendar c = Calendar.getInstance();
        time = new String[2];
        time[0] = (c.get(Calendar.HOUR_OF_DAY) < 10) ? "0" + c.get(Calendar.HOUR_OF_DAY) : "" + c.get(Calendar.HOUR_OF_DAY);
        time[1] = (c.get(Calendar.MINUTE) < 10) ? "0" + c.get(Calendar.MINUTE) : "" + c.get(Calendar.MINUTE);
    } else {
        time = edittext.getText().toString().split(":");
    }

    TimePickerDialog dialog = new TimePickerDialog(context, timePickerListener, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true);

    dialog.show();
}
 
Example 3
Source File: AddRouteActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
private void setupTimePicker(){
    // Get Current Time
    Calendar c = Calendar.getInstance();
    int mHour = c.get(Calendar.HOUR_OF_DAY);
    int mMinute = c.get(Calendar.MINUTE);

    // Launch Time Picker Dialog
    TimePickerDialog timePickerDialog = new TimePickerDialog(this,R.style.TimePickerTheme,
            new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay,
                                      int minute) {
                    Toast.makeText(AddRouteActivity.this,Integer.toString(hourOfDay),Toast.LENGTH_SHORT).show();
                    String time_string=Integer.toString(hourOfDay)+":"+Integer.toString(minute);
                    time.setText(time_string);

                }
            }, mHour, mMinute, false);
    timePickerDialog.show();
}
 
Example 4
Source File: SelfRouteDetailActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
/********************** Custom Functions *********************/
//Creates the dialog for time picking
public void setupTimePickerDialog(){
    // Get Current Time
    Calendar c = Calendar.getInstance();
    int mHour = c.get(Calendar.HOUR_OF_DAY);
    int mMinute = c.get(Calendar.MINUTE);

    // Launch Time Picker Dialog
    TimePickerDialog timePickerDialog = new TimePickerDialog(this,R.style.TimePickerTheme,
            new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay,
                                      int minute) {
                    Toast.makeText(SelfRouteDetailActivity.this,Integer.toString(hourOfDay),Toast.LENGTH_SHORT).show();
                    String time_string=Integer.toString(hourOfDay)+":"+Integer.toString(minute);
                    time.setText(time_string);

                }
            }, mHour, mMinute, false);
    timePickerDialog.show();
}
 
Example 5
Source File: FragmentDarkThemeViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onClickToTime(View v) {

        sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
        int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_TO, 8);
        int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, 0);

        TimePickerDialog mTimePicker = new TimePickerDialog(G.currentActivity, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                long fNow = (selectedHour * 3600000) + (selectedMinute * 60000);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putInt(SHP_SETTING.KEY_SELECTED_HOUR_TO, selectedHour);
                editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, selectedMinute);
                editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_TO, fNow);
                editor.apply();
                callbackToTime.set("" + selectedHour + ":" + selectedMinute);
            }
        }, hour, minute, true);//Yes 24 hour time
        mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
        mTimePicker.show();

    }
 
Example 6
Source File: FragmentDarkThemeViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onClickFromTime(View v) {
    sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
    int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, 8);
    int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, 0);

    TimePickerDialog mTimePicker = new TimePickerDialog(G.currentActivity, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
            long fNow = (selectedHour * 3600000) + (selectedMinute * 60000);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, selectedHour);
            editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, selectedMinute);
            editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_FROM, fNow);
            editor.apply();
            callbackFromTime.set("" + selectedHour + ":" + selectedMinute);
        }
    }, hour, minute, true);//Yes 24 hour time
    mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
    mTimePicker.show();

}
 
Example 7
Source File: PreferencesFragment.java    From HouSi with Apache License 2.0 6 votes vote down vote up
private void showTimePicker() {
    final Calendar calendar = Calendar.getInstance();

    String startTime = QueryPreferences.getSettingServiceStartTime(getContext());
    if (startTime != null) {
        calendar.setTimeInMillis(Long.parseLong(startTime));
    }

    TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(),
            new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);

                    QueryPreferences.setSettingServiceStartTime(getContext(), calendar.getTimeInMillis() + "");
                    mSettingServiceStartTime.setSummary(SERVICE_START_TIME_FORMAT.format(calendar.getTime()));
                }
            },
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            true);
    timePickerDialog.setTitle("设置时间");
    timePickerDialog.show();
}
 
Example 8
Source File: OCM_ChildMenu.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
void showPickTimeDialog (final TimePickerDialog.OnTimeSetListener listener)
{
    final DatePickerDialog.OnDateSetListener dateListener = (DatePickerDialog.OnDateSetListener) listener;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity));
    //
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    //
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick (DialogInterface dialog, int which)
        {
            showPickDateDialog(dateListener, null);
        }
    });
    //
    LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext());
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setCustomTitle(linearLayout);
    //
    d.show();
}
 
Example 9
Source File: DateTimeView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showTimePicker(View view) {
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());

    TimePickerDialog dialog = new TimePickerDialog(getContext(), (
            timePicker, hourOfDay, minutes) -> {
        selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        selectedCalendar.set(Calendar.MINUTE, minutes);
        Date selectedDate = selectedCalendar.getTime();
        String result = dateFormat.format(selectedDate);
        editText.setText(result);
        listener.onDateSelected(selectedDate);
        nextFocus(view);
        date = null;
    },
            hour,
            minute,
            is24HourFormat);
    dialog.setTitle(binding.getLabel());
    dialog.show();
}
 
Example 10
Source File: DateTimeTableView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showTimePicker(View view) {
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());

    TimePickerDialog dialog = new TimePickerDialog(getContext(), (
            timePicker, hourOfDay, minutes) -> {
        selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        selectedCalendar.set(Calendar.MINUTE, minutes);
        Date selectedDate = selectedCalendar.getTime();
        String result = DateUtils.timeFormat().format(selectedDate);
        textView.setText(result);
        listener.onDateSelected(selectedDate);
        nextFocus(view);
    },
            hour,
            minute,
            is24HourFormat);
    dialog.setTitle(label);
    dialog.show();
}
 
Example 11
Source File: OBSetupMenu.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
void showPickTimeDialog (final TimePickerDialog.OnTimeSetListener listener)
{
    final DatePickerDialog.OnDateSetListener dateListener = (DatePickerDialog.OnDateSetListener) listener;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity));
    //
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    //
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick (DialogInterface dialog, int which)
        {
            if (screenType == ScreenType.SET_DATE_SCREEN)
            {
                showPickDateDialog(dateListener, null);
            }
            else
            {
                MainActivity.log("OBSetupMenu:showPickTimeDialog:cancelled!");
            }
        }
    });
    //
    LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext());
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setCustomTitle(linearLayout);
    //
    d.show();
}
 
Example 12
Source File: TimeView.java    From Viewer with Apache License 2.0 5 votes vote down vote up
private void showTimeDlg(final TextView textView) {
    TimePickerDialog pickdialog = new TimePickerDialog(mContext,
            new OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay,
                        int minute) {
                    textView.setText(String.format("%02d:%02d", hourOfDay,
                            minute));
                }
            }, 0, 0, true);
    pickdialog.show();
}
 
Example 13
Source File: TimeView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onClick(View view) {
    activate();
    final Calendar c = Calendar.getInstance();
    if (date != null)
        c.setTime(date);

    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean is24HourFormat = DateFormat.is24HourFormat(getContext());
    SimpleDateFormat twentyFourHourFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
    SimpleDateFormat twelveHourFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
    TimePickerDialog dialog = new TimePickerDialog(getContext(), (timePicker, hourOfDay, minutes) -> {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        calendar.set(Calendar.MINUTE, minutes);
        Date selectedDate = calendar.getTime();
        String calendarTime;

        if (is24HourFormat) {
            calendarTime = twentyFourHourFormat.format(selectedDate);
            editText.setText(calendarTime);
        } else {
            calendarTime = twelveHourFormat.format(selectedDate);
            editText.setText(calendarTime);
        }
        listener.onDateSelected(selectedDate);
        nextFocus(view);
        date = null;
    }, hour, minute, is24HourFormat);
    dialog.setTitle(label);

    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getContext().getString(R.string.date_dialog_clear), (timeDialog, which) -> {
        editText.setText(null);
        listener.onDateSelected(null);
        date=null;
    });

    dialog.show();
}
 
Example 14
Source File: FormTimeDialogFieldCell.java    From QMBForm with MIT License 5 votes vote down vote up
@Override
public void onCellSelected() {
    super.onCellSelected();

    TimePickerDialog dialog = new TimePickerDialog(getContext(), this, getCalendar().get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), true);
    dialog.show();

}
 
Example 15
Source File: TextNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(TextNoteActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example 16
Source File: SketchActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(SketchActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example 17
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(ChecklistNoteActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example 18
Source File: AudioNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(AudioNoteActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example 19
Source File: SystemUpdatePolicyFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private void selectTime(final boolean isWindowStart) {
    int defaultMinutes = isWindowStart ? mMaintenanceStart : mMaintenanceEnd;
    TimePickerDialog timePicker = new TimePickerDialog(getActivity(), (picker, hour, minutes) -> {
        if (isWindowStart) {
            mMaintenanceStart = hour * 60 + minutes;
        } else {
            mMaintenanceEnd = hour * 60 + minutes;
        }
        updateMaintenanceWindowDisplay();
    }, defaultMinutes / 60, defaultMinutes % 60, true);
    timePicker.show();
}
 
Example 20
Source File: InactiveTimePreference.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    final Data data = v == mFrom.labelTextView ? mFrom : mTo;

    TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(),
            new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    data.setTime(getContext(), selectedHour, selectedMinute);
                }
            }, data.hours, data.minutes, true
    );
    timePickerDialog.show();
}