List of usage examples for android.app DatePickerDialog getDatePicker
@NonNull
public DatePicker getDatePicker()
From source file:com.propelforwardmedia.app.DatePickerDialogFragment.java
@TargetApi(11) @Override// w w w . jav a 2 s .co m public Dialog onCreateDialog(Bundle savedInstanceState) { int year = mCalendar.get(Calendar.YEAR); int month = mCalendar.get(Calendar.MONTH); int day = mCalendar.get(Calendar.DAY_OF_MONTH); // 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; }
From source file:com.stephenmcgruer.threethingstoday.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DatePickerDialog dialog = new DatePickerDialog(getActivity(), mOnDateSetListener, mInitialYear, mInitialMonth, mInitialDayOfMonth); // Disallow future dates. For Lollipop, we need to set the timestamp to the last second // of the last allowed day, or that day will be visible but not selectable. // TODO(smcgruer): I don't think this actually works. Need to test on real device. final Calendar maxCal = Calendar.getInstance(); maxCal.set(Calendar.HOUR, 23); maxCal.set(Calendar.MINUTE, 59); maxCal.set(Calendar.SECOND, 59); dialog.getDatePicker().setMaxDate(maxCal.getTimeInMillis()); return dialog; }
From source file:br.com.heitorcolangelo.mobilereport.DatePickerDialogFragment.java
@TargetApi(11) @Override/*from w w w. j a v a 2s .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()) { 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) { // Quando cancela no retorna nenhuma data. DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, 0, 0, 0); } }); } return picker; }
From source file:com.dycody.android.idealnote.utils.date.DatePickerDialogFragment.java
@NonNull @Override//from w w w . j av a 2 s. c o m public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker Calendar cal = DateUtils.getCalendar(defaultDate); int y = cal.get(Calendar.YEAR); int m = cal.get(Calendar.MONTH); int d = cal.get(Calendar.DAY_OF_MONTH); // 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(), DatePickerDialog.THEME_HOLO_LIGHT, getConstructorListener(), y, m, d); picker.setTitle(""); 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:org.akop.crosswords.fragment.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DateTime dateTime = null;/* w ww . ja v a2 s. c o m*/ Bundle args = getArguments(); if (args != null) { long dateMillis = args.getLong("dateMillis", -1); if (dateMillis != -1) { dateTime = new DateTime(dateMillis); } } if (dateTime == null) { dateTime = DateTime.now(); } final DatePickerDialog pickerDialog = new DatePickerDialog(getActivity(), R.style.Theme_Crosswords_Default_Dialog, null, dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); // Workaround for the JellyBean bug // http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel pickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { notifyListener(pickerDialog.getDatePicker()); } }); pickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), (DialogInterface.OnClickListener) null); return pickerDialog; }
From source file:com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment.java
/** * {@inheritDoc}/*from w w w . j a v a2 s .co m*/ * * @return A new dialog to let the user choose an expiration date that will be bound to a share link. */ @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { // 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); long maxDateInMillis = getArguments().getLong(ARG_MAX_DATE_IN_MILLIS); if (chosenDateInMillis < tomorrowInMillis) { chosenDateInMillis = tomorrowInMillis; } chosenDate.setTimeInMillis(chosenDateInMillis); // 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)); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.share_cancel_public_link_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) { // Do Stuff notifyDatePickerListener(null); } } }); // Prevent days in the past may be chosen DatePicker picker = dialog.getDatePicker(); if (maxDateInMillis >= chosenDateInMillis) { // the extra second (+1000) is required to prevent a bug of DatePicker that shows // an extra header with the selected date if maxDateInMillis == chosenDateInMillis picker.setMaxDate(maxDateInMillis + 1000); } 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:org.akvo.caddisfly.sensor.colorimetry.liquid.SaveCalibrationDialogFragment.java
@NonNull @Override/*from w ww.j av a 2s.c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { String testCode = CaddisflyApp.getApp().getCurrentTestInfo().getId(); final Context context = getActivity(); LayoutInflater i = getActivity().getLayoutInflater(); @SuppressLint("InflateParams") View view = i.inflate(R.layout.fragment_save_calibration, null); final DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); String date = new SimpleDateFormat("dd MMM yyyy", Locale.US).format(calendar.getTime()); editExpiryDate.setText(date); } }; editExpiryDate = (EditText) view.findViewById(R.id.editExpiryDate); editBatchCode = (EditText) view.findViewById(R.id.editBatchCode); editRgb = (EditText) view.findViewById(R.id.editRgb); long milliseconds = PreferencesUtil.getLong(getActivity(), CaddisflyApp.getApp().getCurrentTestInfo().getId(), R.string.calibrationExpiryDateKey); if (milliseconds > new Date().getTime()) { editBatchCode.setText(PreferencesUtil.getString(context, testCode, R.string.batchNumberKey, "").trim()); long expiryDate = PreferencesUtil.getLong(getContext(), testCode, R.string.calibrationExpiryDateKey); if (expiryDate >= 0) { calendar.setTimeInMillis(expiryDate); editExpiryDate.setText(new SimpleDateFormat("dd-MMM-yyyy", Locale.US).format(new Date(expiryDate))); } } editRgb.setText(PreferencesUtil.getString(context, testCode, R.string.ledRgbKey, "").trim()); if (!AppPreferences.useExternalCamera()) { editRgb.setVisibility(View.GONE); view.findViewById(R.id.textRgb).setVisibility(View.GONE); } final DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); Calendar date = Calendar.getInstance(); date.add(Calendar.DATE, 1); date.set(Calendar.HOUR_OF_DAY, date.getMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getMinimum(Calendar.MILLISECOND)); datePickerDialog.getDatePicker().setMinDate(date.getTimeInMillis()); date.add(Calendar.MONTH, CaddisflyApp.getApp().getCurrentTestInfo().getMonthsValid()); date.set(Calendar.HOUR_OF_DAY, date.getMaximum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getMaximum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getMaximum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getMaximum(Calendar.MILLISECOND)); datePickerDialog.getDatePicker().setMaxDate(date.getTimeInMillis()); editExpiryDate.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (b) { closeKeyboard(getContext(), editBatchCode); datePickerDialog.show(); } } }); editExpiryDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeKeyboard(getContext(), editBatchCode); datePickerDialog.show(); } }); editName = (EditText) view.findViewById(R.id.editName); if (!isEditing && AppPreferences.isDiagnosticMode()) { editName.requestFocus(); } else { editName.setVisibility(View.GONE); editBatchCode.requestFocus(); } InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); AlertDialog.Builder b = new AlertDialog.Builder(getActivity()).setTitle(R.string.calibrationDetails) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { closeKeyboard(context, editName); dismiss(); } }); b.setView(view); return b.create(); }
From source file:de.kirchnerei.bicycle.battery.BatteryEditFragment.java
private void doPickBatteryDate() { final Calendar now = Calendar.getInstance(); now.setTime(item.getDate());//from ww w. j a va 2 s . c om DatePickerDialog dlg = new DatePickerDialog(getActivity(), // TODO Define a Theme for the DatePickerDialog new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { synchronized (now) { now.set(Calendar.YEAR, year); now.set(Calendar.MONTH, monthOfYear); now.set(Calendar.DATE, dayOfMonth); updateDate(now.getTime()); } } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE)); dlg.getDatePicker().setMaxDate(System.currentTimeMillis()); dlg.getDatePicker().setFirstDayOfWeek(Calendar.MONDAY); dlg.show(); }
From source file:cz.tsystems.portablecheckin.MainActivity.java
private void getEmiseDatePicker() { Calendar c = Calendar.getInstance(); String strDate = txtEmiseDate.getText().toString(); if (strDate.length() > 0) { String parts[] = strDate.split("[.]"); if (parts.length >= 2) { c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.MONTH, Integer.parseInt(parts[0])); c.set(Calendar.YEAR, Integer.parseInt(parts[1])); }//from w w w. j ava2 s.com } int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH) - 1; int day = 1; DatePickerDialog dialog = new DatePickerDialog(getActivity(), DialogFragment.STYLE_NO_FRAME | DialogFragment.STYLE_NORMAL, onEmiseDateChangedListener, year, month, day); findAndHideField(dialog.getDatePicker(), "mMonthPicker"); // Honeycomb(+) fields: findAndHideField(dialog.getDatePicker(), "mDaySpinner"); dialog.getDatePicker().getCalendarView().setVisibility(View.GONE); dialog.show(); }
From source file:cz.tsystems.portablecheckin.MainActivity.java
private void getSTKDatePicker() { Calendar c = Calendar.getInstance(); String strDate = txtSTKDate.getText().toString(); if (strDate.length() > 0) { String parts[] = strDate.split("[.]"); if (parts.length >= 2) { c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.MONTH, Integer.parseInt(parts[0])); c.set(Calendar.YEAR, Integer.parseInt(parts[1])); }//from w ww . j a va 2 s .co m } int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH) - 1; int day = 1; DatePickerDialog dialog = new DatePickerDialog(getActivity(), DialogFragment.STYLE_NO_FRAME | DialogFragment.STYLE_NORMAL, onSTKDateChangedListener, year, month, day); // pre-Honeycomb fields: findAndHideField(dialog.getDatePicker(), "mDayPicker"); // Honeycomb(+) fields: findAndHideField(dialog.getDatePicker(), "mDaySpinner"); dialog.getDatePicker().getCalendarView().setVisibility(View.GONE); dialog.show(); }