e759e8550aaa9bd25a0b5b480fdadde430717661
[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.app.DatePickerDialog.OnDateSetListener;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.widget.DatePicker;
11
12 /**
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.
17  */
18 class ChromeDatePickerDialog extends android.app.DatePickerDialog {
19     private final OnDateSetListener mCallBack;
20
21     public ChromeDatePickerDialog(Context context,
22             OnDateSetListener callBack,
23             int year,
24             int monthOfYear,
25             int dayOfMonth) {
26         super(context, 0, null, year, monthOfYear, dayOfMonth);
27         mCallBack = callBack;
28     }
29
30     /**
31      * The superclass DatePickerDialog has null for OnDateSetListener so we need to call the
32      * listener manually.
33      */
34     @Override
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());
41         }
42     }
43 }