Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / content / public / android / java / src / org / chromium / content / browser / input / ChromeDatePickerDialog.java
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.
4
5 package org.chromium.content.browser.input;
6
7 import android.content.Context;
8 import android.content.DialogInterface;
9 import android.widget.DatePicker;
10
11 /**
12  * The behavior of the DatePickerDialog changed after JellyBean so it now calls
13  * OndateSetListener.onDateSet() even when the dialog is dismissed (e.g. back button, tap
14  * outside). This class will call the listener instead of the DatePickerDialog only when the
15  * BUTTON_POSITIVE has been clicked.
16  */
17 class ChromeDatePickerDialog extends android.app.DatePickerDialog {
18     private final OnDateSetListener mCallBack;
19
20     public ChromeDatePickerDialog(Context context,
21             OnDateSetListener callBack,
22             int year,
23             int monthOfYear,
24             int dayOfMonth) {
25         super(context, 0, callBack, year, monthOfYear, dayOfMonth);
26         mCallBack = callBack;
27     }
28
29     /**
30      * The superclass DatePickerDialog has null for OnDateSetListener so we need to call the
31      * listener manually.
32      */
33     @Override
34     public void onClick(DialogInterface dialog, int which) {
35         if (which == BUTTON_POSITIVE && mCallBack != null) {
36             DatePicker datePicker = getDatePicker();
37             datePicker.clearFocus();
38             mCallBack.onDateSet(datePicker, datePicker.getYear(),
39                     datePicker.getMonth(), datePicker.getDayOfMonth());
40         }
41     }
42 }