OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.app.Activity; |
7 import android.content.Context; | 8 import android.content.Context; |
8 | 9 |
9 import org.chromium.base.CalledByNative; | 10 import org.chromium.base.CalledByNative; |
10 import org.chromium.base.JNINamespace; | 11 import org.chromium.base.JNINamespace; |
11 import org.chromium.content.browser.ContentViewCore; | |
12 import org.chromium.ui.ColorPickerDialog; | 12 import org.chromium.ui.ColorPickerDialog; |
13 import org.chromium.ui.ColorSuggestion; | 13 import org.chromium.ui.ColorSuggestion; |
14 import org.chromium.ui.OnColorChangedListener; | 14 import org.chromium.ui.OnColorChangedListener; |
| 15 import org.chromium.ui.base.WindowAndroid; |
15 | 16 |
16 /** | 17 /** |
17 * ColorChooserAndroid communicates with the java ColorPickerDialog and the | 18 * ColorChooserAndroid communicates with the java ColorPickerDialog and the |
18 * native color_chooser_android.cc | 19 * native color_chooser_android.cc |
19 */ | 20 */ |
20 @JNINamespace("web_contents_delegate_android") | 21 @JNINamespace("web_contents_delegate_android") |
21 public class ColorChooserAndroid { | 22 public class ColorChooserAndroid { |
22 private final ColorPickerDialog mDialog; | 23 private final ColorPickerDialog mDialog; |
23 private final long mNativeColorChooserAndroid; | 24 private final long mNativeColorChooserAndroid; |
24 | 25 |
(...skipping 16 matching lines...) Expand all Loading... |
41 } | 42 } |
42 | 43 |
43 @CalledByNative | 44 @CalledByNative |
44 public void closeColorChooser() { | 45 public void closeColorChooser() { |
45 mDialog.dismiss(); | 46 mDialog.dismiss(); |
46 } | 47 } |
47 | 48 |
48 @CalledByNative | 49 @CalledByNative |
49 public static ColorChooserAndroid createColorChooserAndroid( | 50 public static ColorChooserAndroid createColorChooserAndroid( |
50 long nativeColorChooserAndroid, | 51 long nativeColorChooserAndroid, |
51 ContentViewCore contentViewCore, | 52 WindowAndroid windowAndroid, |
52 int initialColor, | 53 int initialColor, |
53 ColorSuggestion[] suggestions) { | 54 ColorSuggestion[] suggestions) { |
| 55 Activity windowAndroidActivity = windowAndroid.getActivity().get(); |
| 56 if (windowAndroidActivity == null) return null; |
54 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser
Android, | 57 ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooser
Android, |
55 contentViewCore.getContext(), initialColor, suggestions); | 58 windowAndroidActivity, initialColor, suggestions); |
56 chooser.openColorChooser(); | 59 chooser.openColorChooser(); |
57 return chooser; | 60 return chooser; |
58 } | 61 } |
59 | 62 |
60 @CalledByNative | 63 @CalledByNative |
61 private static ColorSuggestion[] createColorSuggestionArray(int size) { | 64 private static ColorSuggestion[] createColorSuggestionArray(int size) { |
62 return new ColorSuggestion[size]; | 65 return new ColorSuggestion[size]; |
63 } | 66 } |
64 | 67 |
65 /** | 68 /** |
66 * @param array ColorSuggestion array that should get a new suggestion added
. | 69 * @param array ColorSuggestion array that should get a new suggestion added
. |
67 * @param index Index in the array where to place a new suggestion. | 70 * @param index Index in the array where to place a new suggestion. |
68 * @param color Color of the suggestion. | 71 * @param color Color of the suggestion. |
69 * @param label Label of the suggestion. | 72 * @param label Label of the suggestion. |
70 */ | 73 */ |
71 @CalledByNative | 74 @CalledByNative |
72 private static void addToColorSuggestionArray(ColorSuggestion[] array, int i
ndex, | 75 private static void addToColorSuggestionArray(ColorSuggestion[] array, int i
ndex, |
73 int color, String label) { | 76 int color, String label) { |
74 array[index] = new ColorSuggestion(color, label); | 77 array[index] = new ColorSuggestion(color, label); |
75 } | 78 } |
76 | 79 |
77 // Implemented in color_chooser_android.cc | 80 // Implemented in color_chooser_android.cc |
78 private native void nativeOnColorChosen(long nativeColorChooserAndroid, int
color); | 81 private native void nativeOnColorChosen(long nativeColorChooserAndroid, int
color); |
79 } | 82 } |
OLD | NEW |