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

Side by Side Diff: ui/android/java/src/org/chromium/ui/picker/DateDialogNormalizer.java

Issue 574673003: Move *Picker.java and *PickerDialog.java to ui/android/java/... - Part1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased patch. Created 6 years, 2 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 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.ui.picker;
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 public class DateDialogNormalizer {
17 17
18 private static void setLimits(DatePicker picker, long minMillis, long maxMil lis) { 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 (maxMillis <= minMillis) { 22 if (maxMillis <= minMillis) {
23 return; 23 return;
24 } 24 }
25 Calendar minCal = trimToDate(minMillis); 25 Calendar minCal = trimToDate(minMillis);
26 Calendar maxCal = trimToDate(maxMillis); 26 Calendar maxCal = trimToDate(maxMillis);
(...skipping 22 matching lines...) Expand all
49 result.clear(); 49 result.clear();
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 public static void normalize(DatePicker picker, OnDateChangedListener listen er,
60 int year, int month, int day, int hour, int minute, long minMillis, long maxMillis) { 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() < minMillis) { 64 if (calendar.getTimeInMillis() < minMillis) {
65 calendar.clear(); 65 calendar.clear();
66 calendar.setTimeInMillis(minMillis); 66 calendar.setTimeInMillis(minMillis);
67 } else if (calendar.getTimeInMillis() > maxMillis) { 67 } else if (calendar.getTimeInMillis() > maxMillis) {
68 calendar.clear(); 68 calendar.clear();
69 calendar.setTimeInMillis(maxMillis); 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, minMillis, maxMillis); 75 setLimits(picker, minMillis, maxMillis);
76 } 76 }
77 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698