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

The following examples show how to use android.app.TimePickerDialog#setTitle() . 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: 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 2
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 3
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 4
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 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: 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 7
Source File: TimeTableView.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) {
    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);
    }, 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);
    });

    dialog.show();
}
 
Example 8
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 9
Source File: TimePickerFragment.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final TimePickerDialog tp = new TimePickerDialog(getActivity(), this, this.hour, this.minute,
            DateFormat.is24HourFormat(getActivity()));
    if (title != null) tp.setTitle(title);
    return tp;
}
 
Example 10
Source File: TimePickerFragment.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final TimePickerDialog tp = new TimePickerDialog(getActivity(), this, this.hour, this.minute,
            DateFormat.is24HourFormat(getActivity()));
    if (title != null) tp.setTitle(title);
    return tp;
}
 
Example 11
Source File: CountDownView.java    From anvil-examples with MIT License 5 votes vote down vote up
public void onSetTime(View v) {
	TimePickerDialog picker = new TimePickerDialog(v.getContext(),
		TimePickerDialog.THEME_DEVICE_DEFAULT_LIGHT, (p, hour, minute) -> {
			App.dispatch(new CountdoneAction(CountdoneAction.Type.SET_DURATION, (hour * 60 + minute ) * 60 * 1000L));
		}, (int) App.state().currentTask().remainder()/60/60/1000,
		(int) (App.state().currentTask().remainder()/60/1000)%60, true);
	picker.setTitle(R.string.set_time_title);
	picker.show();
}