List of usage examples for android.app DatePickerDialog DatePickerDialog
public DatePickerDialog(@NonNull Context context, @StyleRes int themeResId, @Nullable OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth)
From source file:it.feio.android.omninotes.utils.date.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker Calendar cal = DateHelper.getCalendar(defaultDate); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); // Create a new instance of DatePickerDialog and return it DatePickerDialog dpd = new DatePickerDialog(mActivity, R.style.Theme_AppCompat_Dialog_NoBackgroundOrDim, mListener, year, month, day); dpd.setTitle(""); return dpd;/*from ww w . j ava2 s .com*/ }
From source file:org.akop.crosswords.fragment.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DateTime dateTime = null;//from w w w . j av a 2 s. c om 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.dycody.android.idealnote.utils.date.DatePickerDialogFragment.java
@NonNull @Override/*www.ja va 2 s. c om*/ 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:palamarchuk.smartlife.app.RegisterActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_PICKER: Date date = new Date(); return new DatePickerDialog(this, R.style.AppTheme, new DatePickerDialog.OnDateSetListener() { @Override/*from ww w . java 2 s .com*/ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); SimpleDateFormat toServer = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth); birthDateToServer = toServer.format(calendar.getTime()); birthDate.setText(sdf.format(calendar.getTime())); } }, date.getYear() + 1900, date.getMonth(), date.getDate()); } return null; }
From source file:org.openlmis.core.view.holder.StockMovementViewHolder.java
private void showDatePickerDialog(final StockMovementViewModel model, final Date previousMovementDate) { final Calendar today = GregorianCalendar.getInstance(); DatePickerDialog dialog = new DatePickerDialog(context, DatePickerDialog.BUTTON_NEUTRAL, new MovementDateListener(model, previousMovementDate), today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH)); dialog.show();//from www . jav a 2 s . com }
From source file:me.tipi.kiosk.ui.fragments.IdentityFragment.java
/** * Show dob dialog./*from w ww . j ava 2s.co m*/ */ private void showDobDialog() { DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { birthdayLayout.setError(null); Calendar calendar = Calendar.getInstance(); birthDayPickerView.setText( String.format(Locale.US, "%d - %d - %d", dayOfMonth, monthOfYear + 1, year)); calendar.set(year, monthOfYear, dayOfMonth); dob = calendar.getTime(); } }, 1985, 6, 15); DatePicker datePicker = datePickerDialog.getDatePicker(); datePickerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); styleDatePicker(datePicker); datePickerDialog.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 w w . ja v a 2 s . c o 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(); }
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])); }// w w w . j a v a2 s .c o 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, 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 getModelYear(Button theButton) { Calendar c = Calendar.getInstance(); final String dateStr = txtModelYear.getText().toString(); if (!dateStr.isEmpty()) { c.set(Calendar.YEAR, Integer.parseInt(dateStr)); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.MONTH, 1); }/* w ww . jav a 2 s . c o m*/ DatePickerDialog dialog = new DatePickerDialog(getActivity(), DialogFragment.STYLE_NO_FRAME | DialogFragment.STYLE_NORMAL, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { ((FragmentPagerActivity) getActivity()).unsavedCheckin(); txtModelYear.setText(String.valueOf(year)); btnModelYear.setEnabled(true); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); findAndHideField(dialog.getDatePicker(), "mDayPicker"); findAndHideField(dialog.getDatePicker(), "mDaySpinner"); findAndHideField(dialog.getDatePicker(), "mMounthPicker"); findAndHideField(dialog.getDatePicker(), "mMonthSpinner"); dialog.getDatePicker().getCalendarView().setVisibility(View.GONE); dialog.show(); }