Example usage for android.app DatePickerDialog getDatePicker

List of usage examples for android.app DatePickerDialog getDatePicker

Introduction

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

Prototype

@NonNull
public DatePicker getDatePicker() 

Source Link

Document

Returns the DatePicker contained in this dialog.

Usage

From source file:com.cerema.cloud2.ui.dialog.ExpirationDatePickerDialogFragment.java

/**
 * {@inheritDoc}/*from w w  w  .  j  av  a  2 s .  com*/
 *
 * @return      A new dialog to let the user choose an expiration date that will be bound to a share link.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Load arguments
    mFile = getArguments().getParcelable(ARG_FILE);

    // Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
    final Calendar chosenDate = Calendar.getInstance();
    long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
    long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
    if (chosenDateInMillis > tomorrowInMillis) {
        chosenDate.setTimeInMillis(chosenDateInMillis);
    } else {
        chosenDate.setTimeInMillis(tomorrowInMillis);
    }

    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR),
            chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));

    // Prevent days in the past may be chosen
    DatePicker picker = dialog.getDatePicker();
    picker.setMinDate(tomorrowInMillis - 1000);

    // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
    // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
    // shown by default)
    picker.setCalendarViewShown(false);

    return dialog;
}

From source file:at.jclehner.rxdroid.DatePickerFragment.java

@Override
public void onShow(DialogInterface dialogInterface) {
    if (Version.SDK_IS_JELLYBEAN_OR_NEWER) {
        final DatePickerDialog dialog = (DatePickerDialog) dialogInterface;
        dialog.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() {

            @TargetApi(11)//from w  w w  .ja va  2s  .  c o m
            @Override
            public void onClick(View v) {
                final DatePicker picker = dialog.getDatePicker();
                mListener.onDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
                dialog.dismiss();
            }
        });
    }
}

From source file:rta.ae.sharekni.RegisterVehicle.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DILOG_ID) {
        DatePickerDialog dp = new DatePickerDialog(this, dPickerListener, year_x, month_x, day_x);
        DatePicker d = dp.getDatePicker();
        d.setMaxDate(cal.getTimeInMillis());
        return dp;
    }//from   ww w  .  j  av  a  2  s . c  o  m
    return null;
}

From source file:com.gatesnfc.existing.DatePicker_Fix.java

@TargetApi(11)
@Override/*from   w  w w.j  a va  2 s .  c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly 
    // TimePickerDialog as well), and one of the possible solutions is 
    // to postpone the creation of both the listener and the BUTTON_* .
    // 
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be 
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month,
            day);

    if (hasJellyBeanAndAbove()) {
        /*
         * Restriction of Date from 1980 Jan 1st to Current Date
         */
        Calendar c = Calendar.getInstance();
        picker.getDatePicker().setMaxDate(c.getTimeInMillis());
        c.set(Calendar.YEAR, 1980);
        c.set(Calendar.MONTH, c.getMinimum(Calendar.MONTH));
        c.set(Calendar.DATE, c.getMinimum(Calendar.DATE));
        c.set(Calendar.HOUR_OF_DAY, c.getMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getMinimum(Calendar.MILLISECOND));
        picker.getDatePicker().setMinDate(c.getTimeInMillis());
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}

From source file:com.owncloud.android.ui.activity.ContactsPreferenceActivity.java

public void openDate(View v) {
    String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
            + OCFile.PATH_SEPARATOR;/* w  w w  . j  ava2s . c  o m*/
    OCFile backupFolder = getStorageManager().getFileByPath(backupFolderString);

    Vector<OCFile> backupFiles = getStorageManager().getFolderContent(backupFolder, false);

    Collections.sort(backupFiles, new Comparator<OCFile>() {
        @Override
        public int compare(OCFile o1, OCFile o2) {
            if (o1.getModificationTimestamp() == o2.getModificationTimestamp()) {
                return 0;
            }

            if (o1.getModificationTimestamp() > o2.getModificationTimestamp()) {
                return 1;
            } else {
                return -1;
            }
        }
    });

    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
                    + OCFile.PATH_SEPARATOR;
            OCFile backupFolder = getStorageManager().getFileByPath(backupFolderString);
            Vector<OCFile> backupFiles = getStorageManager().getFolderContent(backupFolder, false);

            // find file with modification with date and time between 00:00 and 23:59
            // if more than one file exists, take oldest
            Calendar date = Calendar.getInstance();
            date.set(year, month, dayOfMonth);

            // start
            date.set(Calendar.HOUR, 0);
            date.set(Calendar.MINUTE, 0);
            date.set(Calendar.SECOND, 1);
            date.set(Calendar.MILLISECOND, 0);
            date.set(Calendar.AM_PM, Calendar.AM);
            Long start = date.getTimeInMillis();

            // end
            date.set(Calendar.HOUR, 23);
            date.set(Calendar.MINUTE, 59);
            date.set(Calendar.SECOND, 59);
            Long end = date.getTimeInMillis();

            OCFile backupToRestore = null;

            for (OCFile file : backupFiles) {
                if (start < file.getModificationTimestamp() && end > file.getModificationTimestamp()) {
                    if (backupToRestore == null) {
                        backupToRestore = file;
                    } else if (backupToRestore.getModificationTimestamp() < file.getModificationTimestamp()) {
                        backupToRestore = file;
                    }
                }
            }

            if (backupToRestore != null) {
                Fragment contactListFragment = ContactListFragment.newInstance(backupToRestore, getAccount());

                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.contacts_linear_layout, contactListFragment);
                transaction.commit();
            } else {
                Toast.makeText(ContactsPreferenceActivity.this, R.string.contacts_preferences_no_file_found,
                        Toast.LENGTH_SHORT).show();
            }
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(this, dateSetListener, year, month, day);
    datePickerDialog.getDatePicker().setMaxDate(backupFiles.lastElement().getModificationTimestamp());
    datePickerDialog.getDatePicker().setMinDate(backupFiles.firstElement().getModificationTimestamp());

    datePickerDialog.show();
}

From source file:com.itcorea.coreonwallet.DatePickerDialogFragment.java

@TargetApi(11)
@Override//from   ww  w .jav  a  2s .  c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle b = getArguments();
    int y = b.getInt(YEAR);
    int m = b.getInt(MONTH);
    int d = b.getInt(DATE);

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d);

    if (hasJellyBeanAndAbove()) {
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}

From source file:net.davidcesarino.android.common.ui.DatePickerDialogFragment.java

@TargetApi(11)
@Override//w ww . java  2  s . com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle b = getArguments();
    int y = b.getInt(YEAR);
    int m = b.getInt(MONTH);
    int d = b.getInt(DATE);

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly 
    // TimePickerDialog as well), and one of the possible solutions is 
    // to postpone the creation of both the listener and the BUTTON_* .
    // 
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be 
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d);

    if (isAffectedVersion()) {
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}

From source file:com.example.reminder.alarm.DatePickerFragment.java

@TargetApi(11)
@Override/*from w w w .jav  a  2  s  . c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle b = getArguments();
    int y = b.getInt(YEAR);
    int m = b.getInt(MONTH);
    int d = b.getInt(DATE);

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly 
    // TimePickerDialog as well), and one of the possible solutions is 
    // to postpone the creation of both the listener and the BUTTON_* .
    // 
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be 
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d);

    if (hasJellyBeanAndAbove()) {
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}

From source file:com.app.afridge.ui.fragments.DatePickerDialogFragment.java

@TargetApi(11)
@Override/*  www .j  ava  2 s. c  o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    Bundle b = getArguments();
    int y = b.getInt(YEAR);
    int m = b.getInt(MONTH);
    int d = b.getInt(DATE);

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly
    // TimePickerDialog as well), and one of the possible solutions is
    // to postpone the creation of both the listener and the BUTTON_* .
    //
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d);

    if (hasJellyBeanAndAbove()) {
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
    }
    return picker;
}

From source file:com.cavega.DatePickerDialogSample.DatePickerDialogFragment.java

@TargetApi(11)
@Override//from w ww . j a v a 2 s . com
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly 
    // TimePickerDialog as well), and one of the possible solutions is 
    // to postpone the creation of both the listener and the BUTTON_* .
    // 
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be 
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month,
            day);

    if (hasJellyBeanAndAbove()) {
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}