Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| diff --git a/ui/android/java/src/org/chromium/ui/base/Clipboard.java b/ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| index e62c84ab84134c46b304d537d96300d8e0f234d8..c81d3ec80f1cc36b0e1f4b2472b3b51371e48226 100644 |
| --- a/ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| +++ b/ui/android/java/src/org/chromium/ui/base/Clipboard.java |
| @@ -30,7 +30,7 @@ public class Clipboard { |
| * |
| * @param context for accessing the clipboard |
| */ |
| - private Clipboard(final Context context) { |
| + public Clipboard(final Context context) { |
| mContext = context; |
| mClipboardManager = (ClipboardManager) |
| context.getSystemService(Context.CLIPBOARD_SERVICE); |
| @@ -82,12 +82,40 @@ public class Clipboard { |
| * clipboard's current primary clip to a plain-text clip that consists of |
| * the specified string. |
| * |
| + * @param label will become the label of the clipboard's primary clip |
| + * @param text will become the content of the clipboard's primary clip |
| + */ |
| + public void setText(final String label, final String text) { |
| + setPrimaryClipNoException(ClipData.newPlainText(label, text)); |
| + } |
| + |
| + /** |
| + * Emulates the behavior of the now-deprecated |
| + * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the |
| + * clipboard's current primary clip to a plain-text clip that consists of |
| + * the specified string. |
| + * |
| * @param text will become the content of the clipboard's primary clip |
| */ |
| @SuppressWarnings("javadoc") |
| @CalledByNative |
| private void setText(final String text) { |
| - mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); |
| + setText(null, text); |
| + } |
| + |
| + /** |
| + * Writes HTML to the clipboard, together with a plain-text representation |
| + * of that very data. This API is only available in Android JellyBean+ and |
| + * will be a no-operation in older versions. |
| + * |
| + * @param html The HTML content to be pasted to the clipboard. |
| + * @param label The Plain-text label for the HTML content. |
| + * @param text Plain-text representation of the HTML content. |
| + */ |
| + public void setHTMLText(final String html, final String label, final String text) { |
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| + setPrimaryClipNoException(ClipData.newHtmlText(label, text, html)); |
| + } |
| } |
| /** |
| @@ -100,10 +128,7 @@ public class Clipboard { |
| */ |
| @CalledByNative |
| private void setHTMLText(final String html, final String text) { |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| - mClipboardManager.setPrimaryClip( |
| - ClipData.newHtmlText(null, text, html)); |
| - } |
| + setHTMLText(html, null, text); |
| } |
| /** |
| @@ -125,4 +150,12 @@ public class Clipboard { |
| } |
| return false; |
| } |
| + |
| + private void setPrimaryClipNoException(ClipData clip) { |
| + try { |
| + mClipboardManager.setPrimaryClip(clip); |
| + } catch (Exception ex) { |
|
Ted C
2013/11/26 01:50:09
We should throw up some kind of toast saying copyi
David Trainor- moved to gerrit
2013/11/26 23:51:07
Done.
|
| + // Ignore any exceptions here as certain devices have bugs and will fail. |
| + } |
| + } |
| } |