1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser.input;
7 import android.app.DatePickerDialog.OnDateSetListener;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.widget.DatePicker;
13 * The behavior of the DatePickerDialog changed after JellyBean so it now calls
14 * OndateSetListener.onDateSet() even when the dialog is dismissed (e.g. back button, tap
15 * outside). This class will call the listener instead of the DatePickerDialog only when the
16 * BUTTON_POSITIVE has been clicked.
18 class ChromeDatePickerDialog extends android.app.DatePickerDialog {
19 private final OnDateSetListener mCallBack;
21 public ChromeDatePickerDialog(Context context,
22 OnDateSetListener callBack,
26 super(context, 0, null, year, monthOfYear, dayOfMonth);
31 * The superclass DatePickerDialog has null for OnDateSetListener so we need to call the
35 public void onClick(DialogInterface dialog, int which) {
36 if (which == BUTTON_POSITIVE && mCallBack != null) {
37 DatePicker datePicker = getDatePicker();
38 datePicker.clearFocus();
39 mCallBack.onDateSet(datePicker, datePicker.getYear(),
40 datePicker.getMonth(), datePicker.getDayOfMonth());