OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.content.Context; | 8 import android.content.Context; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.DialogInterface.OnClickListener; | 10 import android.content.DialogInterface.OnClickListener; |
(...skipping 11 matching lines...) Expand all Loading... |
22 protected final TwoFieldDatePicker mPicker; | 22 protected final TwoFieldDatePicker mPicker; |
23 protected final OnValueSetListener mCallBack; | 23 protected final OnValueSetListener mCallBack; |
24 | 24 |
25 /** | 25 /** |
26 * The callback used to indicate the user is done filling in the date. | 26 * The callback used to indicate the user is done filling in the date. |
27 */ | 27 */ |
28 public interface OnValueSetListener { | 28 public interface OnValueSetListener { |
29 | 29 |
30 /** | 30 /** |
31 * @param year The year that was set. | 31 * @param year The year that was set. |
32 * @param positionInYear The week in year. | 32 * @param positionInYear The position in the year that was set. |
33 * with {@link java.util.Calendar}. | |
34 */ | 33 */ |
35 void onValueSet(int year, int positionInYear); | 34 void onValueSet(int year, int positionInYear); |
36 } | 35 } |
37 | 36 |
38 /** | 37 /** |
39 * @param context The context the dialog is to run in. | 38 * @param context The context the dialog is to run in. |
40 * @param callBack How the parent is notified that the date is set. | 39 * @param callBack How the parent is notified that the date is set. |
41 * @param year The initial year of the dialog. | 40 * @param year The initial year of the dialog. |
42 * @param weekOfYear The initial week of the dialog. | 41 * @param weekOfYear The initial week of the dialog. |
43 */ | 42 */ |
44 public TwoFieldDatePickerDialog(Context context, | 43 public TwoFieldDatePickerDialog(Context context, |
45 OnValueSetListener callBack, | 44 OnValueSetListener callBack, |
46 int year, | 45 int year, |
47 int positionInYear, | 46 int positionInYear, |
48 long minValue, | 47 double minValue, |
49 long maxValue) { | 48 double maxValue) { |
50 this(context, 0, callBack, year, positionInYear, minValue, maxValue); | 49 this(context, 0, callBack, year, positionInYear, minValue, maxValue); |
51 } | 50 } |
52 | 51 |
53 /** | 52 /** |
54 * @param context The context the dialog is to run in. | 53 * @param context The context the dialog is to run in. |
55 * @param theme the theme to apply to this dialog | 54 * @param theme the theme to apply to this dialog |
56 * @param callBack How the parent is notified that the date is set. | 55 * @param callBack How the parent is notified that the date is set. |
57 * @param year The initial year of the dialog. | 56 * @param year The initial year of the dialog. |
58 * @param weekOfYear The initial week of the dialog. | 57 * @param weekOfYear The initial week of the dialog. |
59 */ | 58 */ |
60 public TwoFieldDatePickerDialog(Context context, | 59 public TwoFieldDatePickerDialog(Context context, |
61 int theme, | 60 int theme, |
62 OnValueSetListener callBack, | 61 OnValueSetListener callBack, |
63 int year, | 62 int year, |
64 int positionInYear, | 63 int positionInYear, |
65 long minValue, | 64 double minValue, |
66 long maxValue) { | 65 double maxValue) { |
67 super(context, theme); | 66 super(context, theme); |
68 | 67 |
69 mCallBack = callBack; | 68 mCallBack = callBack; |
70 | 69 |
71 setButton(BUTTON_POSITIVE, context.getText( | 70 setButton(BUTTON_POSITIVE, context.getText( |
72 R.string.date_picker_dialog_set), this); | 71 R.string.date_picker_dialog_set), this); |
73 setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel), | 72 setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel), |
74 (OnClickListener) null); | 73 (OnClickListener) null); |
75 setIcon(0); | 74 setIcon(0); |
76 | 75 |
77 mPicker = createPicker(context, minValue, maxValue); | 76 mPicker = createPicker(context, minValue, maxValue); |
78 setView(mPicker); | 77 setView(mPicker); |
79 mPicker.init(year, positionInYear, this); | 78 mPicker.init(year, positionInYear, this); |
80 } | 79 } |
81 | 80 |
82 protected TwoFieldDatePicker createPicker(Context context, long minValue, lo
ng maxValue) { | 81 protected TwoFieldDatePicker createPicker(Context context, double minValue,
double maxValue) { |
83 return null; | 82 return null; |
84 } | 83 } |
85 | 84 |
86 @Override | 85 @Override |
87 public void onClick(DialogInterface dialog, int which) { | 86 public void onClick(DialogInterface dialog, int which) { |
88 tryNotifyDateSet(); | 87 tryNotifyDateSet(); |
89 } | 88 } |
90 | 89 |
91 /** | 90 /** |
92 * Notifies the listener, if such, that a date has been set. | 91 * Notifies the listener, if such, that a date has been set. |
93 */ | 92 */ |
94 protected abstract void tryNotifyDateSet(); | 93 protected void tryNotifyDateSet() { |
| 94 if (mCallBack != null) { |
| 95 mPicker.clearFocus(); |
| 96 mCallBack.onValueSet(mPicker.getYear(), mPicker.getPositionInYear())
; |
| 97 } |
| 98 } |
95 | 99 |
96 @Override | 100 @Override |
97 protected void onStop() { | 101 protected void onStop() { |
98 if (Build.VERSION.SDK_INT >= 16) { | 102 if (Build.VERSION.SDK_INT >= 16) { |
99 // The default behavior of dialogs changed in JellyBean and onwards. | 103 // The default behavior of dialogs changed in JellyBean and onwards. |
100 // Dismissing a dialog (by pressing back for example) | 104 // Dismissing a dialog (by pressing back for example) |
101 // applies the chosen date. This code is added here so that the cust
om | 105 // applies the chosen date. This code is added here so that the cust
om |
102 // pickers behave the same as the internal DatePickerDialog. | 106 // pickers behave the same as the internal DatePickerDialog. |
103 tryNotifyDateSet(); | 107 tryNotifyDateSet(); |
104 } | 108 } |
105 super.onStop(); | 109 super.onStop(); |
106 } | 110 } |
107 | 111 |
108 @Override | 112 @Override |
109 public void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int posi
tionInYear) { | 113 public void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int posi
tionInYear) { |
110 mPicker.init(year, positionInYear, null); | 114 mPicker.init(year, positionInYear, null); |
111 } | 115 } |
112 | 116 |
113 /** | 117 /** |
114 * Sets the current date. | 118 * Sets the current date. |
115 * | 119 * |
116 * @param year The date week year. | 120 * @param year The date week year. |
117 * @param weekOfYear The date week. | 121 * @param weekOfYear The date week. |
118 */ | 122 */ |
119 public void updateDate(int year, int weekOfYear) { | 123 public void updateDate(int year, int weekOfYear) { |
120 mPicker.updateDate(year, weekOfYear); | 124 mPicker.updateDate(year, weekOfYear); |
121 } | 125 } |
122 } | 126 } |
OLD | NEW |