Example usage for android.app DatePickerDialog DatePickerDialog

List of usage examples for android.app DatePickerDialog DatePickerDialog

Introduction

In this page you can find the example usage for android.app DatePickerDialog DatePickerDialog.

Prototype

public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month,
        int dayOfMonth) 

Source Link

Document

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

Usage

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void deferTasks(List<Task> tasks, final int dateType) {
    final List<Task> tasksToDefer = tasks;
    Dialog d = Util.createDeferDialog(this, dateType, true, new Util.InputDialogListener() {
        @Override//from www .ja va  2s . c o m
        public void onClick(@Nullable String selected) {
            if (selected == null) {
                Log.w(TAG, "Can't defer, selected is null. This should not happen");
                return;
            }
            if (selected.equals("pick")) {
                final DateTime today = DateTime.today(TimeZone.getDefault());
                DatePickerDialog dialog = new DatePickerDialog(Simpletask.this,
                        new DatePickerDialog.OnDateSetListener() {
                            @Override
                            public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                month++;

                                DateTime date = DateTime.forDateOnly(year, month, day);
                                getTaskBag().defer(date.format(Constants.DATE_FORMAT), tasksToDefer, dateType);

                            }
                        }, today.getYear(), today.getMonth() - 1, today.getDay());
                boolean showCalendar = m_app.showCalendar();

                dialog.getDatePicker().setCalendarViewShown(showCalendar);
                dialog.getDatePicker().setSpinnersShown(!showCalendar);
                dialog.show();
            } else {
                getTaskBag().defer(selected, tasksToDefer, dateType);
            }
        }
    });
    d.show();
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java

void setupStartEndDatePickers(View rootView) {

    if (schedule.start() == null) {
        schedule.setStart(LocalDate.now());
    }//  w w  w. j a v  a 2 s.  com

    final LocalDate scheduleStart = schedule.start();

    buttonScheduleStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Log.d(TAG, year + " " + monthOfYear);
                            LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth);
                            setScheduleStart(d);
                        }
                    }, scheduleStart.getYear(), scheduleStart.getMonthOfYear() - 1,
                    scheduleStart.getDayOfMonth());
            dpd.show();
        }
    });

    buttonScheduleEnd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            LocalDate scheduleEnd = schedule.end() != null ? schedule.end() : scheduleStart.plusMonths(3);

            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth);
                            setScheduleEnd(d);
                        }
                    }, scheduleEnd.getYear(), scheduleEnd.getMonthOfYear() - 1, scheduleEnd.getDayOfMonth());
            dpd.show();
        }
    });

    buttonScheduleEnd.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage("Do you want this schedule to continue indefinitely?").setCancelable(true)
                    .setPositiveButton(getString(R.string.dialog_yes_option),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    setScheduleEnd(null);
                                }
                            })
                    .setNegativeButton(getString(R.string.dialog_no_option),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });
            AlertDialog alert = builder.create();
            alert.show();
            return true;
        }
    });

    clearStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setScheduleStart(null);
        }
    });

    clearEndButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setScheduleEnd(null);
        }
    });

    setScheduleStart(schedule.start());
    setScheduleEnd(schedule.end());
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupStartEndDatePickers(View rootView) {

    if (schedule.start() == null) {
        schedule.setStart(LocalDate.now());
    }//  w  w  w  . j  a v a2  s  .  co  m

    final LocalDate scheduleStart = schedule.start();

    buttonScheduleStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Log.d(TAG, year + " " + monthOfYear);
                            LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth);
                            setScheduleStart(d);
                        }
                    }, scheduleStart.getYear(), scheduleStart.getMonthOfYear() - 1,
                    scheduleStart.getDayOfMonth());
            dpd.show();
        }
    });

    buttonScheduleEnd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            LocalDate scheduleEnd = schedule.end() != null ? schedule.end() : scheduleStart.plusMonths(3);

            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            LocalDate d = new LocalDate(year, monthOfYear + 1, dayOfMonth);
                            setScheduleEnd(d);
                        }
                    }, scheduleEnd.getYear(), scheduleEnd.getMonthOfYear() - 1, scheduleEnd.getDayOfMonth());
            dpd.show();
        }
    });

    buttonScheduleEnd.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage("Do you want this schedule to continue indefinitely?").setCancelable(true)
                    .setPositiveButton(getString(R.string.dialog_yes_option),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    setScheduleEnd(null);
                                }
                            })
                    .setNegativeButton(getString(R.string.dialog_no_option),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });
            AlertDialog alert = builder.create();
            alert.show();
            return true;
        }
    });

    clearStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setScheduleStart(null);
        }
    });
    clearEndButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setScheduleEnd(null);
        }
    });

    setScheduleStart(schedule.start());

    if (schedule.end() == null && isNew && hasEnd && daysToEnd > 0) {
        LocalDate end = schedule.start().plusDays(daysToEnd);
        setScheduleEnd(end);
    } else {
        setScheduleEnd(schedule.end());
    }
}

From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showStartsOnDateDialog() {
    Calendar startDateCalendar = Calendar.getInstance();
    startDateCalendar.setTime(startDate);

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override//w  w w  .  ja  va2s.com
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            long diff = endDate.getTime() - startDate.getTime();

            startDate = DateUtils.setYears(startDate, year);
            startDate = DateUtils.setMonths(startDate, monthOfYear);
            startDate = DateUtils.setDays(startDate, dayOfMonth);
            updateStartDateButtons();

            endDate.setTime(startDate.getTime() + diff);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            startDateCalendar.get(Calendar.YEAR), startDateCalendar.get(Calendar.MONTH),
            startDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_start_date);
    datePickerDialog.show();
}

From source file:dev.memento.MainActivity.java

public void showDatePicker(View v) {

    // Date picker's months range from 0-11
    final DatePickerDialog dateDialog = new DatePickerDialog(this, null, mDateChosen.getYear(),
            mDateChosen.getMonth() - 1, mDateChosen.getDay());

    // Have to set positive and negative buttons because only a positive button
    // will be displayed by default, and there is a bug in Android that causes
    // the Back button (which should normally be used to cancel) to cause
    // the onDateTime event handler to be triggered.  
    // http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel

    // If either of the buttons are set with .setButton(), the OnDateSetListener is 
    // not triggered on my Galaxy Tab (Android 4.0.4), so implement listening here instead.

    dateDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.button_set),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    DatePicker dp = dateDialog.getDatePicker();
                    dateSelected(dp.getDayOfMonth(), dp.getMonth(), dp.getYear());
                }/* w ww . jav  a2  s.c o  m*/
            });

    dateDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // Nothing to do
                    if (Log.LOG)
                        Log.d(LOG_TAG, "Cancel was pressed");
                }
            });

    dateDialog.show();
}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

private Dialog createDialogDate() {
    return new DatePickerDialog(getActivity(), mDateSetListener, mTime.year, mTime.month, mTime.monthDay);
}

From source file:com.hackensack.umc.activity.DependentDetailsActivity.java

public void showDatePickerDialog(Context context, final TextView tv) {

    DatePickerDialog dDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {

        @Override//from   w  w  w.  ja  v  a  2s .c o  m
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

            mMonth = monthOfYear;
            mDay = dayOfMonth;
            mYear = year;

            Calendar calendar = Calendar.getInstance();
            calendar.set(year, monthOfYear, dayOfMonth);

            birthDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
            String birthDateToshow = new SimpleDateFormat("MM-dd-yyyy").format(calendar.getTime());

            // birthDate = format.(calendar.getTime());
            Log.v(TAG, "strDate is::" + birthDateToshow);
            tv.setText(birthDateToshow);

        }

    }, mYear, mMonth, mDay);
    dDialog.getDatePicker().setMaxDate(new Date().getTime());
    dDialog.show();

}

From source file:com.cwp.cmoneycharge.activity.AddPayActivity.java

@Override
protected Dialog onCreateDialog(int id)// ?onCreateDialog
{
    switch (id) {
    case DATE_DIALOG_ID:// ?
        return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
    }//from  ww w.j  a  v a 2  s.c o m
    return null;
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    DatePickerDialog.OnDateSetListener sched_date_listener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mData.sched_time.set(year, monthOfYear, dayOfMonth);
            update_date_label(R.id.sched_date_button, mData.sched_time);
        }//  w  w  w .  ja  va 2 s .  c o m
    };

    TimePickerDialog.OnTimeSetListener sched_time_listener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            int year = mData.sched_time.get(Calendar.YEAR);
            int month = mData.sched_time.get(Calendar.MONTH);
            int day = mData.sched_time.get(Calendar.DAY_OF_MONTH);
            mData.sched_time.set(year, month, day, hourOfDay, minute);
            update_time_label(R.id.sched_time_button, mData.sched_time);
        }
    };

    DatePickerDialog.OnDateSetListener depart_date_listener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mData.depart_time.set(year, monthOfYear, dayOfMonth);
            update_date_label(R.id.depart_date_button, mData.depart_time);
        }
    };

    TimePickerDialog.OnTimeSetListener depart_time_listener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            int year = mData.depart_time.get(Calendar.YEAR);
            int month = mData.depart_time.get(Calendar.MONTH);
            int day = mData.depart_time.get(Calendar.DAY_OF_MONTH);
            mData.depart_time.set(year, month, day, hourOfDay, minute);
            update_time_label(R.id.depart_time_button, mData.depart_time);
        }
    };
    DatePickerDialog.OnDateSetListener arrival_date_listener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mData.arrival_time.set(year, monthOfYear, dayOfMonth);
            update_date_label(R.id.arrival_date_button, mData.arrival_time);
        }
    };

    TimePickerDialog.OnTimeSetListener arrival_time_listener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            int year = mData.arrival_time.get(Calendar.YEAR);
            int month = mData.arrival_time.get(Calendar.MONTH);
            int day = mData.arrival_time.get(Calendar.DAY_OF_MONTH);
            mData.arrival_time.set(year, month, day, hourOfDay, minute);
            update_time_label(R.id.arrival_time_button, mData.arrival_time);
        }
    };

    switch (id) {
    case SCHED_DATE_DIALOG_ID:
        return new DatePickerDialog(this, sched_date_listener, mData.sched_time.get(Calendar.YEAR),
                mData.sched_time.get(Calendar.MONTH), mData.sched_time.get(Calendar.DAY_OF_MONTH));
    case SCHED_TIME_DIALOG_ID:
        return new TimePickerDialog(this, sched_time_listener, mData.sched_time.get(Calendar.HOUR_OF_DAY),
                mData.sched_time.get(Calendar.MINUTE), false);
    case DEPART_DATE_DIALOG_ID:
        return new DatePickerDialog(this, depart_date_listener, mData.depart_time.get(Calendar.YEAR),
                mData.depart_time.get(Calendar.MONTH), mData.depart_time.get(Calendar.DAY_OF_MONTH));
    case DEPART_TIME_DIALOG_ID:
        return new TimePickerDialog(this, depart_time_listener, mData.depart_time.get(Calendar.HOUR_OF_DAY),
                mData.depart_time.get(Calendar.MINUTE), false);
    case ARRIVAL_DATE_DIALOG_ID:
        return new DatePickerDialog(this, arrival_date_listener, mData.arrival_time.get(Calendar.YEAR),
                mData.arrival_time.get(Calendar.MONTH), mData.arrival_time.get(Calendar.DAY_OF_MONTH));
    case ARRIVAL_TIME_DIALOG_ID:
        return new TimePickerDialog(this, arrival_time_listener, mData.arrival_time.get(Calendar.HOUR_OF_DAY),
                mData.arrival_time.get(Calendar.MINUTE), false);
    }

    return null;
}

From source file:com.barbrdo.app.activities.UserProfileActivity.java

private void initDatePicker() {
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar newDate = Calendar.getInstance();
            newDate.set(year, monthOfYear, dayOfMonth);
            mLicencedSince = dateFormatter.format(newDate.getTime());
            textViewMemberSince.setText(utilObj.getMyDateFormat(mLicencedSince,
                    Constants.DateFormat.YYYYMMDDTHHMMSS, Constants.DateFormat.MMDDYYYY));
        }//from w w w  .j ava2  s  . co  m
    }, year, month, day);
    datePickerDialog.getDatePicker().setMaxDate(new Date().getTime());
}