Commits

Anonymous committed b85d48f

Clamp date setting for the SetupWizard as well as Settings.

We fixed this for Settings in 7ccfa0614caeba8eba5d3040a90541a24fa1e6c9,
but @sonymobile.com point out that it's still broken for SetupWizard.

Change-Id: I59348200105246f3ed7c0892e5f19b901d3e95ac

  • Participants
  • Parent commits 8147640

Comments (0)

Files changed (2)

File src/com/android/settings/DateTimeSettings.java

 
     @Override
     public Dialog onCreateDialog(int id) {
-        Dialog d;
-
+        final Calendar calendar = Calendar.getInstance();
         switch (id) {
-        case DIALOG_DATEPICKER: {
-            final Calendar calendar = Calendar.getInstance();
-            d = new DatePickerDialog(
-                getActivity(),
-                this,
-                calendar.get(Calendar.YEAR),
-                calendar.get(Calendar.MONTH),
-                calendar.get(Calendar.DAY_OF_MONTH));
-            // The system clock can't represent dates outside this range.
-            DatePickerDialog datePicker = (DatePickerDialog)d;
-            Calendar t = Calendar.getInstance();
-            t.clear();
-            t.set(1970, Calendar.JANUARY, 1);
-            datePicker.getDatePicker().setMinDate(t.getTimeInMillis());
-            t.clear();
-            t.set(2037, Calendar.DECEMBER, 31);
-            datePicker.getDatePicker().setMaxDate(t.getTimeInMillis());
-            break;
-        }
-        case DIALOG_TIMEPICKER: {
-            final Calendar calendar = Calendar.getInstance();
-            d = new TimePickerDialog(
+        case DIALOG_DATEPICKER:
+            DatePickerDialog d = new DatePickerDialog(
+                    getActivity(),
+                    this,
+                    calendar.get(Calendar.YEAR),
+                    calendar.get(Calendar.MONTH),
+                    calendar.get(Calendar.DAY_OF_MONTH));
+            configureDatePicker(d.getDatePicker());
+            return d;
+        case DIALOG_TIMEPICKER:
+            return new TimePickerDialog(
                     getActivity(),
                     this,
                     calendar.get(Calendar.HOUR_OF_DAY),
                     calendar.get(Calendar.MINUTE),
                     DateFormat.is24HourFormat(getActivity()));
-            break;
-        }
         default:
-            d = null;
-            break;
+            throw new IllegalArgumentException();
         }
+    }
 
-        return d;
+    static void configureDatePicker(DatePicker datePicker) {
+        // The system clock can't represent dates outside this range.
+        Calendar t = Calendar.getInstance();
+        t.clear();
+        t.set(1970, Calendar.JANUARY, 1);
+        datePicker.setMinDate(t.getTimeInMillis());
+        t.clear();
+        t.set(2037, Calendar.DECEMBER, 31);
+        datePicker.setMaxDate(t.getTimeInMillis());
     }
 
     /*

File src/com/android/settings/DateTimeSettingsSetupWizard.java

         mDatePicker = (DatePicker)findViewById(R.id.date_picker);
         mDatePicker.setEnabled(!autoDateTimeEnabled);
         mDatePicker.setCalendarViewShown(false);
+        DateTimeSettings.configureDatePicker(mDatePicker);
 
         mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);