Commit be3bf145 authored by keishi@chromium.org's avatar keishi@chromium.org

Dismissing of date/time dialogs should not set the value

Tapping the back button, cancel button, or outside the dialog should not set the value.
DatePickerDialog has a bug since JellyBean where the onDateSet callback is called every time the dialog is dismissed.

BUG=325841

Review URL: https://codereview.chromium.org/260903006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269507 0039d316-1c4b-4281-b951-d872f2087c98
parent f82a2aed
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser.input;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.DatePicker;
/**
* The behavior of the DatePickerDialog changed after JellyBean so it now calls
* OndateSetListener.onDateSet() even when the dialog is dismissed (e.g. back button, tap
* outside). This class will call the listener instead of the DatePickerDialog only when the
* BUTTON_POSITIVE has been clicked.
*/
class ChromeDatePickerDialog extends android.app.DatePickerDialog {
private final OnDateSetListener mCallBack;
public ChromeDatePickerDialog(Context context,
OnDateSetListener callBack,
int year,
int monthOfYear,
int dayOfMonth) {
super(context, 0, null, year, monthOfYear, dayOfMonth);
mCallBack = callBack;
}
/**
* The superclass DatePickerDialog has null for OnDateSetListener so we need to call the
* listener manually.
*/
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == BUTTON_POSITIVE && mCallBack != null) {
DatePicker datePicker = getDatePicker();
datePicker.clearFocus();
mCallBack.onDateSet(datePicker, datePicker.getYear(),
datePicker.getMonth(), datePicker.getDayOfMonth());
}
}
}
......@@ -8,7 +8,6 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
......@@ -106,18 +105,6 @@ class DateTimePickerDialog extends AlertDialog implements OnClickListener,
}
}
@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.
tryNotifyDateTimeSet();
}
super.onStop();
}
@Override
public void onDateChanged(DatePicker view, int year,
int month, int day) {
......
......@@ -5,7 +5,6 @@
package org.chromium.content.browser.input;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Context;
import android.content.DialogInterface;
......@@ -216,7 +215,7 @@ public class InputDialogContainer {
int stepTime = (int) step;
if (dialogType == sTextInputTypeDate) {
DatePickerDialog dialog = new DatePickerDialog(mContext,
ChromeDatePickerDialog dialog = new ChromeDatePickerDialog(mContext,
new DateListener(dialogType),
year, month, monthDay);
DateDialogNormalizer.normalize(dialog.getDatePicker(), dialog,
......
......@@ -8,7 +8,6 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.NumberPicker;
......@@ -261,18 +260,6 @@ public class MultiFieldTimePickerDialog
mListener.onTimeSet(hour, minute, sec, milli);
}
@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.
notifyDateSet();
}
super.onStop();
}
private static class NumberFormatter implements NumberPicker.Formatter {
private final String mFormat;
......
......@@ -8,7 +8,6 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import org.chromium.content.R;
import org.chromium.content.browser.input.TwoFieldDatePicker.OnMonthOrWeekChangedListener;
......@@ -97,18 +96,6 @@ public abstract class TwoFieldDatePickerDialog extends AlertDialog implements On
}
}
@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.
tryNotifyDateSet();
}
super.onStop();
}
@Override
public void onMonthOrWeekChanged(TwoFieldDatePicker view, int year, int positionInYear) {
mPicker.init(year, positionInYear, null);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment