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.ui.base; | 5 package org.chromium.ui.base; |
6 | 6 |
| 7 import android.annotation.TargetApi; |
7 import android.content.ClipData; | 8 import android.content.ClipData; |
8 import android.content.Intent; | 9 import android.content.Intent; |
9 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
10 import android.os.Build; | 11 import android.os.Build; |
11 import android.view.View; | 12 import android.view.View; |
12 import android.view.ViewGroup; | 13 import android.view.ViewGroup; |
13 import android.widget.FrameLayout.LayoutParams; | 14 import android.widget.FrameLayout.LayoutParams; |
14 import android.widget.ImageView; | 15 import android.widget.ImageView; |
15 | 16 |
16 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
17 import org.chromium.base.Log; | 18 import org.chromium.base.Log; |
18 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
19 import org.chromium.base.annotations.JNINamespace; | 20 import org.chromium.base.annotations.JNINamespace; |
20 | 21 |
21 import java.net.URISyntaxException; | 22 import java.net.URISyntaxException; |
22 | 23 |
23 /** | 24 /** |
24 * Class to acquire, position, and remove anchor views from the implementing Vie
w. | 25 * Class to acquire, position, and remove anchor views from the implementing Vie
w. |
25 */ | 26 */ |
26 @JNINamespace("ui") | 27 @JNINamespace("ui") |
27 public abstract class ViewAndroidDelegate { | 28 public abstract class ViewAndroidDelegate { |
28 private static final String TAG = "ViewAndroidDelegate"; | 29 private static final String TAG = "ViewAndroidDelegate"; |
29 | |
30 // TODO(hush): use View#DRAG_FLAG_GLOBAL when Chromium starts to build with
API 24. | |
31 private static final int DRAG_FLAG_GLOBAL = 1 << 8; | |
32 | |
33 private static final String GEO_SCHEME = "geo"; | 30 private static final String GEO_SCHEME = "geo"; |
34 private static final String TEL_SCHEME = "tel"; | 31 private static final String TEL_SCHEME = "tel"; |
35 private static final String MAILTO_SCHEME = "mailto"; | 32 private static final String MAILTO_SCHEME = "mailto"; |
36 | 33 |
37 /** | 34 /** |
38 * @return An anchor view that can be used to anchor decoration views like A
utofill popup. | 35 * @return An anchor view that can be used to anchor decoration views like A
utofill popup. |
39 */ | 36 */ |
40 @CalledByNative | 37 @CalledByNative |
41 public View acquireView() { | 38 public View acquireView() { |
42 ViewGroup containerView = getContainerView(); | 39 ViewGroup containerView = getContainerView(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 lp.topMargin = topMargin; | 85 lp.topMargin = topMargin; |
89 view.setLayoutParams(lp); | 86 view.setLayoutParams(lp); |
90 } | 87 } |
91 | 88 |
92 /** | 89 /** |
93 * Drag the text out of current view. | 90 * Drag the text out of current view. |
94 * @param text The dragged text. | 91 * @param text The dragged text. |
95 * @param shadowImage The shadow image for the dragged text. | 92 * @param shadowImage The shadow image for the dragged text. |
96 */ | 93 */ |
97 @SuppressWarnings("deprecation") | 94 @SuppressWarnings("deprecation") |
98 // TODO(hush): uncomment below when we build with API 24. | 95 @TargetApi(Build.VERSION_CODES.N) |
99 // @TargetApi(Build.VERSION_CODES.N) | |
100 @CalledByNative | 96 @CalledByNative |
101 private boolean startDragAndDrop(String text, Bitmap shadowImage) { | 97 private boolean startDragAndDrop(String text, Bitmap shadowImage) { |
102 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) return false; | 98 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) return false; |
103 | 99 |
104 ViewGroup containerView = getContainerView(); | 100 ViewGroup containerView = getContainerView(); |
105 if (containerView == null) return false; | 101 if (containerView == null) return false; |
106 | 102 |
107 ImageView imageView = new ImageView(containerView.getContext()); | 103 ImageView imageView = new ImageView(containerView.getContext()); |
108 imageView.setImageBitmap(shadowImage); | 104 imageView.setImageBitmap(shadowImage); |
109 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); | 105 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); |
110 | 106 |
111 // TODO(hush): use View#startDragAndDrop when Chromium starts to build w
ith API 24. | 107 return containerView.startDragAndDrop(ClipData.newPlainText(null, text), |
112 return containerView.startDrag(ClipData.newPlainText(null, text), | 108 new View.DragShadowBuilder(imageView), null, View.DRAG_FLAG_GLOB
AL); |
113 new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL); | |
114 } | 109 } |
115 | 110 |
116 /** | 111 /** |
117 * Called whenever the background color of the page changes as notified by B
link. | 112 * Called whenever the background color of the page changes as notified by B
link. |
118 * @param color The new ARGB color of the page background. | 113 * @param color The new ARGB color of the page background. |
119 */ | 114 */ |
120 @CalledByNative | 115 @CalledByNative |
121 public void onBackgroundColorChanged(int color) {} | 116 public void onBackgroundColorChanged(int color) {} |
122 | 117 |
123 /** | 118 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return this; | 180 return this; |
186 } | 181 } |
187 | 182 |
188 @Override | 183 @Override |
189 public ViewGroup getContainerView() { | 184 public ViewGroup getContainerView() { |
190 return mContainerView; | 185 return mContainerView; |
191 } | 186 } |
192 }.init(containerView); | 187 }.init(containerView); |
193 } | 188 } |
194 } | 189 } |
OLD | NEW |