| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 protected final TwoFieldDatePicker mPicker; | 24 protected final TwoFieldDatePicker mPicker; |
| 25 protected final OnValueSetListener mCallBack; | 25 protected final OnValueSetListener mCallBack; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * The callback used to indicate the user is done filling in the date. | 28 * The callback used to indicate the user is done filling in the date. |
| 29 */ | 29 */ |
| 30 public interface OnValueSetListener { | 30 public interface OnValueSetListener { |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * @param year The year that was set. | 33 * @param value The value that was set. |
| 34 * @param positionInYear The week in year. | |
| 35 * with {@link java.util.Calendar}. | 34 * with {@link java.util.Calendar}. |
| 36 */ | 35 */ |
| 37 void onValueSet(int year, int positionInYear); | 36 void onValueSet(double value); |
| 38 } | 37 } |
| 39 | 38 |
| 40 /** | 39 /** |
| 41 * @param context The context the dialog is to run in. | 40 * @param context The context the dialog is to run in. |
| 42 * @param callBack How the parent is notified that the date is set. | 41 * @param callBack How the parent is notified that the date is set. |
| 43 * @param year The initial year of the dialog. | 42 * @param year The initial year of the dialog. |
| 44 * @param weekOfYear The initial week of the dialog. | 43 * @param weekOfYear The initial week of the dialog. |
| 45 */ | 44 */ |
| 46 public TwoFieldDatePickerDialog(Context context, | 45 public TwoFieldDatePickerDialog(Context context, |
| 47 OnValueSetListener callBack, | 46 OnValueSetListener callBack, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 85 } |
| 87 | 86 |
| 88 @Override | 87 @Override |
| 89 public void onClick(DialogInterface dialog, int which) { | 88 public void onClick(DialogInterface dialog, int which) { |
| 90 tryNotifyDateSet(); | 89 tryNotifyDateSet(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 /** | 92 /** |
| 94 * Notifies the listener, if such, that a date has been set. | 93 * Notifies the listener, if such, that a date has been set. |
| 95 */ | 94 */ |
| 96 protected abstract void tryNotifyDateSet(); | 95 protected void tryNotifyDateSet() { |
| 96 if (mCallBack != null) { |
| 97 mPicker.clearFocus(); |
| 98 mCallBack.onValueSet(mPicker.getValue()); |
| 99 } |
| 100 } |
| 97 | 101 |
| 98 @Override | 102 @Override |
| 99 protected void onStop() { | 103 protected void onStop() { |
| 100 if (Build.VERSION.SDK_INT >= 16) { | 104 if (Build.VERSION.SDK_INT >= 16) { |
| 101 // The default behavior of dialogs changed in JellyBean and onwards. | 105 // The default behavior of dialogs changed in JellyBean and onwards. |
| 102 // Dismissing a dialog (by pressing back for example) | 106 // Dismissing a dialog (by pressing back for example) |
| 103 // applies the chosen date. This code is added here so that the cust
om | 107 // applies the chosen date. This code is added here so that the cust
om |
| 104 // pickers behave the same as the internal DatePickerDialog. | 108 // pickers behave the same as the internal DatePickerDialog. |
| 105 tryNotifyDateSet(); | 109 tryNotifyDateSet(); |
| 106 } | 110 } |
| 107 super.onStop(); | 111 super.onStop(); |
| 108 } | 112 } |
| 109 | 113 |
| 110 @Override | 114 @Override |
| 111 public void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int posi
tionInYear) { | 115 public void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int posi
tionInYear) { |
| 112 mPicker.init(year, positionInYear, null); | 116 mPicker.init(year, positionInYear, null); |
| 113 } | 117 } |
| 114 | 118 |
| 115 /** | 119 /** |
| 116 * Sets the current date. | 120 * Sets the current date. |
| 117 * | 121 * |
| 118 * @param year The date week year. | 122 * @param year The date week year. |
| 119 * @param weekOfYear The date week. | 123 * @param weekOfYear The date week. |
| 120 */ | 124 */ |
| 121 public void updateDate(int year, int weekOfYear) { | 125 public void updateDate(int year, int weekOfYear) { |
| 122 mPicker.updateDate(year, weekOfYear); | 126 mPicker.updateDate(year, weekOfYear); |
| 123 } | 127 } |
| 124 } | 128 } |
| OLD | NEW |