Android: fix Clipboard deprecated methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 32d9446..ad9aeb5 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -2278,13 +2278,12 @@ class SDLInputConnection extends BaseInputConnection {
interface SDLClipboardHandler {
- public boolean clipboardHasText();
- public String clipboardGetText();
- public void clipboardSetText(String string);
+ boolean clipboardHasText();
+ String clipboardGetText();
+ void clipboardSetText(String string);
}
-
class SDLClipboardHandler_API11 implements
SDLClipboardHandler,
android.content.ClipboardManager.OnPrimaryClipChangedListener {
@@ -2298,15 +2297,20 @@ class SDLClipboardHandler_API11 implements
@Override
public boolean clipboardHasText() {
- return mClipMgr.hasText();
+ return mClipMgr.hasPrimaryClip();
}
@Override
public String clipboardGetText() {
- CharSequence text;
- text = mClipMgr.getText();
- if (text != null) {
- return text.toString();
+ ClipData clip = mClipMgr.getPrimaryClip();
+ if (clip != null) {
+ ClipData.Item item = clip.getItemAt(0);
+ if (item != null) {
+ CharSequence text = item.getText();
+ if (text != null) {
+ return text.toString();
+ }
+ }
}
return null;
}
@@ -2314,7 +2318,8 @@ class SDLClipboardHandler_API11 implements
@Override
public void clipboardSetText(String string) {
mClipMgr.removePrimaryClipChangedListener(this);
- mClipMgr.setText(string);
+ ClipData clip = ClipData.newPlainText(null, string);
+ mClipMgr.setPrimaryClip(clip);
mClipMgr.addPrimaryClipChangedListener(this);
}
@@ -2322,6 +2327,5 @@ class SDLClipboardHandler_API11 implements
public void onPrimaryClipChanged() {
SDLActivity.onNativeClipboardChanged();
}
-
}