OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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; | 5 package org.chromium.ui; |
6 | 6 |
7 import org.chromium.base.CalledByNative; | 7 import org.chromium.base.CalledByNative; |
8 import org.chromium.base.JNINamespace; | 8 import org.chromium.base.JNINamespace; |
9 | 9 |
10 import android.content.ClipData; | 10 import android.content.ClipData; |
11 import android.content.ClipboardManager; | 11 import android.content.ClipboardManager; |
12 import android.content.Context; | 12 import android.content.Context; |
| 13 import android.os.Build; |
13 import android.text.TextUtils; | 14 import android.text.TextUtils; |
14 | 15 |
15 /** | 16 /** |
16 * Simple proxy that provides C++ code with an access pathway to the Android | 17 * Simple proxy that provides C++ code with an access pathway to the Android |
17 * clipboard. | 18 * clipboard. |
18 */ | 19 */ |
19 @JNINamespace("ui") | 20 @JNINamespace("ui") |
20 public class Clipboard { | 21 public class Clipboard { |
21 // Necessary for coercing clipboard contents to text if they require | 22 // Necessary for coercing clipboard contents to text if they require |
22 // access to network resources, etceteras (e.g., URI in clipboard) | 23 // access to network resources, etceteras (e.g., URI in clipboard) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 * | 84 * |
84 * @param text will become the content of the clipboard's primary clip | 85 * @param text will become the content of the clipboard's primary clip |
85 */ | 86 */ |
86 @SuppressWarnings("javadoc") | 87 @SuppressWarnings("javadoc") |
87 @CalledByNative | 88 @CalledByNative |
88 private void setText(final String text) { | 89 private void setText(final String text) { |
89 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); | 90 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); |
90 } | 91 } |
91 | 92 |
92 /** | 93 /** |
| 94 * Writes HTML to the clipboard, together with a plain-text representation |
| 95 * of that very data. This API is only available in Android JellyBean+ and |
| 96 * will be a no-operation in older versions. |
| 97 * |
| 98 * @param html The HTML content to be pasted to the clipboard. |
| 99 * @param text Plain-text representation of the HTML content. |
| 100 */ |
| 101 @CalledByNative |
| 102 private void setHTMLText(final String html, final String text) { |
| 103 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| 104 mClipboardManager.setPrimaryClip( |
| 105 ClipData.newHtmlText(null, text, html)); |
| 106 } |
| 107 } |
| 108 |
| 109 /** |
93 * Approximates the behavior of the now-deprecated | 110 * Approximates the behavior of the now-deprecated |
94 * {@link android.text.ClipboardManager#hasText()}, returning true if and | 111 * {@link android.text.ClipboardManager#hasText()}, returning true if and |
95 * only if the clipboard has a primary clip and that clip contains a plain | 112 * only if the clipboard has a primary clip and that clip contains a plain |
96 * non-empty text entry (without attempting coercion - URLs and intents | 113 * non-empty text entry (without attempting coercion - URLs and intents |
97 * will cause this method to return false). | 114 * will cause this method to return false). |
98 * | 115 * |
99 * @return as described above | 116 * @return as described above |
100 */ | 117 */ |
101 @SuppressWarnings("javadoc") | 118 @SuppressWarnings("javadoc") |
102 @CalledByNative | 119 @CalledByNative |
103 private boolean hasPlainText() { | 120 private boolean hasPlainText() { |
104 final ClipData clip = mClipboardManager.getPrimaryClip(); | 121 final ClipData clip = mClipboardManager.getPrimaryClip(); |
105 if (clip != null && clip.getItemCount() > 0) { | 122 if (clip != null && clip.getItemCount() > 0) { |
106 final CharSequence text = clip.getItemAt(0).getText(); | 123 final CharSequence text = clip.getItemAt(0).getText(); |
107 return !TextUtils.isEmpty(text); | 124 return !TextUtils.isEmpty(text); |
108 } | 125 } |
109 return false; | 126 return false; |
110 } | 127 } |
111 } | 128 } |
OLD | NEW |