Chromium Code Reviews| 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; |
| 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.base.ApiCompatibilityUtils; | 19 import org.chromium.base.ApiCompatibilityUtils; |
| 20 import org.chromium.content.R; | 20 import org.chromium.ui.DateTimePickerDialog.OnDateTimeSetListener; |
| 21 import org.chromium.content.browser.input.DateTimePickerDialog.OnDateTimeSetList ener; | 21 import org.chromium.ui.MultiFieldTimePickerDialog.OnMultiFieldTimeSetListener; |
| 22 import org.chromium.content.browser.input.MultiFieldTimePickerDialog.OnMultiFiel dTimeSetListener; | |
| 23 | 22 |
| 24 import java.util.Arrays; | 23 import java.util.Arrays; |
| 25 import java.util.Calendar; | 24 import java.util.Calendar; |
| 26 import java.util.Date; | 25 import java.util.Date; |
| 27 import java.util.GregorianCalendar; | 26 import java.util.GregorianCalendar; |
| 28 import java.util.TimeZone; | 27 import java.util.TimeZone; |
| 29 import java.util.concurrent.TimeUnit; | 28 import java.util.concurrent.TimeUnit; |
| 30 | 29 |
| 31 /** | 30 /** |
| 32 * 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. |
| 33 */ | 32 */ |
| 34 public class InputDialogContainer { | 33 public class InputDialogContainer { |
| 35 | 34 |
| 36 interface InputActionDelegate { | 35 public interface InputActionDelegate { |
|
ankit
2014/09/18 13:05:19
DateTimeChooserAndroid.java is implementing this i
| |
| 37 void cancelDateTimeDialog(); | 36 void cancelDateTimeDialog(); |
| 38 void replaceDateTime(double value); | 37 void replaceDateTime(double value); |
| 39 } | 38 } |
| 40 | 39 |
| 41 private static int sTextInputTypeDate; | 40 private static int sTextInputTypeDate; |
| 42 private static int sTextInputTypeDateTime; | 41 private static int sTextInputTypeDateTime; |
| 43 private static int sTextInputTypeDateTimeLocal; | 42 private static int sTextInputTypeDateTimeLocal; |
| 44 private static int sTextInputTypeMonth; | 43 private static int sTextInputTypeMonth; |
| 45 private static int sTextInputTypeTime; | 44 private static int sTextInputTypeTime; |
| 46 private static int sTextInputTypeWeek; | 45 private static int sTextInputTypeWeek; |
| 47 | 46 |
| 48 private final Context mContext; | 47 private final Context mContext; |
| 49 | 48 |
| 50 // Prevents sending two notifications (from onClick and from onDismiss) | 49 // Prevents sending two notifications (from onClick and from onDismiss) |
| 51 private boolean mDialogAlreadyDismissed; | 50 private boolean mDialogAlreadyDismissed; |
| 52 | 51 |
| 53 private AlertDialog mDialog; | 52 private AlertDialog mDialog; |
| 54 private final InputActionDelegate mInputActionDelegate; | 53 private final InputActionDelegate mInputActionDelegate; |
| 55 | 54 |
| 56 static void initializeInputTypes(int textInputTypeDate, | 55 public static void initializeInputTypes(int textInputTypeDate, |
|
ankit
2014/09/18 13:05:19
DateTimeChooserAndroid.java is using this method.
| |
| 57 int textInputTypeDateTime, int textInputTypeDateTimeLocal, | 56 int textInputTypeDateTime, int textInputTypeDateTimeLocal, |
| 58 int textInputTypeMonth, int textInputTypeTime, | 57 int textInputTypeMonth, int textInputTypeTime, |
| 59 int textInputTypeWeek) { | 58 int textInputTypeWeek) { |
| 60 sTextInputTypeDate = textInputTypeDate; | 59 sTextInputTypeDate = textInputTypeDate; |
| 61 sTextInputTypeDateTime = textInputTypeDateTime; | 60 sTextInputTypeDateTime = textInputTypeDateTime; |
| 62 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal; | 61 sTextInputTypeDateTimeLocal = textInputTypeDateTimeLocal; |
| 63 sTextInputTypeMonth = textInputTypeMonth; | 62 sTextInputTypeMonth = textInputTypeMonth; |
| 64 sTextInputTypeTime = textInputTypeTime; | 63 sTextInputTypeTime = textInputTypeTime; |
| 65 sTextInputTypeWeek = textInputTypeWeek; | 64 sTextInputTypeWeek = textInputTypeWeek; |
| 66 } | 65 } |
| 67 | 66 |
| 68 static boolean isDialogInputType(int type) { | 67 public static boolean isDialogInputType(int type) { |
|
ankit
2014/09/18 13:05:19
ImeAdapter is using this method.
| |
| 69 return type == sTextInputTypeDate || type == sTextInputTypeTime | 68 return type == sTextInputTypeDate || type == sTextInputTypeTime |
| 70 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT imeLocal | 69 || type == sTextInputTypeDateTime || type == sTextInputTypeDateT imeLocal |
| 71 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; | 70 || type == sTextInputTypeMonth || type == sTextInputTypeWeek; |
| 72 } | 71 } |
| 73 | 72 |
| 74 InputDialogContainer(Context context, InputActionDelegate inputActionDelegat e) { | 73 public InputDialogContainer(Context context, InputActionDelegate inputAction Delegate) { |
|
ankit
2014/09/18 13:05:19
InputDialogContainerForTests is extending this cla
| |
| 75 mContext = context; | 74 mContext = context; |
| 76 mInputActionDelegate = inputActionDelegate; | 75 mInputActionDelegate = inputActionDelegate; |
| 77 } | 76 } |
| 78 | 77 |
| 79 void showPickerDialog(final int dialogType, double dialogValue, | 78 public void showPickerDialog(final int dialogType, double dialogValue, |
|
ankit
2014/09/18 13:05:19
Overridden by InputDialogContainerTest.java
| |
| 80 double min, double max, double step) { | 79 double min, double max, double step) { |
| 81 Calendar cal; | 80 Calendar cal; |
| 82 // |dialogValue|, |min|, |max| mean different things depending on the |d ialogType|. | 81 // |dialogValue|, |min|, |max| mean different things depending on the |d ialogType|. |
| 83 // For input type=month is the number of months since 1970. | 82 // For input type=month is the number of months since 1970. |
| 84 // For input type=time it is milliseconds since midnight. | 83 // For input type=time it is milliseconds since midnight. |
| 85 // For other types they are just milliseconds since 1970. | 84 // For other types they are just milliseconds since 1970. |
| 86 // 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. |
| 87 if (Double.isNaN(dialogValue)) { | 86 if (Double.isNaN(dialogValue)) { |
| 88 cal = Calendar.getInstance(); | 87 cal = Calendar.getInstance(); |
| 89 cal.set(Calendar.MILLISECOND, 0); | 88 cal.set(Calendar.MILLISECOND, 0); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (mDialog == dialog && !mDialogAlreadyDismissed) { | 186 if (mDialog == dialog && !mDialogAlreadyDismissed) { |
| 188 mDialogAlreadyDismissed = true; | 187 mDialogAlreadyDismissed = true; |
| 189 mInputActionDelegate.cancelDateTimeDialog(); | 188 mInputActionDelegate.cancelDateTimeDialog(); |
| 190 } | 189 } |
| 191 } | 190 } |
| 192 }); | 191 }); |
| 193 mDialogAlreadyDismissed = false; | 192 mDialogAlreadyDismissed = false; |
| 194 mDialog.show(); | 193 mDialog.show(); |
| 195 } | 194 } |
| 196 | 195 |
| 197 void showDialog(final int type, final double value, | 196 public void showDialog(final int type, final double value, |
|
ankit
2014/09/18 13:05:19
DateTimeChooserAndroid.java is using this method.
| |
| 198 double min, double max, double step, | 197 double min, double max, double step, |
| 199 DateTimeSuggestion[] suggestions) { | 198 DateTimeSuggestion[] suggestions) { |
| 200 // 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, |
| 201 // dismiss the old one. | 200 // dismiss the old one. |
| 202 dismissDialog(); | 201 dismissDialog(); |
| 203 if (suggestions == null) { | 202 if (suggestions == null) { |
| 204 showPickerDialog(type, value, min, max, step); | 203 showPickerDialog(type, value, min, max, step); |
| 205 } else { | 204 } else { |
| 206 showSuggestionDialog(type, value, min, max, step, suggestions); | 205 showSuggestionDialog(type, value, min, max, step, suggestions); |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 void showPickerDialog(final int dialogType, | 209 protected void showPickerDialog(final int dialogType, |
|
aurimas (slooooooooow)
2014/09/17 15:58:38
What is the reason for all the visibility (public/
ankit
2014/09/18 13:05:19
This funtions is overridden by InputDialogCotainer
| |
| 211 int year, int month, int monthDay, | 210 int year, int month, int monthDay, |
| 212 int hourOfDay, int minute, int second, int millis, int week, | 211 int hourOfDay, int minute, int second, int millis, int week, |
| 213 double min, double max, double step) { | 212 double min, double max, double step) { |
| 214 if (isDialogShowing()) mDialog.dismiss(); | 213 if (isDialogShowing()) mDialog.dismiss(); |
| 215 | 214 |
| 216 int stepTime = (int) step; | 215 int stepTime = (int) step; |
| 217 | 216 |
| 218 if (dialogType == sTextInputTypeDate) { | 217 if (dialogType == sTextInputTypeDate) { |
| 219 ChromeDatePickerDialog dialog = new ChromeDatePickerDialog(mContext, | 218 ChromeDatePickerDialog dialog = new ChromeDatePickerDialog(mContext, |
| 220 new DateListener(dialogType), | 219 new DateListener(dialogType), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 cal.set(Calendar.MONTH, month); | 375 cal.set(Calendar.MONTH, month); |
| 377 cal.set(Calendar.DAY_OF_MONTH, monthDay); | 376 cal.set(Calendar.DAY_OF_MONTH, monthDay); |
| 378 cal.set(Calendar.HOUR_OF_DAY, hourOfDay); | 377 cal.set(Calendar.HOUR_OF_DAY, hourOfDay); |
| 379 cal.set(Calendar.MINUTE, minute); | 378 cal.set(Calendar.MINUTE, minute); |
| 380 cal.set(Calendar.SECOND, second); | 379 cal.set(Calendar.SECOND, second); |
| 381 cal.set(Calendar.MILLISECOND, millis); | 380 cal.set(Calendar.MILLISECOND, millis); |
| 382 mInputActionDelegate.replaceDateTime(cal.getTimeInMillis()); | 381 mInputActionDelegate.replaceDateTime(cal.getTimeInMillis()); |
| 383 } | 382 } |
| 384 } | 383 } |
| 385 } | 384 } |
| OLD | NEW |