Bug 947793 - Change clipboard manager hasText implementation to directly query the android clipboardservice. r=jchen

This commit is contained in:
Wes Johnston 2013-12-10 10:46:13 -08:00
parent c5dc1f883a
commit 381eadd30d

View File

@ -15,7 +15,7 @@ import java.util.concurrent.SynchronousQueue;
public final class Clipboard {
private static Context mContext;
private final static String LOG_TAG = "Clipboard";
private final static String LOGTAG = "GeckoClipboard";
private final static SynchronousQueue<String> sClipboardQueue = new SynchronousQueue<String>();
private Clipboard() {
@ -23,7 +23,7 @@ public final class Clipboard {
public static void init(Context c) {
if (mContext != null) {
Log.w(LOG_TAG, "Clipboard.init() called twice!");
Log.w(LOGTAG, "Clipboard.init() called twice!");
return;
}
mContext = c;
@ -62,7 +62,7 @@ public final class Clipboard {
@SuppressWarnings("deprecation")
public void run() {
if (Build.VERSION.SDK_INT >= 11) {
android.content.ClipboardManager cm = getClipboardManager11(mContext);
android.content.ClipboardManager cm = getClipboardManager(mContext);
ClipData clip = ClipData.newPlainText("Text", text);
try {
cm.setPrimaryClip(clip);
@ -72,7 +72,7 @@ public final class Clipboard {
// Fortunately, the text is still successfully copied to the clipboard.
}
} else {
android.text.ClipboardManager cm = getClipboardManager(mContext);
android.text.ClipboardManager cm = getDeprecatedClipboardManager(mContext);
cm.setText(text);
}
}
@ -86,8 +86,13 @@ public final class Clipboard {
*/
@WrapElementForJNI
public static boolean hasText() {
String text = getText();
return text != null;
if (Build.VERSION.SDK_INT >= 11) {
android.content.ClipboardManager cm = getClipboardManager(mContext);
return cm.hasPrimaryClip();
}
android.text.ClipboardManager cm = getDeprecatedClipboardManager(mContext);
return cm.hasText();
}
/**
@ -98,13 +103,13 @@ public final class Clipboard {
setText(null);
}
private static android.content.ClipboardManager getClipboardManager11(Context context) {
private static android.content.ClipboardManager getClipboardManager(Context context) {
// In API Level 11 and above, CLIPBOARD_SERVICE returns android.content.ClipboardManager,
// which is a subclass of android.text.ClipboardManager.
return (android.content.ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
}
private static android.text.ClipboardManager getClipboardManager(Context context) {
private static android.text.ClipboardManager getDeprecatedClipboardManager(Context context) {
return (android.text.ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
}
@ -114,7 +119,7 @@ public final class Clipboard {
@SuppressWarnings("deprecation")
private static String getClipboardTextImpl() {
if (Build.VERSION.SDK_INT >= 11) {
android.content.ClipboardManager cm = getClipboardManager11(mContext);
android.content.ClipboardManager cm = getClipboardManager(mContext);
if (cm.hasPrimaryClip()) {
ClipData clip = cm.getPrimaryClip();
if (clip != null) {
@ -123,7 +128,7 @@ public final class Clipboard {
}
}
} else {
android.text.ClipboardManager cm = getClipboardManager(mContext);
android.text.ClipboardManager cm = getDeprecatedClipboardManager(mContext);
if (cm.hasText()) {
return cm.getText().toString();
}