OLD | NEW |
---|---|
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 AutofillSuggestion array that should get a new suggestion ad ded. | |
67 * @param index Index in the array where to place a new suggestion. | |
68 * @param name Name of the suggestion. | |
newt (away)
2013/08/26 20:23:20
these params need updating
keishi
2013/08/29 03:40:47
Done.
| |
69 * @param label Label of the suggestion. | |
70 * @param uniqueId Unique suggestion id. | |
71 */ | |
72 @CalledByNative | |
73 private static void addToColorSuggestionArray(ColorSuggestion[] array, int i ndex, | |
74 int valueAsColor, String displayString, String label) { | |
75 array[index] = new ColorSuggestion(valueAsColor, displayString, label); | |
76 } | |
77 | |
58 // Implemented in color_chooser_android.cc | 78 // Implemented in color_chooser_android.cc |
59 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor); | 79 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor); |
60 } | 80 } |
OLD | NEW |