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

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

Issue 85643002: Transfer date/time value to chooser as double (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@doubledate2
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.content.Context; 7 import android.content.Context;
8 import android.text.format.DateUtils; 8 import android.text.format.DateUtils;
9 import android.view.LayoutInflater; 9 import android.view.LayoutInflater;
10 import android.view.accessibility.AccessibilityEvent; 10 import android.view.accessibility.AccessibilityEvent;
11 import android.widget.FrameLayout; 11 import android.widget.FrameLayout;
12 import android.widget.NumberPicker; 12 import android.widget.NumberPicker;
13 import android.widget.NumberPicker.OnValueChangeListener; 13 import android.widget.NumberPicker.OnValueChangeListener;
14 14
15 import org.chromium.content.R; 15 import org.chromium.content.R;
16 16
17 import java.util.Calendar; 17 import java.util.Calendar;
18 import java.util.TimeZone;
18 19
19 /** 20 /**
20 * This class is heavily based on android.widget.DatePicker. 21 * This class is heavily based on android.widget.DatePicker.
21 */ 22 */
22 public abstract class TwoFieldDatePicker extends FrameLayout { 23 public abstract class TwoFieldDatePicker extends FrameLayout {
23 24
24 private final NumberPicker mPositionInYearSpinner; 25 private final NumberPicker mPositionInYearSpinner;
25 26
26 private final NumberPicker mYearSpinner; 27 private final NumberPicker mYearSpinner;
27 28
(...skipping 16 matching lines...) Expand all
44 /** 45 /**
45 * Called upon a date change. 46 * Called upon a date change.
46 * 47 *
47 * @param view The view associated with this listener. 48 * @param view The view associated with this listener.
48 * @param year The year that was set. 49 * @param year The year that was set.
49 * @param positionInYear The month or week in year. 50 * @param positionInYear The month or week in year.
50 */ 51 */
51 void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int positio nInYear); 52 void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int positio nInYear);
52 } 53 }
53 54
54 public TwoFieldDatePicker(Context context, long minValue, long maxValue) { 55 public TwoFieldDatePicker(Context context, double minValue, double maxValue) {
55 super(context, null, android.R.attr.datePickerStyle); 56 super(context, null, android.R.attr.datePickerStyle);
56 57
57 LayoutInflater inflater = (LayoutInflater) context 58 LayoutInflater inflater = (LayoutInflater) context
58 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 59 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
59 inflater.inflate(R.layout.two_field_date_picker, this, true); 60 inflater.inflate(R.layout.two_field_date_picker, this, true);
60 61
61 OnValueChangeListener onChangeListener = new OnValueChangeListener() { 62 OnValueChangeListener onChangeListener = new OnValueChangeListener() {
62 @Override 63 @Override
63 public void onValueChange(NumberPicker picker, int oldVal, int newVa l) { 64 public void onValueChange(NumberPicker picker, int oldVal, int newVa l) {
64 int year = getYear(); 65 int year = getYear();
(...skipping 14 matching lines...) Expand all
79 throw new IllegalArgumentException(); 80 throw new IllegalArgumentException();
80 } 81 }
81 82
82 // now set the date to the adjusted one 83 // now set the date to the adjusted one
83 setCurrentDate(year, positionInYear); 84 setCurrentDate(year, positionInYear);
84 updateSpinners(); 85 updateSpinners();
85 notifyDateChanged(); 86 notifyDateChanged();
86 } 87 }
87 }; 88 };
88 89
89 mCurrentDate = Calendar.getInstance(); 90 mCurrentDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
90 if (minValue >= maxValue) { 91 if (minValue >= maxValue) {
91 mMinDate = Calendar.getInstance(); 92 mMinDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
92 mMinDate.set(0, 0, 1); 93 mMinDate.set(0, 0, 1);
93 mMaxDate = Calendar.getInstance(); 94 mMaxDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
94 mMaxDate.set(9999, 0, 1); 95 mMaxDate.set(9999, 0, 1);
95 } else { 96 } else {
96 mMinDate = createDateFromValue(minValue); 97 mMinDate = getDateForValue(minValue);
97 mMaxDate = createDateFromValue(maxValue); 98 mMaxDate = getDateForValue(maxValue);
98 } 99 }
99 100
100 // month 101 // month
101 mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_ye ar); 102 mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_ye ar);
102 mPositionInYearSpinner.setOnLongPressUpdateInterval(200); 103 mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
103 mPositionInYearSpinner.setOnValueChangedListener(onChangeListener); 104 mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);
104 105
105 // year 106 // year
106 mYearSpinner = (NumberPicker) findViewById(R.id.year); 107 mYearSpinner = (NumberPicker) findViewById(R.id.year);
107 mYearSpinner.setOnLongPressUpdateInterval(100); 108 mYearSpinner.setOnLongPressUpdateInterval(100);
(...skipping 17 matching lines...) Expand all
125 } 126 }
126 127
127 public boolean isNewDate(int year, int positionInYear) { 128 public boolean isNewDate(int year, int positionInYear) {
128 return (getYear() != year || getPositionInYear() != positionInYear); 129 return (getYear() != year || getPositionInYear() != positionInYear);
129 } 130 }
130 131
131 /** 132 /**
132 * Subclasses know the semantics of @value, and need to return 133 * Subclasses know the semantics of @value, and need to return
133 * a Calendar corresponding to it. 134 * a Calendar corresponding to it.
134 */ 135 */
135 protected abstract Calendar createDateFromValue(long value); 136 protected abstract Calendar getDateForValue(double value);
136 137
137 /** 138 /**
138 * Updates the current date. 139 * Updates the current date.
139 * 140 *
140 * @param year The year. 141 * @param year The year.
141 * @param positionInYear The month or week in year. 142 * @param positionInYear The month or week in year.
142 */ 143 */
143 public void updateDate(int year, int positionInYear) { 144 public void updateDate(int year, int positionInYear) {
144 if (!isNewDate(year, positionInYear)) { 145 if (!isNewDate(year, positionInYear)) {
145 return; 146 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 /** 241 /**
241 * Notifies the listener, if such, for a change in the selected date. 242 * Notifies the listener, if such, for a change in the selected date.
242 */ 243 */
243 protected void notifyDateChanged() { 244 protected void notifyDateChanged() {
244 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); 245 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
245 if (mMonthOrWeekChangedListener != null) { 246 if (mMonthOrWeekChangedListener != null) {
246 mMonthOrWeekChangedListener.onMonthOrWeekChanged(this, getYear(), ge tPositionInYear()); 247 mMonthOrWeekChangedListener.onMonthOrWeekChanged(this, getYear(), ge tPositionInYear());
247 } 248 }
248 } 249 }
249 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698