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.ColorPickerDialog; | 12 import org.chromium.ui.ColorPickerDialog; |
13 import org.chromium.ui.OnColorChangedListener; | 13 import org.chromium.ui.OnColorChangedListener; |
14 | 14 |
15 /** | 15 /** |
16 * ColorChooserAndroid communicates with the java ColorPickerDialog and the | 16 * ColorChooserAndroid communicates with the java ColorPickerDialog and the |
17 * native color_chooser_android.cc | 17 * native color_chooser_android.cc |
18 */ | 18 */ |
19 @JNINamespace("web_contents_delegate_android") | 19 @JNINamespace("web_contents_delegate_android") |
20 public class ColorChooserAndroid { | 20 public class ColorChooserAndroid { |
21 private final ColorPickerDialog mDialog; | 21 private final ColorPickerDialog mDialog; |
22 private final int mNativeColorChooserAndroid; | 22 private final int mNativeColorChooserAndroid; |
23 | 23 |
24 private ColorChooserAndroid(int nativeColorChooserAndroid, | 24 private ColorChooserAndroid(int nativeColorChooserAndroid, |
25 Context context, int initialColor) { | 25 Context context, int initialColor, int[] suggestions, String[] sugge stionLabels) { |
Miguel Garcia
2013/08/19 14:43:27
there is a cost (albeit small) in JNIfying the arr
keishi
2013/08/26 05:28:54
I reimplemented the simple color chooser so I can
| |
26 OnColorChangedListener listener = new OnColorChangedListener() { | 26 OnColorChangedListener listener = new OnColorChangedListener() { |
27 @Override | 27 @Override |
28 public void onColorChanged(int color) { | 28 public void onColorChanged(int color) { |
29 mDialog.dismiss(); | 29 mDialog.dismiss(); |
30 nativeOnColorChosen(mNativeColorChooserAndroid, color); | 30 nativeOnColorChosen(mNativeColorChooserAndroid, color); |
31 } | 31 } |
32 }; | 32 }; |
33 | 33 |
34 mNativeColorChooserAndroid = nativeColorChooserAndroid; | 34 mNativeColorChooserAndroid = nativeColorChooserAndroid; |
35 mDialog = new ColorPickerDialog(context, listener, initialColor); | 35 mDialog = new ColorPickerDialog(context, listener, initialColor, |
36 suggestions, suggestionLabels); | |
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 int[] suggestions, | |
54 String[] suggestionLabels) { | |
52 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser Android, | 55 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser Android, |
53 contentViewCore.getContext(), initialColor); | 56 contentViewCore.getContext(), initialColor, suggestions, suggestionL abels); |
54 chooser.openColorChooser(); | 57 chooser.openColorChooser(); |
55 return chooser; | 58 return chooser; |
56 } | 59 } |
57 | 60 |
58 // Implemented in color_chooser_android.cc | 61 // Implemented in color_chooser_android.cc |
59 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor); | 62 private native void nativeOnColorChosen(int nativeColorChooserAndroid, int c olor); |
60 } | 63 } |
OLD | NEW |