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

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

Issue 11418295: Use WebCore:DateTimeChooser for date/time form types instead of considering them text fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 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 (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; 5 package org.chromium.content.browser;
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;
(...skipping 11 matching lines...) Expand all
22 import org.chromium.content.browser.MonthPickerDialog.OnMonthSetListener; 22 import org.chromium.content.browser.MonthPickerDialog.OnMonthSetListener;
23 import org.chromium.content.R; 23 import org.chromium.content.R;
24 24
25 import java.text.ParseException; 25 import java.text.ParseException;
26 import java.text.SimpleDateFormat; 26 import java.text.SimpleDateFormat;
27 import java.util.Date; 27 import java.util.Date;
28 28
29 class InputDialogContainer { 29 class InputDialogContainer {
30 30
31 interface InputActionDelegate { 31 interface InputActionDelegate {
32 void clearFocus(); 32 void cancelDateTimeDialog();
33 void replaceText(String text); 33 void replaceDateTime(String dateTime);
34 } 34 }
35 35
36 // Default values used in Time representations of selected date/time before formatting. 36 // Default values used in Time representations of selected date/time before formatting.
37 // They are never displayed to the user. 37 // They are never displayed to the user.
38 private static final int YEAR_DEFAULT = 1970; 38 private static final int YEAR_DEFAULT = 1970;
39 private static final int MONTH_DEFAULT = 0; 39 private static final int MONTH_DEFAULT = 0;
40 private static final int MONTHDAY_DEFAULT = 1; 40 private static final int MONTHDAY_DEFAULT = 1;
41 private static final int HOUR_DEFAULT = 0; 41 private static final int HOUR_DEFAULT = 0;
42 private static final int MINUTE_DEFAULT = 0; 42 private static final int MINUTE_DEFAULT = 0;
43 43
(...skipping 13 matching lines...) Expand all
57 private static final String PARSE_DATE_TIME_LOCAL_FORMAT = "yyyy-MM-dd'T'HH: mm"; 57 private static final String PARSE_DATE_TIME_LOCAL_FORMAT = "yyyy-MM-dd'T'HH: mm";
58 private static final String PARSE_MONTH_FORMAT = "yyyy-MM"; 58 private static final String PARSE_MONTH_FORMAT = "yyyy-MM";
59 59
60 private static int sTextInputTypeDate; 60 private static int sTextInputTypeDate;
61 private static int sTextInputTypeDateTime; 61 private static int sTextInputTypeDateTime;
62 private static int sTextInputTypeDateTimeLocal; 62 private static int sTextInputTypeDateTimeLocal;
63 private static int sTextInputTypeMonth; 63 private static int sTextInputTypeMonth;
64 private static int sTextInputTypeTime; 64 private static int sTextInputTypeTime;
65 65
66 private Context mContext; 66 private Context mContext;
67 private boolean mDialogCanceled; 67
68 // Prevents sending two notifications (from onClick and from onDismiss)
69 private boolean mDialogAlreadyDismissed;
70
68 private AlertDialog mDialog; 71 private AlertDialog mDialog;
69 private InputActionDelegate mInputActionDelegate; 72 private InputActionDelegate mInputActionDelegate;
70 73
71 static void initializeInputTypes(int textInputTypeDate, int textInputTypeDat eTime, 74 static void initializeInputTypes(int textInputTypeDate, int textInputTypeDat eTime,
72 int textInputTypeDateTimeLocal, int textInputTypeMonth, int textInpu tTypeTime) { 75 int textInputTypeDateTimeLocal, int textInputTypeMonth, int textInpu tTypeTime) {
73 sTextInputTypeDate = textInputTypeDate; 76 sTextInputTypeDate = textInputTypeDate;
74 sTextInputTypeDateTime = textInputTypeDateTime; 77 sTextInputTypeDateTime = textInputTypeDateTime;
75 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal; 78 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal;
76 sTextInputTypeMonth = textInputTypeMonth; 79 sTextInputTypeMonth = textInputTypeMonth;
77 sTextInputTypeTime = textInputTypeTime; 80 sTextInputTypeTime = textInputTypeTime;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 114
112 mDialog.setButton(DialogInterface.BUTTON_POSITIVE, 115 mDialog.setButton(DialogInterface.BUTTON_POSITIVE,
113 mContext.getText(R.string.date_picker_dialog_set), 116 mContext.getText(R.string.date_picker_dialog_set),
114 (DialogInterface.OnClickListener) mDialog); 117 (DialogInterface.OnClickListener) mDialog);
115 118
116 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, 119 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
117 mContext.getText(android.R.string.cancel), 120 mContext.getText(android.R.string.cancel),
118 new DialogInterface.OnClickListener() { 121 new DialogInterface.OnClickListener() {
119 @Override 122 @Override
120 public void onClick(DialogInterface dialog, int which) { 123 public void onClick(DialogInterface dialog, int which) {
121 mDialogCanceled = true; 124 mDialogAlreadyDismissed = true;
125 mInputActionDelegate.cancelDateTimeDialog();
122 } 126 }
123 }); 127 });
124 128
125 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, 129 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
126 mContext.getText(R.string.date_picker_dialog_clear), 130 mContext.getText(R.string.date_picker_dialog_clear),
127 new DialogInterface.OnClickListener() { 131 new DialogInterface.OnClickListener() {
128 @Override 132 @Override
129 public void onClick(DialogInterface dialog, int which) { 133 public void onClick(DialogInterface dialog, int which) {
130 mDialogCanceled = true; 134 mDialogAlreadyDismissed = true;
131 mInputActionDelegate.replaceText(""); 135 mInputActionDelegate.replaceDateTime("");
132 } 136 }
133 }); 137 });
134 138
135 mDialog.setOnDismissListener(new OnDismissListener() { 139 mDialogAlreadyDismissed = false;
136 @Override
137 public void onDismiss(DialogInterface dialog) {
138 mInputActionDelegate.clearFocus();
139 }
140 });
141 mDialogCanceled = false;
142 mDialog.show(); 140 mDialog.show();
143 } 141 }
144 142
145 boolean isDialogShowing() { 143 boolean isDialogShowing() {
146 return mDialog != null && mDialog.isShowing(); 144 return mDialog != null && mDialog.isShowing();
147 } 145 }
148 146
149 void dismissDialog() { 147 void dismissDialog() {
150 if (isDialogShowing()) mDialog.dismiss(); 148 if (isDialogShowing()) mDialog.dismiss();
151 } 149 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 result = new Time(); 191 result = new Time();
194 result.setToNow(); 192 result.setToNow();
195 } 193 }
196 194
197 return result; 195 return result;
198 } 196 }
199 197
200 private class DateListener implements OnDateSetListener { 198 private class DateListener implements OnDateSetListener {
201 @Override 199 @Override
202 public void onDateSet(DatePicker view, int year, int month, int monthDay ) { 200 public void onDateSet(DatePicker view, int year, int month, int monthDay ) {
203 if (!mDialogCanceled) { 201 if (!mDialogAlreadyDismissed) {
204 setFieldDateTimeValue(year, month, monthDay, HOUR_DEFAULT, MINUT E_DEFAULT, 202 setFieldDateTimeValue(year, month, monthDay, HOUR_DEFAULT, MINUT E_DEFAULT,
205 HTML_DATE_FORMAT); 203 HTML_DATE_FORMAT);
206 } 204 }
207 } 205 }
208 } 206 }
209 207
210 private class TimeListener implements OnTimeSetListener { 208 private class TimeListener implements OnTimeSetListener {
211 @Override 209 @Override
212 public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 210 public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
213 if (!mDialogCanceled) { 211 if (!mDialogAlreadyDismissed) {
214 setFieldDateTimeValue(YEAR_DEFAULT, MONTH_DEFAULT, MONTHDAY_DEFA ULT, 212 setFieldDateTimeValue(YEAR_DEFAULT, MONTH_DEFAULT, MONTHDAY_DEFA ULT,
215 hourOfDay, minute, HTML_TIME_FORMAT); 213 hourOfDay, minute, HTML_TIME_FORMAT);
216 } 214 }
217 } 215 }
218 } 216 }
219 217
220 private class DateTimeListener implements OnDateTimeSetListener { 218 private class DateTimeListener implements OnDateTimeSetListener {
221 private boolean mLocal; 219 private boolean mLocal;
222 220
223 public DateTimeListener(boolean local) { 221 public DateTimeListener(boolean local) {
224 mLocal = local; 222 mLocal = local;
225 } 223 }
226 224
227 @Override 225 @Override
228 public void onDateTimeSet(DatePicker dateView, TimePicker timeView, 226 public void onDateTimeSet(DatePicker dateView, TimePicker timeView,
229 int year, int month, int monthDay, 227 int year, int month, int monthDay,
230 int hourOfDay, int minute) { 228 int hourOfDay, int minute) {
231 if (!mDialogCanceled) { 229 if (!mDialogAlreadyDismissed) {
232 setFieldDateTimeValue(year, month, monthDay, hourOfDay, minute, 230 setFieldDateTimeValue(year, month, monthDay, hourOfDay, minute,
233 mLocal ? HTML_DATE_TIME_LOCAL_FORMAT : HTML_DATE_TIME_FO RMAT); 231 mLocal ? HTML_DATE_TIME_LOCAL_FORMAT : HTML_DATE_TIME_FO RMAT);
234 } 232 }
235 } 233 }
236 } 234 }
237 235
238 private class MonthListener implements OnMonthSetListener { 236 private class MonthListener implements OnMonthSetListener {
239 @Override 237 @Override
240 public void onMonthSet(MonthPicker view, int year, int month) { 238 public void onMonthSet(MonthPicker view, int year, int month) {
241 if (!mDialogCanceled) { 239 if (!mDialogAlreadyDismissed) {
242 setFieldDateTimeValue(year, month, MONTHDAY_DEFAULT, 240 setFieldDateTimeValue(year, month, MONTHDAY_DEFAULT,
243 HOUR_DEFAULT, MINUTE_DEFAULT, HTML_MONTH_FORMAT); 241 HOUR_DEFAULT, MINUTE_DEFAULT, HTML_MONTH_FORMAT);
244 } 242 }
245 } 243 }
246 } 244 }
247 245
248 private void setFieldDateTimeValue(int year, int month, int monthDay, int ho urOfDay, 246 private void setFieldDateTimeValue(int year, int month, int monthDay, int ho urOfDay,
249 int minute, String dateFormat) { 247 int minute, String dateFormat) {
248 // Prevents more than one callback being sent to the native
249 // side when the dialog triggers multiple events.
250 mDialogAlreadyDismissed = true;
251
250 Time time = new Time(); 252 Time time = new Time();
251 time.year = year; 253 time.year = year;
252 time.month = month; 254 time.month = month;
253 time.monthDay = monthDay; 255 time.monthDay = monthDay;
254 time.hour = hourOfDay; 256 time.hour = hourOfDay;
255 time.minute = minute; 257 time.minute = minute;
256 mInputActionDelegate.replaceText(time.format(dateFormat)); 258 mInputActionDelegate.replaceDateTime(time.format(dateFormat));
257 } 259 }
258 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698