|
12 | 12 | import javax.annotation.Nullable;
|
13 | 13 |
|
14 | 14 | import java.util.Calendar;
|
| 15 | +import java.util.Locale; |
15 | 16 |
|
16 | 17 | import android.annotation.SuppressLint;
|
17 | 18 | import android.app.DatePickerDialog;
|
|
21 | 22 | import android.content.Context;
|
22 | 23 | import android.content.DialogInterface;
|
23 | 24 | import android.content.DialogInterface.OnDismissListener;
|
| 25 | +import android.os.Build; |
24 | 26 | import android.os.Bundle;
|
25 | 27 | import android.widget.DatePicker;
|
26 | 28 |
|
@@ -53,8 +55,43 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
|
53 | 55 | final int month = c.get(Calendar.MONTH);
|
54 | 56 | final int day = c.get(Calendar.DAY_OF_MONTH);
|
55 | 57 |
|
56 |
| - final DatePickerDialog dialog = |
57 |
| - new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); |
| 58 | + DatePickerMode mode = DatePickerMode.DEFAULT; |
| 59 | + if (args != null && args.getString(DatePickerDialogModule.ARG_MODE, null) != null) { |
| 60 | + mode = DatePickerMode.valueOf(args.getString(DatePickerDialogModule.ARG_MODE).toUpperCase(Locale.US)); |
| 61 | + } |
| 62 | + |
| 63 | + DatePickerDialog dialog = null; |
| 64 | + |
| 65 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 66 | + switch (mode) { |
| 67 | + case CALENDAR: |
| 68 | + dialog = new DismissableDatePickerDialog(activityContext, |
| 69 | + activityContext.getResources().getIdentifier("CalendarDatePickerDialog", "style", activityContext.getPackageName()), |
| 70 | + onDateSetListener, year, month, day); |
| 71 | + break; |
| 72 | + case SPINNER: |
| 73 | + dialog = new DismissableDatePickerDialog(activityContext, |
| 74 | + activityContext.getResources().getIdentifier("SpinnerDatePickerDialog", "style", activityContext.getPackageName()), |
| 75 | + onDateSetListener, year, month, day); |
| 76 | + break; |
| 77 | + case DEFAULT: |
| 78 | + dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); |
| 79 | + break; |
| 80 | + } |
| 81 | + } else { |
| 82 | + dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); |
| 83 | + |
| 84 | + switch (mode) { |
| 85 | + case CALENDAR: |
| 86 | + dialog.getDatePicker().setCalendarViewShown(true); |
| 87 | + dialog.getDatePicker().setSpinnersShown(false); |
| 88 | + break; |
| 89 | + case SPINNER: |
| 90 | + dialog.getDatePicker().setCalendarViewShown(false); |
| 91 | + break; |
| 92 | + } |
| 93 | + } |
| 94 | + |
58 | 95 | final DatePicker datePicker = dialog.getDatePicker();
|
59 | 96 |
|
60 | 97 | if (args != null && args.containsKey(DatePickerDialogModule.ARG_MINDATE)) {
|
|
0 commit comments