Index: content/public/android/java/src/org/chromium/content/browser/input/DateTimePickerDialog.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/DateTimePickerDialog.java b/content/public/android/java/src/org/chromium/content/browser/input/DateTimePickerDialog.java |
index 29bca66d02d861fe0ebc9b5ea477d0296938650d..07351e4abfb04f1f79d3518d101c171eaaaee224 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/input/DateTimePickerDialog.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/input/DateTimePickerDialog.java |
@@ -10,6 +10,7 @@ import android.content.DialogInterface; |
import android.content.DialogInterface.OnClickListener; |
import android.os.Build; |
import android.os.Bundle; |
+import android.text.format.Time; |
import android.view.LayoutInflater; |
import android.view.View; |
import android.widget.DatePicker; |
@@ -33,6 +34,9 @@ class DateTimePickerDialog extends AlertDialog implements OnClickListener, |
private final TimePicker mTimePicker; |
private final OnDateTimeSetListener mCallBack; |
+ private final Time mMinTime; |
+ private final Time mMaxTime; |
bulach
2013/05/21 17:26:35
these seem to be only ever used in the millis form
Miguel Garcia
2013/05/23 12:16:48
Done.
|
+ |
/** |
* The callback used to indicate the user is done filling in the date. |
*/ |
@@ -64,27 +68,14 @@ class DateTimePickerDialog extends AlertDialog implements OnClickListener, |
int year, |
int monthOfYear, |
int dayOfMonth, |
- int hourOfDay, int minute, boolean is24HourView) { |
- this(context, 0, callBack, year, monthOfYear, dayOfMonth, |
- hourOfDay, minute, is24HourView); |
- } |
+ int hourOfDay, int minute, boolean is24HourView, |
+ long min, long max) { |
+ super(context, 0); |
- /** |
- * @param context The context the dialog is to run in. |
- * @param theme the theme to apply to this dialog |
- * @param callBack How the parent is notified that the date is set. |
- * @param year The initial year of the dialog. |
- * @param monthOfYear The initial month of the dialog. |
- * @param dayOfMonth The initial day of the dialog. |
- */ |
- public DateTimePickerDialog(Context context, |
- int theme, |
- OnDateTimeSetListener callBack, |
- int year, |
- int monthOfYear, |
- int dayOfMonth, |
- int hourOfDay, int minute, boolean is24HourView) { |
- super(context, theme); |
+ mMinTime = new Time(); |
+ mMinTime.set(min); |
+ mMaxTime = new Time(); |
+ mMaxTime.set(max); |
mCallBack = callBack; |
@@ -100,7 +91,10 @@ class DateTimePickerDialog extends AlertDialog implements OnClickListener, |
View view = inflater.inflate(R.layout.date_time_picker_dialog, null); |
setView(view); |
mDatePicker = (DatePicker) view.findViewById(R.id.date_picker); |
+ |
mDatePicker.init(year, monthOfYear, dayOfMonth, this); |
bulach
2013/05/21 17:26:35
init is being called twice..
Miguel Garcia
2013/05/30 10:06:31
True. Removed one call now.
|
+ DateDialogNormalizer.normalize(mDatePicker, this, |
+ year, monthOfYear, dayOfMonth, min, max); |
mTimePicker = (TimePicker) view.findViewById(R.id.time_picker); |
mTimePicker.setIs24HourView(is24HourView); |
@@ -138,30 +132,28 @@ class DateTimePickerDialog extends AlertDialog implements OnClickListener, |
@Override |
public void onDateChanged(DatePicker view, int year, |
int month, int day) { |
- mDatePicker.init(year, month, day, null); |
+ |
+ // Signal a time change so the max/min checks can be applied. |
+ if (mTimePicker != null) { |
+ onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(), |
+ mTimePicker.getCurrentMinute()); |
+ } |
} |
@Override |
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { |
- /* do nothing */ |
- } |
- |
- /** |
- * Gets the {@link DatePicker} contained in this dialog. |
- * |
- * @return The DatePicker view. |
- */ |
- public DatePicker getDatePicker() { |
- return mDatePicker; |
- } |
- |
- /** |
- * Gets the {@link TimePicker} contained in this dialog. |
- * |
- * @return The TimePicker view. |
- */ |
- public TimePicker getTimePicker() { |
- return mTimePicker; |
+ Time time = new Time(); |
+ time.set(0, mTimePicker.getCurrentMinute(), |
bulach
2013/05/21 17:26:35
should this use hourOfDay and minute params?
Miguel Garcia
2013/05/30 10:06:31
It seems more consistent to get everything from th
|
+ mTimePicker.getCurrentHour(), mDatePicker.getDayOfMonth(), |
+ mDatePicker.getMonth(), mDatePicker.getYear()); |
+ |
+ if (time.toMillis(true) < mMinTime.toMillis(true)) { |
+ time.set(mMinTime); |
+ } else if (time.toMillis(true) > mMaxTime.toMillis(true)) { |
+ time.set(mMaxTime); |
+ } |
+ mTimePicker.setCurrentHour(time.hour); |
+ mTimePicker.setCurrentMinute(time.minute); |
} |
/** |