- // Get current day
- 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);
-
- // Create a new instance of DatePickerDialog, highlighting "tomorrow" as chosen day
- DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day + 1);
+ // 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)
+ );