mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 947793 - Change clipboard manager hasText implementation to directly query the android clipboardservice. r=jchen
This commit is contained in:
parent
c5dc1f883a
commit
381eadd30d
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user