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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/TwoFieldDatePicker.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: Used double to transfer value Created 7 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.content.browser.input;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.widget.NumberPicker; 9 import android.widget.NumberPicker;
10 import android.widget.NumberPicker.OnValueChangeListener; 10 import android.widget.NumberPicker.OnValueChangeListener;
11 import android.text.format.DateUtils; 11 import android.text.format.DateUtils;
12 import android.view.accessibility.AccessibilityEvent; 12 import android.view.accessibility.AccessibilityEvent;
13 import android.widget.FrameLayout; 13 import android.widget.FrameLayout;
14 import android.widget.NumberPicker; 14 import android.widget.NumberPicker;
15 15
16 import java.util.Calendar; 16 import java.util.Calendar;
17 import java.util.TimeZone;
17 18
18 import org.chromium.content.R; 19 import org.chromium.content.R;
19 20
20 // This class is heavily based on android.widget.DatePicker. 21 // This class is heavily based on android.widget.DatePicker.
21 public abstract class TwoFieldDatePicker extends FrameLayout { 22 public abstract class TwoFieldDatePicker extends FrameLayout {
22 23
23 private NumberPicker mPositionInYearSpinner; 24 private NumberPicker mPositionInYearSpinner;
24 25
25 private NumberPicker mYearSpinner; 26 private NumberPicker mYearSpinner;
26 27
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 throw new IllegalArgumentException(); 79 throw new IllegalArgumentException();
79 } 80 }
80 81
81 // now set the date to the adjusted one 82 // now set the date to the adjusted one
82 setCurrentDate(year, positionInYear); 83 setCurrentDate(year, positionInYear);
83 updateSpinners(); 84 updateSpinners();
84 notifyDateChanged(); 85 notifyDateChanged();
85 } 86 }
86 }; 87 };
87 88
88 mCurrentDate = Calendar.getInstance(); 89 mCurrentDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
89 if (minValue >= maxValue) { 90 if (minValue >= maxValue) {
90 mMinDate = Calendar.getInstance(); 91 mMinDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
91 mMinDate.set(0, 0, 1); 92 mMinDate.set(0, 0, 1);
92 mMaxDate = Calendar.getInstance(); 93 mMaxDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
93 mMaxDate.set(9999, 0, 1); 94 mMaxDate.set(9999, 0, 1);
94 } else { 95 } else {
95 mMinDate = createDateFromValue(minValue); 96 mMinDate = createDateFromValue(minValue);
96 mMaxDate = createDateFromValue(maxValue); 97 mMaxDate = createDateFromValue(maxValue);
97 } 98 }
98 99
99 // month 100 // month
100 mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_ye ar); 101 mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_ye ar);
101 mPositionInYearSpinner.setOnLongPressUpdateInterval(200); 102 mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
102 mPositionInYearSpinner.setOnValueChangedListener(onChangeListener); 103 mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);
(...skipping 23 matching lines...) Expand all
126 public boolean isNewDate(int year, int positionInYear) { 127 public boolean isNewDate(int year, int positionInYear) {
127 return (getYear() != year || getPositionInYear() != positionInYear); 128 return (getYear() != year || getPositionInYear() != positionInYear);
128 } 129 }
129 130
130 /** 131 /**
131 * Subclasses know the semantics of @value, and need to return 132 * Subclasses know the semantics of @value, and need to return
132 * a Calendar corresponding to it. 133 * a Calendar corresponding to it.
133 */ 134 */
134 protected abstract Calendar createDateFromValue(long value); 135 protected abstract Calendar createDateFromValue(long value);
135 136
136 /** 137 /**
newt (away) 2013/11/04 17:35:55 javadoc
keishi 2013/11/05 07:23:42 Done.
138 */
139 protected abstract long valueFromDate(int year, int positionInYear);
140
141 /**
137 * Updates the current date. 142 * Updates the current date.
138 * 143 *
139 * @param year The year. 144 * @param year The year.
140 * @param positionInYear The month or week in year. 145 * @param positionInYear The month or week in year.
141 */ 146 */
142 public void updateDate(int year, int positionInYear) { 147 public void updateDate(int year, int positionInYear) {
143 if (!isNewDate(year, positionInYear)) { 148 if (!isNewDate(year, positionInYear)) {
144 return; 149 return;
145 } 150 }
146 setCurrentDate(year, positionInYear); 151 setCurrentDate(year, positionInYear);
(...skipping 28 matching lines...) Expand all
175 } 180 }
176 181
177 /** 182 /**
178 * @return The selected year. 183 * @return The selected year.
179 */ 184 */
180 public int getYear() { 185 public int getYear() {
181 return mCurrentDate.get(Calendar.YEAR); 186 return mCurrentDate.get(Calendar.YEAR);
182 } 187 }
183 188
184 /** 189 /**
190 * @return The selected value.
191 */
192 public long getValue() {
193 return valueFromDate(getYear(), getPositionInYear());
194 }
195
196 /**
185 * @return The selected month or week. 197 * @return The selected month or week.
186 */ 198 */
187 public abstract int getPositionInYear(); 199 public abstract int getPositionInYear();
188 200
189 protected abstract int getMaxYear(); 201 protected abstract int getMaxYear();
190 202
191 protected abstract int getMinYear(); 203 protected abstract int getMinYear();
192 204
193 protected abstract int getMaxPositionInYear(int year); 205 protected abstract int getMaxPositionInYear(int year);
194 206
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 /** 251 /**
240 * Notifies the listener, if such, for a change in the selected date. 252 * Notifies the listener, if such, for a change in the selected date.
241 */ 253 */
242 protected void notifyDateChanged() { 254 protected void notifyDateChanged() {
243 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); 255 sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
244 if (mMonthOrWeekChangedListener != null) { 256 if (mMonthOrWeekChangedListener != null) {
245 mMonthOrWeekChangedListener.onMonthOrWeekChanged(this, getYear(), ge tPositionInYear()); 257 mMonthOrWeekChangedListener.onMonthOrWeekChanged(this, getYear(), ge tPositionInYear());
246 } 258 }
247 } 259 }
248 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698