DateTimeChooserAndroid.java revision 868fa2fe829687343ffae624259930155e16dbd8
1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use of this source code is governed by a BSD-style license that can be
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// found in the LICENSE file.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpackage org.chromium.content.browser.input;
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.chromium.base.CalledByNative;
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.chromium.base.JNINamespace;
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.chromium.content.browser.ContentViewCore;
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport android.content.Context;
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Plumbing for the different date/time dialog adapters.
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org@JNINamespace("content")
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass DateTimeChooserAndroid {
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    private final int mNativeDateTimeChooserAndroid;
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    private final InputDialogContainer mInputDialogContainer;
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    private DateTimeChooserAndroid(Context context,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            int nativeDateTimeChooserAndroid) {
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        mNativeDateTimeChooserAndroid = nativeDateTimeChooserAndroid;
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        mInputDialogContainer = new InputDialogContainer(context,
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                new InputDialogContainer.InputActionDelegate() {
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            @Override
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            public void replaceDateTime(
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                    int dialogType,
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                    int year, int month, int day, int hour, int minute, int second) {
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                nativeReplaceDateTime(mNativeDateTimeChooserAndroid,
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        dialogType,
34                        year, month, day, hour, minute, second);
35            }
36
37            @Override
38            public void cancelDateTimeDialog() {
39                nativeCancelDialog(mNativeDateTimeChooserAndroid);
40            }
41        });
42    }
43
44    private void showDialog(int dialogType, int year, int month, int monthDay,
45            int hour, int minute, int second, double min, double max) {
46        mInputDialogContainer.showDialog(dialogType, year, month, monthDay,
47                hour, minute, second, min, max);
48    }
49
50    @CalledByNative
51    private static DateTimeChooserAndroid createDateTimeChooser(
52            ContentViewCore contentViewCore,
53            int nativeDateTimeChooserAndroid, int dialogType,
54            int year, int month, int day, int hour, int minute,
55            int second, double min, double max) {
56        DateTimeChooserAndroid chooser =
57                new DateTimeChooserAndroid(
58                        contentViewCore.getContext(), nativeDateTimeChooserAndroid);
59        chooser.showDialog(dialogType, year, month, day, hour, minute, second, min, max);
60        return chooser;
61    }
62
63    @CalledByNative
64    private static void initializeDateInputTypes(int textInputTypeDate, int textInputTypeDateTime,
65            int textInputTypeDateTimeLocal, int textInputTypeMonth,
66            int textInputTypeTime) {
67        InputDialogContainer.initializeInputTypes(textInputTypeDate, textInputTypeDateTime,
68                textInputTypeDateTimeLocal, textInputTypeMonth, textInputTypeTime);
69    }
70
71    private native void nativeReplaceDateTime(int nativeDateTimeChooserAndroid,
72            int dialogType,
73            int year, int month, int day, int hour, int minute, int second);
74
75    private native void nativeCancelDialog(int nativeDateTimeChooserAndroid);
76}
77