Index: content/public/android/java/src/org/chromium/content/browser/input/MonthPickerDialog.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/MonthPickerDialog.java b/content/public/android/java/src/org/chromium/content/browser/input/MonthPickerDialog.java |
index 354810e5e429662ca400284a90d5dcc54cf3a054..5ab78ae6a0c0b08827587874734622df39011439 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/input/MonthPickerDialog.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/input/MonthPickerDialog.java |
@@ -4,39 +4,9 @@ |
package org.chromium.content.browser.input; |
-import android.app.AlertDialog; |
import android.content.Context; |
-import android.content.DialogInterface; |
-import android.content.DialogInterface.OnClickListener; |
-import android.os.Build; |
-import android.os.Bundle; |
-import android.view.View; |
-import org.chromium.content.browser.input.MonthPicker.OnMonthChangedListener; |
-import org.chromium.content.R; |
- |
-public class MonthPickerDialog extends AlertDialog implements OnClickListener, |
- OnMonthChangedListener { |
- |
- private static final String YEAR = "year"; |
- private static final String MONTH = "month"; |
- |
- private final MonthPicker mMonthPicker; |
- private final OnMonthSetListener mCallBack; |
- |
- /** |
- * The callback used to indicate the user is done filling in the date. |
- */ |
- public interface OnMonthSetListener { |
- |
- /** |
- * @param view The view associated with this listener. |
- * @param year The year that was set. |
- * @param monthOfYear The month that was set (0-11) for compatibility |
- * with {@link java.util.Calendar}. |
- */ |
- void onMonthSet(MonthPicker view, int year, int monthOfYear); |
- } |
+public class MonthPickerDialog extends BaseDatePickerDialog { |
/** |
* @param context The context the dialog is to run in. |
@@ -45,7 +15,7 @@ public class MonthPickerDialog extends AlertDialog implements OnClickListener, |
* @param monthOfYear The initial month of the dialog. |
*/ |
public MonthPickerDialog(Context context, |
- OnMonthSetListener callBack, |
+ OnMonthOrWeekSetListener callBack, |
int year, |
int monthOfYear) { |
this(context, 0, callBack, year, monthOfYear); |
@@ -60,53 +30,29 @@ public class MonthPickerDialog extends AlertDialog implements OnClickListener, |
*/ |
public MonthPickerDialog(Context context, |
int theme, |
- OnMonthSetListener callBack, |
+ OnMonthOrWeekSetListener callBack, |
int year, |
int monthOfYear) { |
- super(context, theme); |
- |
- mCallBack = callBack; |
- |
- setButton(BUTTON_POSITIVE, context.getText( |
- R.string.date_picker_dialog_set), this); |
- setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel), |
- (OnClickListener) null); |
- setIcon(0); |
- setTitle(R.string.month_picker_dialog_title); |
- |
- mMonthPicker = new MonthPicker(context); |
- setView(mMonthPicker); |
- mMonthPicker.init(year, monthOfYear, this); |
+ super(context, theme, callBack, year, monthOfYear); |
} |
@Override |
- public void onClick(DialogInterface dialog, int which) { |
- tryNotifyMonthSet(); |
- } |
- |
- private void tryNotifyMonthSet() { |
- if (mCallBack != null) { |
- mMonthPicker.clearFocus(); |
- mCallBack.onMonthSet(mMonthPicker, mMonthPicker.getYear(), |
- mMonthPicker.getMonth()); |
- } |
+ protected BaseDatePicker createPicker(Context context) { |
+ return new MonthPicker(context); |
} |
@Override |
- protected void onStop() { |
- if (Build.VERSION.SDK_INT >= 16) { |
- // The default behavior of dialogs changed in JellyBean and onwards. |
- // Dismissing a dialog (by pressing back for example) |
- // applies the chosen date. This code is added here so that the custom |
- // pickers behave the same as the internal DatePickerDialog. |
- tryNotifyMonthSet(); |
+ protected void tryNotifyDateSet() { |
+ if (mCallBack != null) { |
+ MonthPicker picker = getMonthPicker(); |
+ picker.clearFocus(); |
+ mCallBack.onMonthSet(picker, picker.getYear(), picker.getMonth()); |
} |
- super.onStop(); |
} |
@Override |
public void onMonthChanged(MonthPicker view, int year, int month) { |
- mMonthPicker.init(year, month, null); |
+ mPicker.init(year, month, null); |
} |
/** |
@@ -115,32 +61,6 @@ public class MonthPickerDialog extends AlertDialog implements OnClickListener, |
* @return The calendar view. |
*/ |
public MonthPicker getMonthPicker() { |
- return mMonthPicker; |
- } |
- |
- /** |
- * Sets the current date. |
- * |
- * @param year The date year. |
- * @param monthOfYear The date month. |
- */ |
- public void updateDate(int year, int monthOfYear) { |
- mMonthPicker.updateMonth(year, monthOfYear); |
- } |
- |
- @Override |
- public Bundle onSaveInstanceState() { |
- Bundle state = super.onSaveInstanceState(); |
- state.putInt(YEAR, mMonthPicker.getYear()); |
- state.putInt(MONTH, mMonthPicker.getMonth()); |
- return state; |
- } |
- |
- @Override |
- public void onRestoreInstanceState(Bundle savedInstanceState) { |
- super.onRestoreInstanceState(savedInstanceState); |
- int year = savedInstanceState.getInt(YEAR); |
- int month = savedInstanceState.getInt(MONTH); |
- mMonthPicker.init(year, month, this); |
+ return (MonthPicker) mPicker; |
} |
} |