Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / public / android / java / src / org / chromium / content / browser / input / DateTimeChooserAndroid.java
1 // Copyright 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 android.content.Context;
8
9 import org.chromium.base.CalledByNative;
10 import org.chromium.base.JNINamespace;
11 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.ui.picker.DateTimeSuggestion;
13 import org.chromium.ui.picker.InputDialogContainer;
14
15 /**
16  * Plumbing for the different date/time dialog adapters.
17  */
18 @JNINamespace("content")
19 class DateTimeChooserAndroid {
20
21     private final long mNativeDateTimeChooserAndroid;
22     private final InputDialogContainer mInputDialogContainer;
23
24     private DateTimeChooserAndroid(Context context,
25             long nativeDateTimeChooserAndroid) {
26         mNativeDateTimeChooserAndroid = nativeDateTimeChooserAndroid;
27         mInputDialogContainer = new InputDialogContainer(context,
28                 new InputDialogContainer.InputActionDelegate() {
29
30                     @Override
31                     public void replaceDateTime(double value) {
32                         nativeReplaceDateTime(mNativeDateTimeChooserAndroid, value);
33                     }
34
35                     @Override
36                     public void cancelDateTimeDialog() {
37                         nativeCancelDialog(mNativeDateTimeChooserAndroid);
38                     }
39                 });
40     }
41
42     private void showDialog(int dialogType, double dialogValue,
43                             double min, double max, double step,
44                             DateTimeSuggestion[] suggestions) {
45         mInputDialogContainer.showDialog(dialogType, dialogValue, min, max, step, suggestions);
46     }
47
48     @CalledByNative
49     private static DateTimeChooserAndroid createDateTimeChooser(
50             ContentViewCore contentViewCore,
51             long nativeDateTimeChooserAndroid,
52             int dialogType, double dialogValue,
53             double min, double max, double step,
54             DateTimeSuggestion[] suggestions) {
55         DateTimeChooserAndroid chooser =
56                 new DateTimeChooserAndroid(
57                         contentViewCore.getContext(),
58                         nativeDateTimeChooserAndroid);
59         chooser.showDialog(dialogType, dialogValue, min, max, step, suggestions);
60         return chooser;
61     }
62
63     @CalledByNative
64     private static DateTimeSuggestion[] createSuggestionsArray(int size) {
65         return new DateTimeSuggestion[size];
66     }
67
68     /**
69      * @param array DateTimeSuggestion array that should get a new suggestion set.
70      * @param index Index in the array where to place a new suggestion.
71      * @param value Value of the suggestion.
72      * @param localizedValue Localized value of the suggestion.
73      * @param label Label of the suggestion.
74      */
75     @CalledByNative
76     private static void setDateTimeSuggestionAt(DateTimeSuggestion[] array, int index,
77             double value, String localizedValue, String label) {
78         array[index] = new DateTimeSuggestion(value, localizedValue, label);
79     }
80
81     @CalledByNative
82     private static void initializeDateInputTypes(
83             int textInputTypeDate, int textInputTypeDateTime,
84             int textInputTypeDateTimeLocal, int textInputTypeMonth,
85             int textInputTypeTime, int textInputTypeWeek) {
86         InputDialogContainer.initializeInputTypes(
87                 textInputTypeDate,
88                 textInputTypeDateTime, textInputTypeDateTimeLocal,
89                 textInputTypeMonth, textInputTypeTime, textInputTypeWeek);
90     }
91
92     private native void nativeReplaceDateTime(long nativeDateTimeChooserAndroid,
93                                               double dialogValue);
94
95     private native void nativeCancelDialog(long nativeDateTimeChooserAndroid);
96 }