diff options
| author | Po Lu | 2024-05-18 20:45:35 +0800 |
|---|---|---|
| committer | Po Lu | 2024-05-18 20:45:35 +0800 |
| commit | 8dc00dc22250b383e7692fc761cbca25b014aa8a (patch) | |
| tree | a016100ec536856ccbb3c7334b63e0595b8b549f /java/org | |
| parent | 5ec4c1a7d3f0d184982f4efa0c01bc9a76197533 (diff) | |
| download | emacs-8dc00dc22250b383e7692fc761cbca25b014aa8a.tar.gz emacs-8dc00dc22250b383e7692fc761cbca25b014aa8a.zip | |
Housekeeping around androidselect.c
* java/org/gnu/emacs/EmacsClipboard.java (setClipboard)
(getClipboard):
* java/org/gnu/emacs/EmacsSdk11Clipboard.java (setClipboard)
(getClipboard):
* java/org/gnu/emacs/EmacsSdk8Clipboard.java (setClipboard)
(getClipboard): Save and return Strings rather than byte arrays.
* src/androidselect.c (android_init_emacs_clipboard)
(Fandroid_set_clipboard, Fandroid_get_clipboard): Adjust to
match.
Diffstat (limited to 'java/org')
| -rw-r--r-- | java/org/gnu/emacs/EmacsClipboard.java | 4 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsSdk11Clipboard.java | 47 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsSdk8Clipboard.java | 29 |
3 files changed, 22 insertions, 58 deletions
diff --git a/java/org/gnu/emacs/EmacsClipboard.java b/java/org/gnu/emacs/EmacsClipboard.java index 86553f478ed..2560ef793c2 100644 --- a/java/org/gnu/emacs/EmacsClipboard.java +++ b/java/org/gnu/emacs/EmacsClipboard.java | |||
| @@ -27,10 +27,10 @@ import android.os.Build; | |||
| 27 | 27 | ||
| 28 | public abstract class EmacsClipboard | 28 | public abstract class EmacsClipboard |
| 29 | { | 29 | { |
| 30 | public abstract void setClipboard (byte[] bytes); | 30 | public abstract void setClipboard (String string); |
| 31 | public abstract int ownsClipboard (); | 31 | public abstract int ownsClipboard (); |
| 32 | public abstract boolean clipboardExists (); | 32 | public abstract boolean clipboardExists (); |
| 33 | public abstract byte[] getClipboard (); | 33 | public abstract String getClipboard (); |
| 34 | 34 | ||
| 35 | public abstract String[] getClipboardTargets (); | 35 | public abstract String[] getClipboardTargets (); |
| 36 | public abstract AssetFileDescriptor getClipboardData (String target); | 36 | public abstract AssetFileDescriptor getClipboardData (String target); |
diff --git a/java/org/gnu/emacs/EmacsSdk11Clipboard.java b/java/org/gnu/emacs/EmacsSdk11Clipboard.java index dfc714476ec..e179551c14d 100644 --- a/java/org/gnu/emacs/EmacsSdk11Clipboard.java +++ b/java/org/gnu/emacs/EmacsSdk11Clipboard.java | |||
| @@ -86,32 +86,23 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard | |||
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | /* Set the clipboard text to CLIPBOARD, a string in UTF-8 | 89 | /* Save the STRING into the clipboard by way of text copied by the |
| 90 | encoding. */ | 90 | user. */ |
| 91 | 91 | ||
| 92 | @Override | 92 | @Override |
| 93 | public synchronized void | 93 | public synchronized void |
| 94 | setClipboard (byte[] bytes) | 94 | setClipboard (String string) |
| 95 | { | 95 | { |
| 96 | ClipData data; | 96 | ClipData data; |
| 97 | String string; | ||
| 98 | 97 | ||
| 99 | try | 98 | data = ClipData.newPlainText ("Emacs", string); |
| 100 | { | 99 | manager.setPrimaryClip (data); |
| 101 | string = new String (bytes, "UTF-8"); | 100 | ownsClipboard = true; |
| 102 | data = ClipData.newPlainText ("Emacs", string); | 101 | |
| 103 | manager.setPrimaryClip (data); | 102 | /* onPrimaryClipChanged will be called again. Use this |
| 104 | ownsClipboard = true; | 103 | variable to keep track of how many times the clipboard has |
| 105 | 104 | been changed. */ | |
| 106 | /* onPrimaryClipChanged will be called again. Use this | 105 | ++clipboardChangedCount; |
| 107 | variable to keep track of how many times the clipboard has | ||
| 108 | been changed. */ | ||
| 109 | ++clipboardChangedCount; | ||
| 110 | } | ||
| 111 | catch (UnsupportedEncodingException exception) | ||
| 112 | { | ||
| 113 | Log.w (TAG, "setClipboard: " + exception); | ||
| 114 | } | ||
| 115 | } | 106 | } |
| 116 | 107 | ||
| 117 | /* Return whether or not Emacs owns the clipboard. Value is 1 if | 108 | /* Return whether or not Emacs owns the clipboard. Value is 1 if |
| @@ -141,7 +132,7 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard | |||
| 141 | NULL if no content is available. */ | 132 | NULL if no content is available. */ |
| 142 | 133 | ||
| 143 | @Override | 134 | @Override |
| 144 | public byte[] | 135 | public String |
| 145 | getClipboard () | 136 | getClipboard () |
| 146 | { | 137 | { |
| 147 | ClipData clip; | 138 | ClipData clip; |
| @@ -154,18 +145,8 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard | |||
| 154 | return null; | 145 | return null; |
| 155 | 146 | ||
| 156 | context = EmacsService.SERVICE; | 147 | context = EmacsService.SERVICE; |
| 157 | 148 | text = clip.getItemAt (0).coerceToText (context); | |
| 158 | try | 149 | return text.toString (); |
| 159 | { | ||
| 160 | text = clip.getItemAt (0).coerceToText (context); | ||
| 161 | return text.toString ().getBytes ("UTF-8"); | ||
| 162 | } | ||
| 163 | catch (UnsupportedEncodingException exception) | ||
| 164 | { | ||
| 165 | Log.w (TAG, "getClipboard: " + exception); | ||
| 166 | } | ||
| 167 | |||
| 168 | return null; | ||
| 169 | } | 150 | } |
| 170 | 151 | ||
| 171 | /* Return an array of targets currently provided by the | 152 | /* Return an array of targets currently provided by the |
diff --git a/java/org/gnu/emacs/EmacsSdk8Clipboard.java b/java/org/gnu/emacs/EmacsSdk8Clipboard.java index 344ec6f7997..afd235babf5 100644 --- a/java/org/gnu/emacs/EmacsSdk8Clipboard.java +++ b/java/org/gnu/emacs/EmacsSdk8Clipboard.java | |||
| @@ -52,21 +52,14 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard | |||
| 52 | = (ClipboardManager) context.getSystemService (what); | 52 | = (ClipboardManager) context.getSystemService (what); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /* Set the clipboard text to CLIPBOARD, a string in UTF-8 | 55 | /* Save the STRING into the clipboard by way of text copied by the |
| 56 | encoding. */ | 56 | user. */ |
| 57 | 57 | ||
| 58 | @Override | 58 | @Override |
| 59 | public void | 59 | public void |
| 60 | setClipboard (byte[] bytes) | 60 | setClipboard (String string) |
| 61 | { | 61 | { |
| 62 | try | 62 | manager.setText (string); |
| 63 | { | ||
| 64 | manager.setText (new String (bytes, "UTF-8")); | ||
| 65 | } | ||
| 66 | catch (UnsupportedEncodingException exception) | ||
| 67 | { | ||
| 68 | Log.w (TAG, "setClipboard: " + exception); | ||
| 69 | } | ||
| 70 | } | 63 | } |
| 71 | 64 | ||
| 72 | /* Return whether or not Emacs owns the clipboard. Value is 1 if | 65 | /* Return whether or not Emacs owns the clipboard. Value is 1 if |
| @@ -93,7 +86,7 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard | |||
| 93 | NULL if no content is available. */ | 86 | NULL if no content is available. */ |
| 94 | 87 | ||
| 95 | @Override | 88 | @Override |
| 96 | public byte[] | 89 | public String |
| 97 | getClipboard () | 90 | getClipboard () |
| 98 | { | 91 | { |
| 99 | String string; | 92 | String string; |
| @@ -105,17 +98,7 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard | |||
| 105 | return null; | 98 | return null; |
| 106 | 99 | ||
| 107 | string = text.toString (); | 100 | string = text.toString (); |
| 108 | 101 | return string; | |
| 109 | try | ||
| 110 | { | ||
| 111 | return string.getBytes ("UTF-8"); | ||
| 112 | } | ||
| 113 | catch (UnsupportedEncodingException exception) | ||
| 114 | { | ||
| 115 | Log.w (TAG, "getClipboard: " + exception); | ||
| 116 | } | ||
| 117 | |||
| 118 | return null; | ||
| 119 | } | 102 | } |
| 120 | 103 | ||
| 121 | /* Return an array of targets currently provided by the | 104 | /* Return an array of targets currently provided by the |