Bug 1239823 - Part 1: Parse min/max date before use r=margaret
MozReview-Commit-ID: 4th3CJwwcDg
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
@@ -264,16 +264,51 @@ public class DateTimePicker extends Fram
display.getMetrics(dm);
mScreenWidth = display.getWidth() / dm.densityDpi;
mScreenHeight = display.getHeight() / dm.densityDpi;
if (DEBUG) {
Log.d(LOGTAG, "screen width: " + mScreenWidth + " screen height: " + mScreenHeight);
}
+ // Set the min / max attribute.
+ try {
+ if (minDateValue != null && !minDateValue.equals("")) {
+ mMinDate.setTime(new SimpleDateFormat(dateFormat).parse(minDateValue));
+ } else {
+ mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
+ }
+ } catch (Exception ex) {
+ Log.e(LOGTAG, "Error parsing format sting: " + ex);
+ mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
+ }
+
+ try {
+ if (maxDateValue != null && !maxDateValue.equals("")) {
+ mMaxDate.setTime(new SimpleDateFormat(dateFormat).parse(maxDateValue));
+ } else {
+ mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
+ }
+ } catch (Exception ex) {
+ Log.e(LOGTAG, "Error parsing format string: " + ex);
+ mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
+ }
+
+ // Find the initial date from the constructor arguments.
+ try {
+ if (!dateTimeValue.equals("")) {
+ mTempDate.setTime(new SimpleDateFormat(dateFormat).parse(dateTimeValue));
+ } else {
+ mTempDate.setTimeInMillis(System.currentTimeMillis());
+ }
+ } catch (Exception ex) {
+ Log.e(LOGTAG, "Error parsing format string: " + ex);
+ mTempDate.setTimeInMillis(System.currentTimeMillis());
+ }
+
// If we're displaying a date, the screen is wide enough
// (and if we're using an SDK where the calendar view exists)
// then display a calendar.
if (Versions.feature11Plus &&
(mState == PickersState.DATE || mState == PickersState.DATETIME) &&
mScreenWidth >= SCREEN_SIZE_THRESHOLD) {
if (DEBUG) {
@@ -307,51 +342,16 @@ public class DateTimePicker extends Fram
// time spinners, and if there is no calendar displayed, we should
// display the fields in one row.
if (mScreenWidth > mScreenHeight && mState == PickersState.DATETIME) {
mPickers.setOrientation(LinearLayout.HORIZONTAL);
}
mCalendar = null;
}
- // Find the initial date from the constructor arguments.
- try {
- if (!dateTimeValue.equals("")) {
- mTempDate.setTime(new SimpleDateFormat(dateFormat).parse(dateTimeValue));
- } else {
- mTempDate.setTimeInMillis(System.currentTimeMillis());
- }
- } catch (Exception ex) {
- Log.e(LOGTAG, "Error parsing format string: " + ex);
- mTempDate.setTimeInMillis(System.currentTimeMillis());
- }
-
- // Set the min / max attribute.
- try {
- if (minDateValue != null && !minDateValue.equals("")) {
- mMinDate.setTime(new SimpleDateFormat(dateFormat).parse(minDateValue));
- } else {
- mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
- }
- } catch (Exception ex) {
- Log.e(LOGTAG, "Error parsing format sting: " + ex);
- mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
- }
-
- try {
- if (maxDateValue != null && !maxDateValue.equals("")) {
- mMaxDate.setTime(new SimpleDateFormat(dateFormat).parse(maxDateValue));
- } else {
- mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
- }
- } catch (Exception ex) {
- Log.e(LOGTAG, "Error parsing format string: " + ex);
- mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
- }
-
// Initialize all spinners.
mDaySpinner = setupSpinner(R.id.day, 1,
mTempDate.get(Calendar.DAY_OF_MONTH));
mDaySpinner.setFormatter(TWO_DIGIT_FORMATTER);
mDaySpinnerInput = (EditText) mDaySpinner.getChildAt(1);
mMonthSpinner = setupSpinner(R.id.month, 1,
mTempDate.get(Calendar.MONTH) + 1); // Month is 0-based