OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.ui.picker; |
6 | 6 |
7 import android.app.AlertDialog; | 7 import android.app.AlertDialog; |
8 import android.app.DatePickerDialog.OnDateSetListener; | 8 import android.app.DatePickerDialog.OnDateSetListener; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
11 import android.content.DialogInterface.OnDismissListener; | 11 import android.content.DialogInterface.OnDismissListener; |
12 import android.text.format.DateFormat; | 12 import android.text.format.DateFormat; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.widget.AdapterView; | 14 import android.widget.AdapterView; |
15 import android.widget.DatePicker; | 15 import android.widget.DatePicker; |
16 import android.widget.ListView; | 16 import android.widget.ListView; |
17 import android.widget.TimePicker; | 17 import android.widget.TimePicker; |
18 | 18 |
19 import org.chromium.content.R; | 19 import org.chromium.ui.R; |
20 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList
ener; | 20 import org.chromium.ui.picker.DateTimePickerDialog.OnDateTimeSetListener; |
21 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel
dTimeSetListener; | 21 import org.chromium.ui.picker.MultiFieldTimePickerDialog.OnMultiFieldTimeSetList
ener; |
22 | 22 |
23 import java.util.Arrays; | 23 import java.util.Arrays; |
24 import java.util.Calendar; | 24 import java.util.Calendar; |
25 import java.util.Date; | 25 import java.util.Date; |
26 import java.util.GregorianCalendar; | 26 import java.util.GregorianCalendar; |
27 import java.util.TimeZone; | 27 import java.util.TimeZone; |
28 import java.util.concurrent.TimeUnit; | 28 import java.util.concurrent.TimeUnit; |
29 | 29 |
30 /** | 30 /** |
31 * Opens the approprate date/time picker dialog for the given dialog type. | 31 * Opens the appropriate date/time picker dialog for the given dialog type. |
32 */ | 32 */ |
33 public class InputDialogContainer { | 33 public class InputDialogContainer { |
34 | 34 |
35 interface InputActionDelegate { | 35 public interface InputActionDelegate { |
36 void cancelDateTimeDialog(); | 36 void cancelDateTimeDialog(); |
37 void replaceDateTime(double value); | 37 void replaceDateTime(double value); |
38 } | 38 } |
39 | 39 |
40 private static int sTextInputTypeDate; | 40 private static int sTextInputTypeDate; |
41 private static int sTextInputTypeDateTime; | 41 private static int sTextInputTypeDateTime; |
42 private static int sTextInputTypeDateTimeLocal; | 42 private static int sTextInputTypeDateTimeLocal; |
43 private static int sTextInputTypeMonth; | 43 private static int sTextInputTypeMonth; |
44 private static int sTextInputTypeTime; | 44 private static int sTextInputTypeTime; |
45 private static int sTextInputTypeWeek; | 45 private static int sTextInputTypeWeek; |
46 | 46 |
47 private final Context mContext; | 47 private final Context mContext; |
48 | 48 |
49 // Prevents sending two notifications (from onClick and from onDismiss) | 49 // Prevents sending two notifications (from onClick and from onDismiss) |
50 private boolean mDialogAlreadyDismissed; | 50 private boolean mDialogAlreadyDismissed; |
51 | 51 |
52 private AlertDialog mDialog; | 52 private AlertDialog mDialog; |
53 private final InputActionDelegate mInputActionDelegate; | 53 private final InputActionDelegate mInputActionDelegate; |
54 | 54 |
55 static void initializeInputTypes(int textInputTypeDate, | 55 public static void initializeInputTypes(int textInputTypeDate, |
56 int textInputTypeDateTime, int textInputTypeDateTimeLocal, | 56 int textInputTypeDateTime, int textInputTypeDateTimeLocal, |
57 int textInputTypeMonth, int textInputTypeTime, | 57 int textInputTypeMonth, int textInputTypeTime, |
58 int textInputTypeWeek) { | 58 int textInputTypeWeek) { |
59 sTextInputTypeDate = textInputTypeDate; | 59 sTextInputTypeDate = textInputTypeDate; |
60 sTextInputTypeDateTime = textInputTypeDateTime; | 60 sTextInputTypeDateTime = textInputTypeDateTime; |
61 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal; | 61 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal; |
62 sTextInputTypeMonth = textInputTypeMonth; | 62 sTextInputTypeMonth = textInputTypeMonth; |
63 sTextInputTypeTime = textInputTypeTime; | 63 sTextInputTypeTime = textInputTypeTime; |
64 sTextInputTypeWeek = textInputTypeWeek; | 64 sTextInputTypeWeek = textInputTypeWeek; |
65 } | 65 } |
66 | 66 |
67 static boolean isDialogInputType(int type) { | 67 public static boolean isDialogInputType(int type) { |
68 return type == sTextInputTypeDate || type == sTextInputTypeTime | 68 return type == sTextInputTypeDate || type == sTextInputTypeTime |
69 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT
imeLocal | 69 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT
imeLocal |
70 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; | 70 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; |
71 } | 71 } |
72 | 72 |
73 InputDialogContainer(Context context, InputActionDelegate inputActionDelegat
e) { | 73 public InputDialogContainer(Context context, InputActionDelegate inputAction
Delegate) { |
74 mContext = context; | 74 mContext = context; |
75 mInputActionDelegate = inputActionDelegate; | 75 mInputActionDelegate = inputActionDelegate; |
76 } | 76 } |
77 | 77 |
78 void showPickerDialog(final int dialogType, double dialogValue, | 78 public void showPickerDialog(final int dialogType, double dialogValue, |
79 double min, double max, double step) { | 79 double min, double max, double step) { |
80 Calendar cal; | 80 Calendar cal; |
81 // |dialogValue|, |min|, |max| mean different things depending on the |d
ialogType|. | 81 // |dialogValue|, |min|, |max| mean different things depending on the |d
ialogType|. |
82 // For input type=month is the number of months since 1970. | 82 // For input type=month is the number of months since 1970. |
83 // For input type=time it is milliseconds since midnight. | 83 // For input type=time it is milliseconds since midnight. |
84 // For other types they are just milliseconds since 1970. | 84 // For other types they are just milliseconds since 1970. |
85 // If |dialogValue| is NaN it means an empty value. We will show the cur
rent time. | 85 // If |dialogValue| is NaN it means an empty value. We will show the cur
rent time. |
86 if (Double.isNaN(dialogValue)) { | 86 if (Double.isNaN(dialogValue)) { |
87 cal = Calendar.getInstance(); | 87 cal = Calendar.getInstance(); |
88 cal.set(Calendar.MILLISECOND, 0); | 88 cal.set(Calendar.MILLISECOND, 0); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (mDialog == dialog && !mDialogAlreadyDismissed) { | 186 if (mDialog == dialog && !mDialogAlreadyDismissed) { |
187 mDialogAlreadyDismissed = true; | 187 mDialogAlreadyDismissed = true; |
188 mInputActionDelegate.cancelDateTimeDialog(); | 188 mInputActionDelegate.cancelDateTimeDialog(); |
189 } | 189 } |
190 } | 190 } |
191 }); | 191 }); |
192 mDialogAlreadyDismissed = false; | 192 mDialogAlreadyDismissed = false; |
193 mDialog.show(); | 193 mDialog.show(); |
194 } | 194 } |
195 | 195 |
196 void showDialog(final int type, final double value, | 196 public void showDialog(final int type, final double value, |
197 double min, double max, double step, | 197 double min, double max, double step, |
198 DateTimeSuggestion[] suggestions) { | 198 DateTimeSuggestion[] suggestions) { |
199 // When the web page asks to show a dialog while there is one already op
en, | 199 // When the web page asks to show a dialog while there is one already op
en, |
200 // dismiss the old one. | 200 // dismiss the old one. |
201 dismissDialog(); | 201 dismissDialog(); |
202 if (suggestions == null) { | 202 if (suggestions == null) { |
203 showPickerDialog(type, value, min, max, step); | 203 showPickerDialog(type, value, min, max, step); |
204 } else { | 204 } else { |
205 showSuggestionDialog(type, value, min, max, step, suggestions); | 205 showSuggestionDialog(type, value, min, max, step, suggestions); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 void showPickerDialog(final int dialogType, | 209 protected void showPickerDialog(final int dialogType, |
210 int year, int month, int monthDay, | 210 int year, int month, int monthDay, |
211 int hourOfDay, int minute, int second, int millis, int week, | 211 int hourOfDay, int minute, int second, int millis, int week, |
212 double min, double max, double step) { | 212 double min, double max, double step) { |
213 if (isDialogShowing()) mDialog.dismiss(); | 213 if (isDialogShowing()) mDialog.dismiss(); |
214 | 214 |
215 int stepTime = (int) step; | 215 int stepTime = (int) step; |
216 | 216 |
217 if (dialogType == sTextInputTypeDate) { | 217 if (dialogType == sTextInputTypeDate) { |
218 ChromeDatePickerDialog dialog = new ChromeDatePickerDialog(mContext, | 218 ChromeDatePickerDialog dialog = new ChromeDatePickerDialog(mContext, |
219 new DateListener(dialogType), | 219 new DateListener(dialogType), |
(...skipping 22 matching lines...) Expand all Loading... |
242 } else if (dialogType == sTextInputTypeMonth) { | 242 } else if (dialogType == sTextInputTypeMonth) { |
243 mDialog = new MonthPickerDialog(mContext, new MonthOrWeekListener(di
alogType), | 243 mDialog = new MonthPickerDialog(mContext, new MonthOrWeekListener(di
alogType), |
244 year, month, min, max); | 244 year, month, min, max); |
245 } else if (dialogType == sTextInputTypeWeek) { | 245 } else if (dialogType == sTextInputTypeWeek) { |
246 mDialog = new WeekPickerDialog(mContext, new MonthOrWeekListener(dia
logType), | 246 mDialog = new WeekPickerDialog(mContext, new MonthOrWeekListener(dia
logType), |
247 year, week, min, max); | 247 year, week, min, max); |
248 } | 248 } |
249 | 249 |
250 mDialog.setButton(DialogInterface.BUTTON_POSITIVE, | 250 mDialog.setButton(DialogInterface.BUTTON_POSITIVE, |
251 mContext.getText(R.string.date_picker_dialog_set), | 251 mContext.getText(R.string.date_picker_dialog_set), |
252 (DialogInterface.OnClickListener) mDialog); | 252 (DialogInterface.OnClickListener)mDialog); |
253 | |
254 | 253 |
255 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, | 254 mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, |
256 mContext.getText(android.R.string.cancel), | 255 mContext.getText(android.R.string.cancel), |
257 (DialogInterface.OnClickListener) null); | 256 (DialogInterface.OnClickListener) null); |
258 | 257 |
259 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, | 258 mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, |
260 mContext.getText(R.string.date_picker_dialog_clear), | 259 mContext.getText(R.string.date_picker_dialog_clear), |
261 new DialogInterface.OnClickListener() { | 260 new DialogInterface.OnClickListener() { |
262 @Override | 261 @Override |
263 public void onClick(DialogInterface dialog, int which) { | 262 public void onClick(DialogInterface dialog, int which) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 cal.set(Calendar.MONTH, month); | 374 cal.set(Calendar.MONTH, month); |
376 cal.set(Calendar.DAY_OF_MONTH, monthDay); | 375 cal.set(Calendar.DAY_OF_MONTH, monthDay); |
377 cal.set(Calendar.HOUR_OF_DAY, hourOfDay); | 376 cal.set(Calendar.HOUR_OF_DAY, hourOfDay); |
378 cal.set(Calendar.MINUTE, minute); | 377 cal.set(Calendar.MINUTE, minute); |
379 cal.set(Calendar.SECOND, second); | 378 cal.set(Calendar.SECOND, second); |
380 cal.set(Calendar.MILLISECOND, millis); | 379 cal.set(Calendar.MILLISECOND, millis); |
381 mInputActionDelegate.replaceDateTime(cal.getTimeInMillis()); | 380 mInputActionDelegate.replaceDateTime(cal.getTimeInMillis()); |
382 } | 381 } |
383 } | 382 } |
384 } | 383 } |
OLD | NEW |