OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.app.AlertDialog; | 7 import android.app.AlertDialog; |
8 import android.app.DatePickerDialog; | 8 import android.app.DatePickerDialog; |
9 import android.app.DatePickerDialog.OnDateSetListener; | 9 import android.app.DatePickerDialog.OnDateSetListener; |
10 import android.app.TimePickerDialog.OnTimeSetListener; | 10 import android.app.TimePickerDialog.OnTimeSetListener; |
11 import android.content.Context; | 11 import android.content.Context; |
12 import android.content.DialogInterface; | 12 import android.content.DialogInterface; |
13 import android.content.DialogInterface.OnDismissListener; | 13 import android.content.DialogInterface.OnDismissListener; |
14 import android.text.format.DateFormat; | 14 import android.text.format.DateFormat; |
15 import android.text.format.Time; | 15 import android.text.format.Time; |
16 import android.view.View; | |
17 import android.widget.AdapterView; | |
16 import android.widget.DatePicker; | 18 import android.widget.DatePicker; |
19 import android.widget.ListView; | |
20 import android.widget.SimpleAdapter; | |
21 import android.widget.TextView; | |
17 import android.widget.TimePicker; | 22 import android.widget.TimePicker; |
18 | 23 |
19 import org.chromium.content.R; | 24 import org.chromium.content.R; |
20 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList ener; | 25 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList ener; |
21 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel dTimeSetListener; | 26 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel dTimeSetListener; |
22 | 27 |
28 import java.util.Arrays; | |
23 import java.util.Calendar; | 29 import java.util.Calendar; |
30 import java.util.Date; | |
31 import java.util.GregorianCalendar; | |
32 import java.util.TimeZone; | |
33 import java.util.concurrent.TimeUnit; | |
24 | 34 |
25 public class InputDialogContainer { | 35 public class InputDialogContainer { |
26 | 36 |
27 interface InputActionDelegate { | 37 interface InputActionDelegate { |
28 void cancelDateTimeDialog(); | 38 void cancelDateTimeDialog(); |
29 void replaceDateTime(int dialogType, | 39 void replaceDateTime(double value); |
30 int year, int month, int day, int hour, int minute, int second, int milli, int week); | |
31 } | 40 } |
32 | 41 |
33 // Default values used in Time representations of selected date/time before formatting. | |
34 // They are never displayed to the user. | |
35 private static final int YEAR_DEFAULT = 1970; | |
36 private static final int MONTH_DEFAULT = 0; | |
37 private static final int MONTHDAY_DEFAULT = 1; | |
38 private static final int HOUR_DEFAULT = 0; | |
39 private static final int MINUTE_DEFAULT = 0; | |
40 private static final int WEEK_DEFAULT = 0; | |
41 | |
42 // Date formats as accepted by Time.format. | |
43 private static final String HTML_DATE_FORMAT = "%Y-%m-%d"; | |
44 private static final String HTML_TIME_FORMAT = "%H:%M"; | |
45 // For datetime we always send selected time as UTC, as we have no timezone selector. | |
46 // This is consistent with other browsers. | |
47 private static final String HTML_DATE_TIME_FORMAT = "%Y-%m-%dT%H:%MZ"; | |
48 private static final String HTML_DATE_TIME_LOCAL_FORMAT = "%Y-%m-%dT%H:%M"; | |
49 private static final String HTML_MONTH_FORMAT = "%Y-%m"; | |
50 private static final String HTML_WEEK_FORMAT = "%Y-%w"; | |
51 | |
52 private static int sTextInputTypeDate; | 42 private static int sTextInputTypeDate; |
53 private static int sTextInputTypeDateTime; | 43 private static int sTextInputTypeDateTime; |
54 private static int sTextInputTypeDateTimeLocal; | 44 private static int sTextInputTypeDateTimeLocal; |
55 private static int sTextInputTypeMonth; | 45 private static int sTextInputTypeMonth; |
56 private static int sTextInputTypeTime; | 46 private static int sTextInputTypeTime; |
57 private static int sTextInputTypeWeek; | 47 private static int sTextInputTypeWeek; |
58 | 48 |
59 private final Context mContext; | 49 private final Context mContext; |
60 | 50 |
61 // Prevents sending two notifications (from onClick and from onDismiss) | 51 // Prevents sending two notifications (from onClick and from onDismiss) |
(...skipping 18 matching lines...) Expand all Loading... | |
80 return type == sTextInputTypeDate || type == sTextInputTypeTime | 70 return type == sTextInputTypeDate || type == sTextInputTypeTime |
81 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT imeLocal | 71 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT imeLocal |
82 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; | 72 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; |
83 } | 73 } |
84 | 74 |
85 InputDialogContainer(Context context, InputActionDelegate inputActionDelegat e) { | 75 InputDialogContainer(Context context, InputActionDelegate inputActionDelegat e) { |
86 mContext = context; | 76 mContext = context; |
87 mInputActionDelegate = inputActionDelegate; | 77 mInputActionDelegate = inputActionDelegate; |
88 } | 78 } |
89 | 79 |
90 private Time normalizeTime(int year, int month, int monthDay, | 80 void showPickerDialog(final int dialogType, double dialogValue, |
91 int hour, int minute, int second) { | 81 double min, double max, double step) { |
92 Time result = new Time(); | 82 Calendar cal; |
93 if (year == 0 && month == 0 && monthDay == 0 && hour == 0 && | 83 // |dialogValue|, |min|, |max| mean different things depending on the |d ialogType|. |
94 minute == 0 && second == 0) { | 84 // For input type=month is the number of months since 1970. |
95 Calendar cal = Calendar.getInstance(); | 85 // For input type=time it is milliseconds since midnight. |
96 result.set(cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), | 86 // For other types they are just milliseconds since 1970. |
97 cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DATE), | 87 // If |dialogValue| is NaN it means an empty value. We will show the cur rent time. |
98 cal.get(Calendar.MONTH), cal.get(Calendar.YEAR)); | 88 if (Double.isNaN(dialogValue)) { |
89 cal = Calendar.getInstance(); | |
90 cal.set(Calendar.MILLISECOND, 0); | |
99 } else { | 91 } else { |
100 result.set(second, minute, hour, monthDay, month, year); | 92 if (dialogType == sTextInputTypeMonth) { |
93 cal = MonthPicker.createDateFromValue(dialogValue); | |
94 } else if (dialogType == sTextInputTypeWeek) { | |
95 cal = WeekPicker.createDateFromValue(dialogValue); | |
96 } else { | |
97 GregorianCalendar gregorianCalendar = | |
98 new GregorianCalendar(TimeZone.getTimeZone("UTC")); | |
99 // According to the HTML spec we only use the Gregorian calendar | |
100 // so we ignore the Julian/Gregorian transition. | |
101 gregorianCalendar.setGregorianChange(new Date(Long.MIN_VALUE)); | |
102 gregorianCalendar.setTimeInMillis((long) dialogValue); | |
103 cal = gregorianCalendar; | |
104 } | |
101 } | 105 } |
102 return result; | 106 if (dialogType == sTextInputTypeDate) { |
107 showPickerDialog(dialogType, | |
108 cal.get(Calendar.YEAR), | |
109 cal.get(Calendar.MONTH), | |
110 cal.get(Calendar.DAY_OF_MONTH), | |
111 0, 0, 0, 0, 0, min, max, step); | |
112 } else if (dialogType == sTextInputTypeTime) { | |
113 showPickerDialog(dialogType, 0, 0, 0, | |
114 cal.get(Calendar.HOUR_OF_DAY), | |
115 cal.get(Calendar.MINUTE), | |
116 0, 0, 0, min, max, step); | |
117 } else if (dialogType == sTextInputTypeDateTime || | |
118 dialogType == sTextInputTypeDateTimeLocal) { | |
119 showPickerDialog(dialogType, | |
120 cal.get(Calendar.YEAR), | |
121 cal.get(Calendar.MONTH), | |
122 cal.get(Calendar.DAY_OF_MONTH), | |
123 cal.get(Calendar.HOUR_OF_DAY), | |
124 cal.get(Calendar.MINUTE), | |
125 cal.get(Calendar.SECOND), | |
126 cal.get(Calendar.MILLISECOND), | |
127 0, min, max, step); | |
128 } else if (dialogType == sTextInputTypeMonth) { | |
129 showPickerDialog(dialogType, cal.get(Calendar.YEAR), cal.get(Calenda r.MONTH), 0, | |
130 0, 0, 0, 0, 0, min, max, step); | |
131 } else if (dialogType == sTextInputTypeWeek) { | |
132 int year = WeekPicker.getISOWeekYearForDate(cal); | |
133 int week = WeekPicker.getWeekForDate(cal); | |
134 showPickerDialog(dialogType, year, 0, 0, 0, 0, 0, 0, week, min, max, step); | |
135 } | |
103 } | 136 } |
104 | 137 |
105 void showDialog(final int dialogType, int year, int month, int monthDay, | 138 void showSuggestionDialog(final int dialogType, |
106 int hour, int minute, int second, int milli, int week, | 139 final double dialogValue, |
107 double min, double max, double step) { | 140 final double min, final double max, final double step, |
141 DateTimeSuggestion[] suggestions) { | |
142 ListView suggestionListView = new ListView(mContext); | |
143 final DateTimeSuggestionListAdapter adapter = | |
144 new DateTimeSuggestionListAdapter(mContext, Arrays.asList(suggestion s)); | |
145 suggestionListView.setAdapter(adapter); | |
146 suggestionListView.setOnItemClickListener(new AdapterView.OnItemClickLis tener() { | |
147 @Override | |
148 public void onItemClick(AdapterView<?> parent, View view, int positi on, long id) { | |
149 if (position == adapter.getCount() - 1) { | |
150 dismissDialog(); | |
151 showPickerDialog(dialogType, dialogValue, min, max, step); | |
152 } else { | |
153 double suggestionValue = adapter.getItem(position).value(); | |
154 mInputActionDelegate.replaceDateTime(suggestionValue); | |
155 dismissDialog(); | |
156 mDialogAlreadyDismissed = true; | |
157 } | |
158 } | |
159 }); | |
160 | |
161 int dialogTitleId = R.string.date_picker_dialog_title; | |
162 if (dialogType == sTextInputTypeTime) { | |
163 dialogTitleId = R.string.time_picker_dialog_title; | |
164 } else if (dialogType == sTextInputTypeDateTime || | |
165 dialogType == sTextInputTypeDateTimeLocal) { | |
166 dialogTitleId = R.string.date_time_picker_dialog_title; | |
167 } else if (dialogType == sTextInputTypeMonth) { | |
168 dialogTitleId = R.string.month_picker_dialog_title; | |
169 } else if (dialogType == sTextInputTypeWeek) { | |
170 dialogTitleId = R.string.week_picker_dialog_title; | |
171 } | |
172 | |
173 mDialog = new AlertDialog.Builder(mContext) | |
174 .setTitle(dialogTitleId) | |
175 .setView(suggestionListView) | |
176 .setOnDismissListener(new DialogInterface.OnDismissListener() { | |
177 @Override | |
178 public void onDismiss(DialogInterface dialog) { | |
179 if (mDialog == dialog && !mDialogAlreadyDismissed) { | |
180 mDialogAlreadyDismissed = true; | |
181 mInputActionDelegate.cancelDateTimeDialog(); | |
182 } | |
183 } | |
184 }) | |
185 .setNegativeButton(mContext.getText(android.R.string.cancel), | |
186 new DialogInterface.OnClickListener() { | |
187 @Override | |
188 public void onClick(DialogInterface dialog, int which) { | |
189 dismissDialog(); | |
190 } | |
191 }) | |
192 .create(); | |
193 | |
194 mDialogAlreadyDismissed = false; | |
195 mDialog.show(); | |
196 } | |
197 | |
198 void showDialog(final int type, final double value, | |
199 double min, double max, double step, | |
200 DateTimeSuggestion[] suggestions) { | |
201 // When the web page asks to show a dialog while there is one already op en, | |
202 // dismiss the old one. | |
203 dismissDialog(); | |
204 if (suggestions == null) { | |
205 showPickerDialog(type, value, min, max, step); | |
206 } else { | |
207 showSuggestionDialog(type, value, min, max, step, suggestions); | |
208 } | |
209 } | |
210 | |
211 void showPickerDialog(final int dialogType, | |
212 int year, int month, int monthDay, | |
213 int hourOfDay, int minute, int second, int millis, int week, | |
214 double min, double max, double step) { | |
108 if (isDialogShowing()) mDialog.dismiss(); | 215 if (isDialogShowing()) mDialog.dismiss(); |
109 | 216 |
110 // Java Date dialogs like longs but Blink prefers doubles.. | |
111 // Both parameters mean different things depending on the type | |
112 // For input type=month min and max come as number on months since 1970 | |
113 // For other types (including type=time) they are just milliseconds sinc e 1970 | |
114 // In any case the cast here is safe given the above restrictions. | |
115 long minTime = (long) min; | |
116 long maxTime = (long) max; | |
117 int stepTime = (int) step; | 217 int stepTime = (int) step; |
118 | 218 |
119 if (milli > 1000) { | |
120 second += milli / 1000; | |
121 milli %= 1000; | |
122 } | |
123 Time time = normalizeTime(year, month, monthDay, hour, minute, second); | |
124 if (dialogType == sTextInputTypeDate) { | 219 if (dialogType == sTextInputTypeDate) { |
125 DatePickerDialog dialog = new DatePickerDialog(mContext, | 220 DatePickerDialog dialog = new DatePickerDialog(mContext, |
126 new DateListener(dialogType), time.year, time.month, time.mo nthDay); | 221 new DateListener(dialogType), |
222 year, month, monthDay); | |
127 DateDialogNormalizer.normalize(dialog.getDatePicker(), dialog, | 223 DateDialogNormalizer.normalize(dialog.getDatePicker(), dialog, |
128 time.year, time.month, time.monthDay, 0, 0, minTime, maxTime ); | 224 year, month, monthDay, |
225 0, 0, | |
226 (long) min, (long) max); | |
bulach
2013/12/04 10:37:54
nit: as above, perhaps best to change this method
keishi
2013/12/04 12:21:24
DateDialogNormalizer will only take min/max as num
| |
129 | 227 |
130 dialog.setTitle(mContext.getText(R.string.date_picker_dialog_title)) ; | 228 dialog.setTitle(mContext.getText(R.string.date_picker_dialog_title)) ; |
131 mDialog = dialog; | 229 mDialog = dialog; |
132 } else if (dialogType == sTextInputTypeTime) { | 230 } else if (dialogType == sTextInputTypeTime) { |
133 mDialog = new MultiFieldTimePickerDialog( | 231 mDialog = new MultiFieldTimePickerDialog( |
134 mContext, 0 /* theme */ , | 232 mContext, 0 /* theme */ , |
135 time.hour, time.minute, time.second, milli, | 233 hourOfDay, minute, second, millis, |
136 (int) minTime, (int) maxTime, stepTime, | 234 (int) min, (int) max, stepTime, |
137 DateFormat.is24HourFormat(mContext), | 235 DateFormat.is24HourFormat(mContext), |
138 new FullTimeListener(dialogType)); | 236 new FullTimeListener(dialogType)); |
139 } else if (dialogType == sTextInputTypeDateTime || | 237 } else if (dialogType == sTextInputTypeDateTime || |
140 dialogType == sTextInputTypeDateTimeLocal) { | 238 dialogType == sTextInputTypeDateTimeLocal) { |
141 mDialog = new DateTimePickerDialog(mContext, | 239 mDialog = new DateTimePickerDialog(mContext, |
142 new DateTimeListener(dialogType), | 240 new DateTimeListener(dialogType), |
143 time.year, time.month, time.monthDay, | 241 year, month, monthDay, |
144 time.hour, time.minute, DateFormat.is24HourFormat(mContext), | 242 hourOfDay, minute, |
145 minTime, maxTime); | 243 DateFormat.is24HourFormat(mContext), min, max); |
146 } else if (dialogType == sTextInputTypeMonth) { | 244 } else if (dialogType == sTextInputTypeMonth) { |
147 mDialog = new MonthPickerDialog(mContext, new MonthOrWeekListener(di alogType), | 245 mDialog = new MonthPickerDialog(mContext, new MonthOrWeekListener(di alogType), |
148 time.year, time.month, minTime, maxTime); | 246 year, month, min, max); |
149 } else if (dialogType == sTextInputTypeWeek) { | 247 } else if (dialogType == sTextInputTypeWeek) { |
150 if (week == 0) { | |
151 Calendar cal = Calendar.getInstance(); | |
152 year = WeekPicker.getISOWeekYearForDate(cal); | |
153 week = WeekPicker.getWeekForDate(cal); | |
154 } | |
155 mDialog = new WeekPickerDialog(mContext, new MonthOrWeekListener(dia logType), | 248 mDialog = new WeekPickerDialog(mContext, new MonthOrWeekListener(dia logType), |
156 year, week, minTime, maxTime); | 249 year, week, min, max); |
157 } | 250 } |
158 | 251 |
159 mDialog.setButton(DialogInterface.BUTTON_POSITIVE, | 252 mDialog.setButton(DialogInterface.BUTTON_POSITIVE, |
160 mContext.getText(R.string.date_picker_dialog_set), | 253 mContext.getText(R.string.date_picker_dialog_set), |
161 (DialogInterface.OnClickListener) mDialog); | 254 (DialogInterface.OnClickListener) mDialog); |
162 | 255 |
163 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, | 256 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, |
164 mContext.getText(android.R.string.cancel), | 257 mContext.getText(android.R.string.cancel), |
165 (DialogInterface.OnClickListener) null); | 258 (DialogInterface.OnClickListener) null); |
166 | 259 |
167 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, | 260 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, |
168 mContext.getText(R.string.date_picker_dialog_clear), | 261 mContext.getText(R.string.date_picker_dialog_clear), |
169 new DialogInterface.OnClickListener() { | 262 new DialogInterface.OnClickListener() { |
170 @Override | 263 @Override |
171 public void onClick(DialogInterface dialog, int which) { | 264 public void onClick(DialogInterface dialog, int which) { |
172 mDialogAlreadyDismissed = true; | 265 mDialogAlreadyDismissed = true; |
173 mInputActionDelegate.replaceDateTime(dialogType, 0, 0, 0 , 0, 0, 0, 0, 0); | 266 mInputActionDelegate.replaceDateTime(Double.NaN); |
174 } | 267 } |
175 }); | 268 }); |
176 | 269 |
177 mDialog.setOnDismissListener( | 270 mDialog.setOnDismissListener( |
178 new OnDismissListener() { | 271 new OnDismissListener() { |
179 @Override | 272 @Override |
180 public void onDismiss(final DialogInterface dialog) { | 273 public void onDismiss(final DialogInterface dialog) { |
181 if (!mDialogAlreadyDismissed) { | 274 if (!mDialogAlreadyDismissed) { |
182 mDialogAlreadyDismissed = true; | 275 mDialogAlreadyDismissed = true; |
183 mInputActionDelegate.cancelDateTimeDialog(); | 276 mInputActionDelegate.cancelDateTimeDialog(); |
(...skipping 15 matching lines...) Expand all Loading... | |
199 | 292 |
200 private class DateListener implements OnDateSetListener { | 293 private class DateListener implements OnDateSetListener { |
201 private final int mDialogType; | 294 private final int mDialogType; |
202 | 295 |
203 DateListener(int dialogType) { | 296 DateListener(int dialogType) { |
204 mDialogType = dialogType; | 297 mDialogType = dialogType; |
205 } | 298 } |
206 | 299 |
207 @Override | 300 @Override |
208 public void onDateSet(DatePicker view, int year, int month, int monthDay ) { | 301 public void onDateSet(DatePicker view, int year, int month, int monthDay ) { |
209 if (!mDialogAlreadyDismissed) { | 302 setFieldDateTimeValue(mDialogType, year, month, monthDay, 0, 0, 0, 0 , 0); |
210 setFieldDateTimeValue(mDialogType, | |
211 year, month, monthDay, | |
212 HOUR_DEFAULT, MINUTE_DEFAULT, WEEK_DEFAULT, | |
213 HTML_DATE_FORMAT); | |
214 } | |
215 } | 303 } |
216 } | 304 } |
217 | 305 |
218 private class TimeListener implements OnTimeSetListener { | |
219 private final int mDialogType; | |
220 | |
221 TimeListener(int dialogType) { | |
222 mDialogType = dialogType; | |
223 } | |
224 | |
225 @Override | |
226 public void onTimeSet(TimePicker view, int hourOfDay, int minute) { | |
227 if (!mDialogAlreadyDismissed) { | |
228 setFieldDateTimeValue(mDialogType, | |
229 YEAR_DEFAULT, MONTH_DEFAULT, MONTHDAY_DEFAULT, | |
230 hourOfDay, minute, WEEK_DEFAULT, HTML_TIME_FORMAT); | |
231 } | |
232 } | |
233 } | |
234 | |
235 private class FullTimeListener implements OnMultiFieldTimeSetListener { | 306 private class FullTimeListener implements OnMultiFieldTimeSetListener { |
236 private final int mDialogType; | 307 private final int mDialogType; |
237 FullTimeListener(int dialogType) { | 308 FullTimeListener(int dialogType) { |
238 mDialogType = dialogType; | 309 mDialogType = dialogType; |
239 } | 310 } |
240 | 311 |
241 @Override | 312 @Override |
242 public void onTimeSet(int hourOfDay, int minute, int second, int milli) { | 313 public void onTimeSet(int hourOfDay, int minute, int second, int milli) { |
243 if (!mDialogAlreadyDismissed) { | 314 setFieldDateTimeValue(mDialogType, 0, 0, 0, hourOfDay, minute, secon d, milli, 0); |
244 setFieldDateTimeValue(mDialogType, | |
245 YEAR_DEFAULT, MONTH_DEFAULT, MONTHDAY_DEFAULT, | |
246 hourOfDay, minute, second, milli, WEEK_DEFAULT, HTML_TIM E_FORMAT); | |
247 } | |
248 } | 315 } |
249 } | 316 } |
250 | 317 |
251 private class DateTimeListener implements OnDateTimeSetListener { | 318 private class DateTimeListener implements OnDateTimeSetListener { |
252 private final boolean mLocal; | 319 private final boolean mLocal; |
253 private final int mDialogType; | 320 private final int mDialogType; |
254 | 321 |
255 public DateTimeListener(int dialogType) { | 322 public DateTimeListener(int dialogType) { |
256 mLocal = dialogType == sTextInputTypeDateTimeLocal; | 323 mLocal = dialogType == sTextInputTypeDateTimeLocal; |
257 mDialogType = dialogType; | 324 mDialogType = dialogType; |
258 } | 325 } |
259 | 326 |
260 @Override | 327 @Override |
261 public void onDateTimeSet(DatePicker dateView, TimePicker timeView, | 328 public void onDateTimeSet(DatePicker dateView, TimePicker timeView, |
262 int year, int month, int monthDay, | 329 int year, int month, int monthDay, |
263 int hourOfDay, int minute) { | 330 int hourOfDay, int minute) { |
264 if (!mDialogAlreadyDismissed) { | 331 setFieldDateTimeValue(mDialogType, year, month, monthDay, hourOfDay, minute, 0, 0, 0); |
265 setFieldDateTimeValue(mDialogType, year, month, monthDay, | |
266 hourOfDay, minute, WEEK_DEFAULT, | |
267 mLocal ? HTML_DATE_TIME_LOCAL_FORMAT : HTML_DATE_TIME_FO RMAT); | |
268 } | |
269 } | 332 } |
270 } | 333 } |
271 | 334 |
272 private class MonthOrWeekListener implements TwoFieldDatePickerDialog.OnValu eSetListener { | 335 private class MonthOrWeekListener implements TwoFieldDatePickerDialog.OnValu eSetListener { |
273 private final int mDialogType; | 336 private final int mDialogType; |
274 | 337 |
275 MonthOrWeekListener(int dialogType) { | 338 MonthOrWeekListener(int dialogType) { |
276 mDialogType = dialogType; | 339 mDialogType = dialogType; |
277 } | 340 } |
278 | 341 |
279 @Override | 342 @Override |
280 public void onValueSet(int year, int positionInYear) { | 343 public void onValueSet(int year, int positionInYear) { |
281 if (!mDialogAlreadyDismissed) { | 344 if (mDialogType == sTextInputTypeMonth) { |
282 if (mDialogType == sTextInputTypeMonth) { | 345 setFieldDateTimeValue(mDialogType, year, positionInYear, 0, 0, 0 , 0, 0, 0); |
283 setFieldDateTimeValue(mDialogType, year, positionInYear, MON THDAY_DEFAULT, | 346 } else { |
284 HOUR_DEFAULT, MINUTE_DEFAULT, WEEK_DEFAULT, | 347 setFieldDateTimeValue(mDialogType, year, 0, 0, 0, 0, 0, 0, posit ionInYear); |
285 HTML_MONTH_FORMAT); | |
286 } else { | |
287 setFieldDateTimeValue(mDialogType, year, MONTH_DEFAULT, MONT HDAY_DEFAULT, | |
288 HOUR_DEFAULT, MINUTE_DEFAULT, positionInYear, HTML_W EEK_FORMAT); | |
289 } | |
290 } | 348 } |
291 } | 349 } |
292 } | 350 } |
293 | 351 |
294 private void setFieldDateTimeValue(int dialogType, | 352 protected void setFieldDateTimeValue(int dialogType, |
295 int year, int month, int monthDay, int hourOfDay, | 353 int year, int month, int monthDay, |
296 int minute, int week, String dateFormat) { | 354 int hourOfDay, int minute, int second, in t millis, |
355 int week) { | |
297 // Prevents more than one callback being sent to the native | 356 // Prevents more than one callback being sent to the native |
298 // side when the dialog triggers multiple events. | 357 // side when the dialog triggers multiple events. |
358 if (mDialogAlreadyDismissed) | |
359 return; | |
299 mDialogAlreadyDismissed = true; | 360 mDialogAlreadyDismissed = true; |
300 | 361 |
301 mInputActionDelegate.replaceDateTime(dialogType, | 362 double value = 0; |
302 year, month, monthDay, hourOfDay, minute, 0 /* second */, 0 /* milli */, week); | 363 if (dialogType == sTextInputTypeMonth) { |
303 } | 364 mInputActionDelegate.replaceDateTime((year - 1970) * 12 + month); |
304 | 365 } else if (dialogType == sTextInputTypeWeek) { |
305 private void setFieldDateTimeValue(int dialogType, | 366 mInputActionDelegate.replaceDateTime( |
306 int year, int month, int monthDay, int hourOfDay, | 367 WeekPicker.createDateFromWeek(year, week).getTimeInMillis()); |
307 int minute, int second, int milli, int week, String dateFormat) { | 368 } else if (dialogType == sTextInputTypeTime) { |
308 // Prevents more than one callback being sent to the native | 369 mInputActionDelegate.replaceDateTime(TimeUnit.HOURS.toMillis(hourOfD ay) + |
309 // side when the dialog triggers multiple events. | 370 TimeUnit.MINUTES.toMillis(minut e) + |
310 mDialogAlreadyDismissed = true; | 371 TimeUnit.SECONDS.toMillis(secon d) + |
311 | 372 millis); |
312 mInputActionDelegate.replaceDateTime( | 373 } else { |
313 dialogType, year, month, monthDay, hourOfDay, minute, second, milli, week); | 374 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
375 cal.clear(); | |
bulach
2013/12/04 10:37:54
nit: unindent
keishi
2013/12/04 12:21:24
Done.
| |
376 cal.set(Calendar.YEAR, year); | |
377 cal.set(Calendar.MONTH, month); | |
378 cal.set(Calendar.DAY_OF_MONTH, monthDay); | |
379 cal.set(Calendar.HOUR_OF_DAY, hourOfDay); | |
380 cal.set(Calendar.MINUTE, minute); | |
381 cal.set(Calendar.SECOND, second); | |
382 cal.set(Calendar.MILLISECOND, millis); | |
383 mInputActionDelegate.replaceDateTime((double) cal.getTimeInMillis()) ; | |
384 } | |
314 } | 385 } |
315 } | 386 } |
OLD | NEW |