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.AlertDialog; | |
Miguel Garcia
2013/10/08 17:44:40
double import
keishi
2013/10/21 17:00:58
Done.
| |
8 import android.app.DatePickerDialog; | 9 import android.app.DatePickerDialog; |
9 import android.app.TimePickerDialog; | 10 import android.app.TimePickerDialog; |
10 import android.app.DatePickerDialog.OnDateSetListener; | 11 import android.app.DatePickerDialog.OnDateSetListener; |
11 import android.app.TimePickerDialog.OnTimeSetListener; | 12 import android.app.TimePickerDialog.OnTimeSetListener; |
12 import android.content.Context; | 13 import android.content.Context; |
13 import android.content.DialogInterface; | 14 import android.content.DialogInterface; |
14 import android.content.DialogInterface.OnDismissListener; | 15 import android.content.DialogInterface.OnDismissListener; |
15 import android.text.TextUtils; | 16 import android.text.TextUtils; |
16 import android.text.format.DateFormat; | 17 import android.text.format.DateFormat; |
17 import android.text.format.Time; | 18 import android.text.format.Time; |
19 import android.view.LayoutInflater; | |
20 import android.view.View; | |
21 import android.widget.AdapterView; | |
18 import android.widget.DatePicker; | 22 import android.widget.DatePicker; |
23 import android.widget.ListView; | |
24 import android.widget.SimpleAdapter; | |
25 import android.widget.TextView; | |
19 import android.widget.TimePicker; | 26 import android.widget.TimePicker; |
20 | 27 |
21 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList ener; | 28 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList ener; |
22 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel dTimeSetListener; | 29 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel dTimeSetListener; |
23 import org.chromium.content.browser.input.TwoFieldDatePickerDialog; | 30 import org.chromium.content.browser.input.TwoFieldDatePickerDialog; |
24 import org.chromium.content.R; | 31 import org.chromium.content.R; |
25 | 32 |
33 import java.util.Arrays; | |
26 import java.text.ParseException; | 34 import java.text.ParseException; |
27 import java.text.SimpleDateFormat; | 35 import java.text.SimpleDateFormat; |
28 import java.util.Calendar; | 36 import java.util.Calendar; |
29 import java.util.Date; | 37 import java.util.Date; |
38 import java.util.List; | |
39 import java.util.Map; | |
40 import java.util.HashMap; | |
41 import java.util.ArrayList; | |
30 | 42 |
31 public class InputDialogContainer { | 43 public class InputDialogContainer { |
32 | 44 |
33 interface InputActionDelegate { | 45 interface InputActionDelegate { |
34 void cancelDateTimeDialog(); | 46 void cancelDateTimeDialog(); |
35 void replaceDateTime(int dialogType, | 47 void replaceDateTime(int dialogType, |
36 int year, int month, int day, int hour, int minute, int second, int milli, int week); | 48 int year, int month, int day, int hour, int minute, int second, int milli, int week); |
49 void acceptDataListSuggestion(String value); | |
37 } | 50 } |
38 | 51 |
39 // Default values used in Time representations of selected date/time before formatting. | 52 // Default values used in Time representations of selected date/time before formatting. |
40 // They are never displayed to the user. | 53 // They are never displayed to the user. |
41 private static final int YEAR_DEFAULT = 1970; | 54 private static final int YEAR_DEFAULT = 1970; |
42 private static final int MONTH_DEFAULT = 0; | 55 private static final int MONTH_DEFAULT = 0; |
43 private static final int MONTHDAY_DEFAULT = 1; | 56 private static final int MONTHDAY_DEFAULT = 1; |
44 private static final int HOUR_DEFAULT = 0; | 57 private static final int HOUR_DEFAULT = 0; |
45 private static final int MINUTE_DEFAULT = 0; | 58 private static final int MINUTE_DEFAULT = 0; |
46 private static final int WEEK_DEFAULT = 0; | 59 private static final int WEEK_DEFAULT = 0; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 Calendar cal = Calendar.getInstance(); | 114 Calendar cal = Calendar.getInstance(); |
102 result.set(cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), | 115 result.set(cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), |
103 cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DATE), | 116 cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DATE), |
104 cal.get(Calendar.MONTH), cal.get(Calendar.YEAR)); | 117 cal.get(Calendar.MONTH), cal.get(Calendar.YEAR)); |
105 } else { | 118 } else { |
106 result.set(second, minute, hour, monthDay, month, year); | 119 result.set(second, minute, hour, monthDay, month, year); |
107 } | 120 } |
108 return result; | 121 return result; |
109 } | 122 } |
110 | 123 |
124 void showSuggestionDialog(final int dialogType, | |
Miguel Garcia
2013/10/08 17:44:40
Add javadoc.
Can this be private?
I think this sh
| |
125 final int year, final int month, final int monthDay, | |
126 final int hour, final int minute, final int second, final int milli, final int week, | |
127 final double min, final double max, final double step, | |
128 DateTimeSuggestion[] suggestions) { | |
129 if (isDialogShowing()) mDialog.dismiss(); | |
130 | |
131 ListView suggestionListView = new ListView(mContext); | |
132 LayoutInflater inflater = | |
newt (away)
2013/10/09 07:20:52
unused variable
keishi
2013/10/21 17:00:58
Done.
| |
133 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_S ERVICE); | |
134 ArrayList<DateTimeSuggestion> suggestionList = | |
135 new ArrayList<DateTimeSuggestion>(Arrays.asList(suggestions)); | |
136 final DateTimeSuggestionListAdapter adapter = | |
137 new DateTimeSuggestionListAdapter(mContext, suggestionList); | |
Miguel Garcia
2013/10/08 17:44:40
nit: no need for the suggestionList temp variable,
keishi
2013/10/21 17:00:58
Done.
| |
138 suggestionListView.setAdapter(adapter); | |
139 suggestionListView.setOnItemClickListener(new AdapterView.OnItemClickLis tener() { | |
140 @Override | |
141 public void onItemClick(AdapterView<?> parent, View view, int positi on, long id) { | |
142 if (position == adapter.getCount() - 1) { | |
143 showPickerDialog(dialogType, year, month, monthDay, | |
144 hour, minute, second, milli, | |
145 week, min, max, step); | |
146 } else { | |
147 mInputActionDelegate.acceptDataListSuggestion(adapter.getIte m(position).mValue); | |
Miguel Garcia
2013/10/08 17:44:40
can you call replaceDateTime with the right values
keishi
2013/10/21 17:00:58
Done.
| |
148 mDialogAlreadyDismissed = true; | |
149 } | |
150 } | |
151 }); | |
152 | |
153 int dialogTitleId = R.string.date_picker_dialog_title; | |
Miguel Garcia
2013/10/08 17:44:40
How does this layout on a phone, it seems the desi
keishi
2013/10/21 17:00:58
I don't have a device with a small screen so here
| |
154 if (dialogType == sTextInputTypeTime) { | |
155 dialogTitleId = R.string.time_picker_dialog_title; | |
156 } else if (dialogType == sTextInputTypeDateTime || | |
157 dialogType == sTextInputTypeDateTimeLocal) { | |
158 dialogTitleId = R.string.date_time_picker_dialog_title; | |
159 } else if (dialogType == sTextInputTypeMonth) { | |
160 dialogTitleId = R.string.month_picker_dialog_title; | |
161 } else if (dialogType == sTextInputTypeWeek) { | |
162 dialogTitleId = R.string.week_picker_dialog_title; | |
163 } | |
164 | |
165 mDialog = new AlertDialog.Builder(mContext) | |
166 .setTitle(dialogTitleId) | |
167 .setView(suggestionListView) | |
168 .setOnDismissListener(new DialogInterface.OnDismissListener() { | |
169 @Override | |
170 public void onDismiss(DialogInterface dialog) { | |
171 if (mDialog == dialog && !mDialogAlreadyDismissed) { | |
172 mDialogAlreadyDismissed = true; | |
173 mInputActionDelegate.cancelDateTimeDialog(); | |
174 } | |
175 } | |
176 }) | |
177 .setNegativeButton(mContext.getText(android.R.string.cancel), | |
178 new DialogInterface.OnClickListener() { | |
179 @Override | |
180 public void onClick(DialogInterface dialog, int which) { | |
181 mDialogAlreadyDismissed = true; | |
newt (away)
2013/10/09 07:20:52
Can you replace lines 181-182 with "mDialog.dismis
keishi
2013/10/21 17:00:58
Done.
| |
182 mInputActionDelegate.cancelDateTimeDialog(); | |
183 } | |
184 }) | |
185 .create(); | |
186 | |
187 mDialogAlreadyDismissed = false; | |
188 mDialog.show(); | |
189 } | |
190 | |
111 void showDialog(final int dialogType, int year, int month, int monthDay, | 191 void showDialog(final int dialogType, int year, int month, int monthDay, |
112 int hour, int minute, int second, int milli, int week, | 192 int hour, int minute, int second, int milli, int week, |
113 double min, double max, double step) { | 193 double min, double max, double step, |
194 DateTimeSuggestion[] suggestions) { | |
195 if (suggestions == null) { | |
196 showPickerDialog(dialogType, year, month, monthDay, | |
197 hour, minute, second, milli, | |
198 week, min, max, step); | |
199 } else { | |
200 showSuggestionDialog(dialogType, year, month, monthDay, | |
201 hour, minute, second, milli, week, | |
202 min, max, step, suggestions); | |
203 } | |
204 } | |
205 | |
206 void showPickerDialog(final int dialogType, int year, int month, int monthDa y, | |
207 int hour, int minute, int second, int milli, int week, | |
208 double min, double max, double step) { | |
114 if (isDialogShowing()) mDialog.dismiss(); | 209 if (isDialogShowing()) mDialog.dismiss(); |
Miguel Garcia
2013/10/08 17:44:40
can you move this check to the showDialog call ins
keishi
2013/10/21 17:00:58
Done.
| |
115 | 210 |
116 // Java Date dialogs like longs but Blink prefers doubles.. | 211 // Java Date dialogs like longs but Blink prefers doubles.. |
117 // Both parameters mean different things depending on the type | 212 // Both parameters mean different things depending on the type |
118 // For input type=month min and max come as number on months since 1970 | 213 // 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 | 214 // 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. | 215 // In any case the cast here is safe given the above restrictions. |
121 long minTime = (long) min; | 216 long minTime = (long) min; |
122 long maxTime = (long) max; | 217 long maxTime = (long) max; |
123 int stepTime = (int) step; | 218 int stepTime = (int) step; |
124 | 219 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 int year, int month, int monthDay, int hourOfDay, | 406 int year, int month, int monthDay, int hourOfDay, |
312 int minute, int second, int milli, int week, String dateFormat) { | 407 int minute, int second, int milli, int week, String dateFormat) { |
313 // Prevents more than one callback being sent to the native | 408 // Prevents more than one callback being sent to the native |
314 // side when the dialog triggers multiple events. | 409 // side when the dialog triggers multiple events. |
315 mDialogAlreadyDismissed = true; | 410 mDialogAlreadyDismissed = true; |
316 | 411 |
317 mInputActionDelegate.replaceDateTime( | 412 mInputActionDelegate.replaceDateTime( |
318 dialogType, year, month, monthDay, hourOfDay, minute, second, milli, week); | 413 dialogType, year, month, monthDay, hourOfDay, minute, second, milli, week); |
319 } | 414 } |
320 } | 415 } |
OLD | NEW |