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.
5 package org.chromium.content.browser.input;
7 import android.content.Context;
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;
16 * Plumbing for the different date/time dialog adapters.
18 @JNINamespace("content")
19 class DateTimeChooserAndroid {
21 private final long mNativeDateTimeChooserAndroid;
22 private final InputDialogContainer mInputDialogContainer;
24 private DateTimeChooserAndroid(Context context,
25 long nativeDateTimeChooserAndroid) {
26 mNativeDateTimeChooserAndroid = nativeDateTimeChooserAndroid;
27 mInputDialogContainer = new InputDialogContainer(context,
28 new InputDialogContainer.InputActionDelegate() {
31 public void replaceDateTime(double value) {
32 nativeReplaceDateTime(mNativeDateTimeChooserAndroid, value);
36 public void cancelDateTimeDialog() {
37 nativeCancelDialog(mNativeDateTimeChooserAndroid);
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);
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);
64 private static DateTimeSuggestion[] createSuggestionsArray(int size) {
65 return new DateTimeSuggestion[size];
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.
76 private static void setDateTimeSuggestionAt(DateTimeSuggestion[] array, int index,
77 double value, String localizedValue, String label) {
78 array[index] = new DateTimeSuggestion(value, localizedValue, label);
82 private static void initializeDateInputTypes(
83 int textInputTypeDate, int textInputTypeDateTime,
84 int textInputTypeDateTimeLocal, int textInputTypeMonth,
85 int textInputTypeTime, int textInputTypeWeek) {
86 InputDialogContainer.initializeInputTypes(
88 textInputTypeDateTime, textInputTypeDateTimeLocal,
89 textInputTypeMonth, textInputTypeTime, textInputTypeWeek);
92 private native void nativeReplaceDateTime(long nativeDateTimeChooserAndroid,
95 private native void nativeCancelDialog(long nativeDateTimeChooserAndroid);