Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1190)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java

Issue 15533003: [Android] Implement min/max on all supported date types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6cafc37487b62e78ebb7e6e7abce8cbe945cf3b9
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/input/TimeDialog.java
@@ -0,0 +1,70 @@
+// 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;
+ 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);
+ }
+ super.onTimeChanged(view, time.hour, time.minute);
+ updateTime(time.hour, time.minute);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698