List of usage examples for android.app DatePickerDialog DatePickerDialog
public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month, int dayOfMonth)
From source file:de.ribeiro.android.gso.activities.PlanActivity.java
/** * @author ribeiro/*from w w w.j av a 2 s . co m*/ * ffnet ein Datumsplugin und prft, ob dieses TimeTable verfgbar ist, wenn ja, springt er dorthin */ private void gotoDate() { ctxt.handler.post(new Runnable() { @Override public void run() { _logger.Info("Goto Date called"); if (ctxt.mIsRunning && ctxt.pager != null && ctxt.pager.size() > 1) { Calendar cal = ctxt.pager.getDateOfCurrentPage(); if (cal != null) { DatePickerDialog picker = new DatePickerDialog(PlanActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { _logger.Info("Set Date " + dayOfMonth + "." + monthOfYear + "." + year); // das Ausgewhlte Datum einstellen Calendar newDate = new GregorianCalendar(); newDate.set(year, monthOfYear, dayOfMonth); // prfen, ob es sich dabei um wochenend tage // handelt: switch (newDate.get(Calendar.DAY_OF_WEEK)) { case Calendar.SATURDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2)); break; case Calendar.SUNDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 1)); break; } int page = ctxt.pager.getPage(newDate, -1); if (page != -1) { // gefunden ctxt.pager.setPage(page); } else { _logger.Info("Selected date is unavailable"); Toast.makeText(PlanActivity.this, "Dieses Datum ist nicht verfgbar!", Toast.LENGTH_SHORT).show(); } } }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); picker.show(); } else _logger.Info("Cal Picker canceled, because Pager is empty"); } } }); }
From source file:com.mvcoding.financius.feature.DateDialogFragment.java
@NonNull @Override/*from w w w. j a va 2s .c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final int year = getArguments().getInt(ARG_YEAR); final int monthOfYear = getArguments().getInt(ARG_MONTH_OF_YEAR); final int dayOfMonth = getArguments().getInt(ARG_DAY_OF_MONTH); return new DatePickerDialog(getActivity(), this, year, monthOfYear - 1, dayOfMonth); }
From source file:com.example.crudcontent.fragment.DatePickerDialogFragment.java
@NonNull @Override//from w w w .j a va 2s. co m public Dialog onCreateDialog(Bundle savedInstanceState) { // Initialize our date picker dialog with the last birthday of the user... Calendar cal = Calendar.getInstance(); cal.setTime(date); DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); // No birthdays allowed in the future... dialog.getDatePicker().setMaxDate(System.currentTimeMillis()); // One note. The DatePickerDialog is managing the saved state for us. This is why // this fragment isn't trying to do that. It is nice when that happens, but you // should always verify expected behavior. return dialog; }
From source file:com.manning.androidhacks.hack009.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); }// ww w . j a v a2 s .c om return super.onCreateDialog(id); }
From source file:com.franmontiel.localechanger.sample.SampleFragment.java
@OnClick(R.id.showDatePicker) void onShowDatePickerClick() { Calendar now = Calendar.getInstance(); DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override//from w w w . j av a 2 s . co m public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dialog.show(); }
From source file:ca.ualberta.cs.shoven_habittracker.DatePickerFragment.java
@Override @NonNull// ww w .j ava 2 s .c o m public Dialog onCreateDialog(Bundle savedInstanceState) { DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day); dialog.getDatePicker().setMaxDate(System.currentTimeMillis()); return dialog; }
From source file:de.grobox.transportr.ui.TimeDateFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_time_date, container); // Time//from w ww. j a v a 2s. c o m timePicker = v.findViewById(R.id.timePicker); timePicker.setOnTimeChangedListener(this); showTime(calendar); // Date dateView = v.findViewById(R.id.dateView); dateView.setOnClickListener(view -> new DatePickerDialog(getContext(), TimeDateFragment.this, calendar.get(YEAR), calendar.get(MONTH), calendar.get(DAY_OF_MONTH)).show()); showDate(calendar); // Previous and Next Date ImageButton prevDateButton = v.findViewById(R.id.prevDateButton); prevDateButton.setOnClickListener(view -> { calendar.add(DAY_OF_MONTH, -1); showDate(calendar); }); ImageButton nextDateButton = v.findViewById(R.id.nextDateButton); nextDateButton.setOnClickListener(view -> { calendar.add(DAY_OF_MONTH, 1); showDate(calendar); }); // Buttons Button okButton = v.findViewById(R.id.okButton); okButton.setOnClickListener(view -> { if (listener != null) { listener.onTimeAndDateSet(calendar); } dismiss(); }); v.findViewById(R.id.nowButton).setOnClickListener(view -> { if (listener != null) { listener.onTimeAndDateSet(Calendar.getInstance()); } dismiss(); }); Button cancelButton = v.findViewById(R.id.cancelButton); cancelButton.setOnClickListener(view -> dismiss()); return v; }
From source file:com.cerema.cloud2.ui.dialog.ExpirationDatePickerDialogFragment.java
/** * {@inheritDoc}// ww w. j a v 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:fr.cobaltians.cobalt.fragments.CobaltDatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();//from w w w .j av a 2s . c o m if (args != null) { int year = args.getInt(ARG_YEAR); int month = args.getInt(ARG_MONTH); int day = args.getInt(ARG_DAY); mCallbackId = args.getString(ARG_CALLBACK_ID); mTitle = args.getString(ARG_TITLE); mDelete = args.getString(ARG_DELETE); mCancel = args.getString(ARG_CANCEL); mValidate = args.getString(ARG_VALIDATE); if (year != 0 && month >= 0 && day != 0) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } } if (mDelete == null && mCancel == null && mValidate == null && mTitle == null) { return new DatePickerDialog(mContext, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); } else { LayoutInflater inflater = (LayoutInflater) ((Activity) mContext).getLayoutInflater(); final DatePicker datePicker = (DatePicker) inflater.inflate(R.layout.date_picker_cobalt, null); AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(mContext); datePickerBuilder.setView(datePicker); /* // Init the datePicker with mindate under 1900 //TODO test for under HoneyComb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", Locale.FRANCE); Calendar minDate = Calendar.getInstance(); try { minDate.setTime(formatter.parse("01.01.1800")); } catch (ParseException e) { e.printStackTrace(); } datePicker.setMinDate(minDate.getTimeInMillis()); } else { datePicker.init(1800, 01, 01, new OnDateChangedListener() { @Override public void onDateChanged(DatePicker datePicker, int year, int month, int day) { Calendar newDate = Calendar.getInstance(); newDate.set(year, month, day); } }); }*/ // View settings int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (mTitle != null) { datePickerBuilder.setTitle(mTitle); } // Buttons datePickerBuilder.setNegativeButton(mDelete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.clear(); if (mListener != null) { mListener.sendDate(-1, -1, -1, mCallbackId); } } }); datePickerBuilder.setNeutralButton(mCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); datePickerBuilder.setPositiveButton(mValidate, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); if (mListener != null) { mListener.sendDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), mCallbackId); } dialog.dismiss(); } }); final AlertDialog dialog = datePickerBuilder.create(); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } }); return dialog; } }
From source file:org.cobaltians.cobalt.fragments.CobaltDatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();//from w w w . j av a2 s . c o m if (args != null) { int year = args.getInt(ARG_YEAR); int month = args.getInt(ARG_MONTH); int day = args.getInt(ARG_DAY); mCallbackId = args.getString(ARG_CALLBACK_ID); mTitle = args.getString(ARG_TITLE); mDelete = args.getString(ARG_DELETE); mCancel = args.getString(ARG_CANCEL); mValidate = args.getString(ARG_VALIDATE); if (year != 0 && month >= 0 && day != 0) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } } if (mDelete == null && mCancel == null && mValidate == null && mTitle == null) { return new DatePickerDialog(mContext, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); } else { LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); final DatePicker datePicker = (DatePicker) inflater.inflate(R.layout.date_picker_cobalt, null); AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(mContext); datePickerBuilder.setView(datePicker); /* // Init the datePicker with mindate under 1900 //TODO test for under HoneyComb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", Locale.FRANCE); Calendar minDate = Calendar.getInstance(); try { minDate.setTime(formatter.parse("01.01.1800")); } catch (ParseException e) { e.printStackTrace(); } datePicker.setMinDate(minDate.getTimeInMillis()); } else { datePicker.init(1800, 01, 01, new OnDateChangedListener() { @Override public void onDateChanged(DatePicker datePicker, int year, int month, int day) { Calendar newDate = Calendar.getInstance(); newDate.set(year, month, day); } }); }*/ // View settings int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (mTitle != null) { datePickerBuilder.setTitle(mTitle); } // Buttons datePickerBuilder.setNegativeButton(mDelete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.clear(); if (mListener != null) { mListener.sendDate(-1, -1, -1, mCallbackId); } } }); datePickerBuilder.setNeutralButton(mCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); datePickerBuilder.setPositiveButton(mValidate, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); if (mListener != null) { mListener.sendDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), mCallbackId); } dialog.dismiss(); } }); final AlertDialog dialog = datePickerBuilder.create(); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } }); return dialog; } }