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

The following examples show how to use android.app.TimePickerDialog#setButton() . 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: OBSystemsManager.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public Dialog createTimeSetDialog(OBUtils.RunLambda completionBlock, final OBUtils.RunLambda cancelCompletionBlock)
{
    timeSetCompletionBlock = completionBlock;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, this, 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)
        {
            OBUtils.runOnMainThread(cancelCompletionBlock);
        }
    });
    d.setMessage("Please set the current time.\n");
    return d;
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: TimePickerProxy.java    From TiDialogs with MIT License 4 votes vote down vote up
private TimePickerDialog getDialog() {
	TimePickerDialog picker = new TimePickerDialog(this.proxy.getActivity(),
				new TimePickerDialog.OnTimeSetListener() {

					@Override
					public void onTimeSet(TimePicker selectedTime,
							int selectedHour, int selectedMinute) {
						// TODO Auto-generated method stub

						hour = selectedHour;
						minute = selectedMinute;

						KrollDict data = new KrollDict();

							Calendar calendar = Calendar.getInstance();
							calendar.set(Calendar.HOUR_OF_DAY, hour);
							calendar.set(Calendar.MINUTE, minute);
							Date value = calendar.getTime();

							data.put("value", value);
							data.put("hour", hour);
							data.put("minute", minute);
                                  fireEvent("click", data);

					}
				}, hour, minute, DateFormat.is24HourFormat(this.proxy
						.getActivity()));

	picker.setCanceledOnTouchOutside(false);

	picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);

	picker.setButton(DialogInterface.BUTTON_NEGATIVE, cancelButtonTitle,
		new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				fireEvent("cancel", new KrollDict());
			}
		});

	return picker;
}