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