Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java

Issue 23026006: Add support for color input datalist on Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.web_contents_delegate_android; 5 package org.chromium.components.web_contents_delegate_android;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 8
9 import org.chromium.base.CalledByNative; 9 import org.chromium.base.CalledByNative;
10 import org.chromium.base.JNINamespace; 10 import org.chromium.base.JNINamespace;
11 import org.chromium.content.browser.ContentViewCore; 11 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.ui.ColorSuggestion;
12 import org.chromium.ui.ColorPickerDialog; 13 import org.chromium.ui.ColorPickerDialog;
13 import org.chromium.ui.OnColorChangedListener; 14 import org.chromium.ui.OnColorChangedListener;
14 15
15 /** 16 /**
16 * ColorChooserAndroid communicates with the java ColorPickerDialog and the 17 * ColorChooserAndroid communicates with the java ColorPickerDialog and the
17 * native color_chooser_android.cc 18 * native color_chooser_android.cc
18 */ 19 */
19 @JNINamespace("web_contents_delegate_android") 20 @JNINamespace("web_contents_delegate_android")
20 public class ColorChooserAndroid { 21 public class ColorChooserAndroid {
21 private final ColorPickerDialog mDialog; 22 private final ColorPickerDialog mDialog;
22 private final int mNativeColorChooserAndroid; 23 private final int mNativeColorChooserAndroid;
23 24
24 private ColorChooserAndroid(int nativeColorChooserAndroid, 25 private ColorChooserAndroid(int nativeColorChooserAndroid,
25 Context context, int initialColor) { 26 Context context, int initialColor, ColorSuggestion[] suggestions) {
26 OnColorChangedListener listener = new OnColorChangedListener() { 27 OnColorChangedListener listener = new OnColorChangedListener() {
27 @Override 28 @Override
28 public void onColorChanged(int color) { 29 public void onColorChanged(int color) {
29 mDialog.dismiss(); 30 mDialog.dismiss();
30 nativeOnColorChosen(mNativeColorChooserAndroid, color); 31 nativeOnColorChosen(mNativeColorChooserAndroid, color);
31 } 32 }
32 }; 33 };
33 34
34 mNativeColorChooserAndroid = nativeColorChooserAndroid; 35 mNativeColorChooserAndroid = nativeColorChooserAndroid;
35 mDialog = new ColorPickerDialog(context, listener, initialColor); 36 mDialog = new ColorPickerDialog(context, listener, initialColor, suggest ions);
36 } 37 }
37 38
38 private void openColorChooser() { 39 private void openColorChooser() {
39 mDialog.show(); 40 mDialog.show();
40 } 41 }
41 42
42 @CalledByNative 43 @CalledByNative
43 public void closeColorChooser() { 44 public void closeColorChooser() {
44 mDialog.dismiss(); 45 mDialog.dismiss();
45 } 46 }
46 47
47 @CalledByNative 48 @CalledByNative
48 public static ColorChooserAndroid createColorChooserAndroid( 49 public static ColorChooserAndroid createColorChooserAndroid(
49 int nativeColorChooserAndroid, 50 int nativeColorChooserAndroid,
50 ContentViewCore contentViewCore, 51 ContentViewCore contentViewCore,
51 int initialColor) { 52 int initialColor,
53 ColorSuggestion[] suggestions) {
52 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser Android, 54 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser Android,
53 contentViewCore.getContext(), initialColor); 55 contentViewCore.getContext(), initialColor, suggestions);
54 chooser.openColorChooser(); 56 chooser.openColorChooser();
55 return chooser; 57 return chooser;
56 } 58 }
57 59
60 @CalledByNative
61 private static ColorSuggestion[] createColorSuggestionArray(int size) {
62 return new ColorSuggestion[size];
63 }
64
65 /**
66 * @param array ColorSuggestion array that should get a new suggestion added .
67 * @param index Index in the array where to place a new suggestion.
68 * @param color Color of the suggestion.
69 * @param label Label of the suggestion.
70 */
71 @CalledByNative
72 private static void addToColorSuggestionArray(ColorSuggestion[] array, int i ndex,
73 int color, String label) {
74 array[index] = new ColorSuggestion(color, label);
75 }
76
58 // Implemented in color_chooser_android.cc 77 // Implemented in color_chooser_android.cc
59 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor); 78 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor);
60 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698