Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java b/content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b78fe4c4f6020c9fb2e8560bbf2e49b4238a2160 |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.content.browser.input; |
| + |
| +import android.app.TimePickerDialog; |
| +import android.content.Context; |
| +import android.text.format.Time; |
| +import android.widget.TimePicker; |
| + |
| +/** |
| + * Wrapper on {@code TimePickerDialog} to control min and max times. |
| + */ |
| +public class TimeDialog extends TimePickerDialog { |
| + |
| + private Time mMinTime; |
| + private Time mMaxTime; |
| + |
| + private int mYear; |
| + private int mMonth; |
| + private int mDay; |
| + |
| + public static TimeDialog create(Context context, OnTimeSetListener callBack, |
| + int year, int month, int day, int hour, |
| + int minute, boolean is24HourView, long min, long max) { |
| + Time time = new Time(); |
| + time.set(0, minute, hour, day, month, year); |
| + if (time.toMillis(true) < min) { |
| + time.set(min); |
| + } else if (time.toMillis(true) > max) { |
| + time.set(max); |
| + } |
| + return new TimeDialog(context, callBack, year, month, day, time.hour, time.minute, |
| + is24HourView, min, max); |
| + } |
| + |
| + private TimeDialog( |
| + Context context, OnTimeSetListener callBack, int year, int month, int day, |
| + int hourOfDay, int minute, boolean is24HourView, long min, long max) { |
| + super(context, callBack, hourOfDay, minute, is24HourView); |
| + mYear = year; |
| + mMonth = month; |
| + mDay = day; |
| + Time time = new Time(); |
| + time.set(min); |
| + mMinTime = new Time(time); |
| + time.set(max); |
| + mMaxTime = new Time(time); |
| + } |
| + |
| + public void updateBaseDate(int year, int month, int day) { |
| + this.mYear = year; |
|
bulach
2013/05/30 14:16:30
nit: s/this.//
Miguel Garcia
2013/06/03 13:08:58
Done.
|
| + this.mMonth = month; |
| + this.mDay = day; |
| + } |
| + |
| + @Override |
| + public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { |
| + Time time = new Time(); |
| + time.set(0, minute, hourOfDay, mDay, mMonth, mYear); |
| + |
| + if (time.toMillis(true) < mMinTime.toMillis(true)) { |
| + time.set(mMinTime); |
| + } else if (time.toMillis(true) > mMaxTime.toMillis(true)) { |
| + time.set(mMaxTime); |
| + } |
|
bulach
2013/05/30 14:16:30
60-67 and 27-32 are the same, maybe have something
Miguel Garcia
2013/06/03 13:08:58
Good idea! done, also made the private method stat
|
| + super.onTimeChanged(view, time.hour, time.minute); |
| + updateTime(time.hour, time.minute); |
| + } |
| +} |