1 | // Copyright (c) 2013 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 org.chromium.base.CalledByNative; |
8 | import org.chromium.base.JNINamespace; |
9 | import org.chromium.content.browser.ContentViewCore; |
10 | |
11 | import android.content.Context; |
12 | |
13 | /** |
14 | * Plumbing for the different date/time dialog adapters. |
15 | */ |
16 | @JNINamespace("content") |
17 | class DateTimeChooserAndroid { |
18 | |
19 | private final int mNativeDateTimeChooserAndroid; |
20 | private final InputDialogContainer mInputDialogContainer; |
21 | |
22 | private DateTimeChooserAndroid(Context context, |
23 | int nativeDateTimeChooserAndroid) { |
24 | mNativeDateTimeChooserAndroid = nativeDateTimeChooserAndroid; |
25 | mInputDialogContainer = new InputDialogContainer(context, |
26 | new InputDialogContainer.InputActionDelegate() { |
27 | |
28 | @Override |
29 | public void replaceDateTime( |
30 | int dialogType, |
31 | int year, int month, int day, int hour, int minute, |
32 | int second, int milli, int week) { |
33 | nativeReplaceDateTime(mNativeDateTimeChooserAndroid, |
34 | dialogType, |
35 | year, month, day, hour, minute, second, milli, week); |
36 | } |
37 | |
38 | @Override |
39 | public void cancelDateTimeDialog() { |
40 | nativeCancelDialog(mNativeDateTimeChooserAndroid); |
41 | } |
42 | }); |
43 | } |
44 | |
45 | private void showDialog(int dialogType, int year, int month, int monthDay, |
46 | int hour, int minute, int second, int milli, |
47 | int week, double min, double max, double step) { |
48 | mInputDialogContainer.showDialog( |
49 | dialogType, year, month, monthDay, |
50 | hour, minute, second, milli, week, min, max, step); |
51 | } |
52 | |
53 | @CalledByNative |
54 | private static DateTimeChooserAndroid createDateTimeChooser( |
55 | ContentViewCore contentViewCore, |
56 | int nativeDateTimeChooserAndroid, int dialogType, |
57 | int year, int month, int day, |
58 | int hour, int minute, int second, int milli, int week, |
59 | double min, double max, double step) { |
60 | DateTimeChooserAndroid chooser = |
61 | new DateTimeChooserAndroid( |
62 | contentViewCore.getContext(), |
63 | nativeDateTimeChooserAndroid); |
64 | chooser.showDialog( |
65 | dialogType, year, month, day, hour, minute, second, milli, |
66 | week, min, max, step); |
67 | return chooser; |
68 | } |
69 | |
70 | @CalledByNative |
71 | private static void initializeDateInputTypes( |
72 | int textInputTypeDate, int textInputTypeDateTime, |
73 | int textInputTypeDateTimeLocal, int textInputTypeMonth, |
74 | int textInputTypeTime, int textInputTypeWeek) { |
75 | InputDialogContainer.initializeInputTypes(textInputTypeDate, |
76 | textInputTypeDateTime, textInputTypeDateTimeLocal, |
77 | textInputTypeMonth, textInputTypeTime, textInputTypeWeek); |
78 | } |
79 | |
80 | private native void nativeReplaceDateTime( |
81 | int nativeDateTimeChooserAndroid, int dialogType, |
82 | int year, int month, int day, int hour, int minute, |
83 | int second, int milli, int week); |
84 | |
85 | private native void nativeCancelDialog(int nativeDateTimeChooserAndroid); |
86 | } |