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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/DateDialogNormalizer.java

Issue 23623019: Support datalist for date/time input types on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser.input; 5 package org.chromium.content.browser.input;
6 6
7 import android.widget.DatePicker; 7 import android.widget.DatePicker;
8 import android.widget.DatePicker.OnDateChangedListener; 8 import android.widget.DatePicker.OnDateChangedListener;
9 9
10 import java.util.Calendar; 10 import java.util.Calendar;
11 import java.util.TimeZone; 11 import java.util.TimeZone;
12 12
13 /** 13 /**
14 * Normalize a date dialog so that it respect min and max. 14 * Normalize a date dialog so that it respect min and max.
15 */ 15 */
16 class DateDialogNormalizer { 16 class DateDialogNormalizer {
17 17
18 private static void setLimits(DatePicker picker, long min, long max) { 18 private static void setLimits(DatePicker picker, long minMillis, long maxMil lis) {
19 // DatePicker intervals are non inclusive, the DatePicker will throw an 19 // DatePicker intervals are non inclusive, the DatePicker will throw an
20 // exception when setting the min/max attribute to the current date 20 // exception when setting the min/max attribute to the current date
21 // so make sure this never happens 21 // so make sure this never happens
22 if (max <= min) { 22 if (maxMillis <= minMillis) {
23 return; 23 return;
24 } 24 }
25 Calendar minCal = trimToDate(min); 25 Calendar minCal = trimToDate(minMillis);
26 Calendar maxCal = trimToDate(max); 26 Calendar maxCal = trimToDate(maxMillis);
27 int currentYear = picker.getYear(); 27 int currentYear = picker.getYear();
28 int currentMonth = picker.getMonth(); 28 int currentMonth = picker.getMonth();
29 int currentDayOfMonth = picker.getDayOfMonth(); 29 int currentDayOfMonth = picker.getDayOfMonth();
30 picker.updateDate(maxCal.get(Calendar.YEAR), 30 picker.updateDate(maxCal.get(Calendar.YEAR),
31 maxCal.get(Calendar.MONTH), 31 maxCal.get(Calendar.MONTH),
32 maxCal.get(Calendar.DAY_OF_MONTH)); 32 maxCal.get(Calendar.DAY_OF_MONTH));
33 picker.setMinDate(minCal.getTimeInMillis()); 33 picker.setMinDate(minCal.getTimeInMillis());
34 picker.updateDate(minCal.get(Calendar.YEAR), 34 picker.updateDate(minCal.get(Calendar.YEAR),
35 minCal.get(Calendar.MONTH), 35 minCal.get(Calendar.MONTH),
36 minCal.get(Calendar.DAY_OF_MONTH)); 36 minCal.get(Calendar.DAY_OF_MONTH));
(...skipping 13 matching lines...) Expand all
50 result.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Cale ndar.DAY_OF_MONTH), 50 result.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Cale ndar.DAY_OF_MONTH),
51 0, 0, 0); 51 0, 0, 0);
52 return result; 52 return result;
53 } 53 }
54 54
55 /** 55 /**
56 * Normalizes an existing DateDialogPicker changing the default date if 56 * Normalizes an existing DateDialogPicker changing the default date if
57 * needed to comply with the {@code min} and {@code max} attributes. 57 * needed to comply with the {@code min} and {@code max} attributes.
58 */ 58 */
59 static void normalize(DatePicker picker, OnDateChangedListener listener, 59 static void normalize(DatePicker picker, OnDateChangedListener listener,
60 int year, int month, int day, int hour, int minute, long min, long m ax) { 60 int year, int month, int day, int hour, int minute, long minMillis, long maxMillis) {
61 Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 61 Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
62 calendar.clear(); 62 calendar.clear();
63 calendar.set(year, month, day, hour, minute, 0); 63 calendar.set(year, month, day, hour, minute, 0);
64 if (calendar.getTimeInMillis() < min) { 64 if (calendar.getTimeInMillis() < minMillis) {
65 calendar.clear(); 65 calendar.clear();
66 calendar.setTimeInMillis(min); 66 calendar.setTimeInMillis(minMillis);
67 } else if (calendar.getTimeInMillis() > max) { 67 } else if (calendar.getTimeInMillis() > maxMillis) {
68 calendar.clear(); 68 calendar.clear();
69 calendar.setTimeInMillis(max); 69 calendar.setTimeInMillis(maxMillis);
70 } 70 }
71 picker.init( 71 picker.init(
72 calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 72 calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
73 calendar.get(Calendar.DAY_OF_MONTH), listener); 73 calendar.get(Calendar.DAY_OF_MONTH), listener);
74 74
75 setLimits(picker, min, max); 75 setLimits(picker, minMillis, maxMillis);
76 } 76 }
77 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698