aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-05-06 11:32:56 +0800
committerPo Lu2023-05-06 11:32:56 +0800
commit3198b7dc565e0e41d40b6c23509c285e96044a83 (patch)
treec9193f1b8825c30fac483ed66e02eb9181397668 /java
parent96f9fe6514a2139373c50e19a77fd217ef62e6ef (diff)
downloademacs-3198b7dc565e0e41d40b6c23509c285e96044a83.tar.gz
emacs-3198b7dc565e0e41d40b6c23509c285e96044a83.zip
Update Android port
* cross/verbose.mk.android: Get rid of badly aligned ANDROID_CC messages. * java/org/gnu/emacs/EmacsInputConnection.java (syncAfterCommit) (extractAbsoluteOffsets): Add workarounds for several kinds of machines. (commitText, getExtractedText): Likewise. * src/textconv.c (really_commit_text): Improve definition of POSITION. (get_extracted_text): Default to providing at least 4 characters.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsInputConnection.java87
1 files changed, 82 insertions, 5 deletions
diff --git a/java/org/gnu/emacs/EmacsInputConnection.java b/java/org/gnu/emacs/EmacsInputConnection.java
index 7b40fcff99e..d13b48288ce 100644
--- a/java/org/gnu/emacs/EmacsInputConnection.java
+++ b/java/org/gnu/emacs/EmacsInputConnection.java
@@ -26,6 +26,8 @@ import android.view.inputmethod.ExtractedTextRequest;
26import android.view.inputmethod.TextSnapshot; 26import android.view.inputmethod.TextSnapshot;
27import android.view.KeyEvent; 27import android.view.KeyEvent;
28 28
29import android.os.Build;
30
29import android.util.Log; 31import android.util.Log;
30 32
31/* Android input methods, take number six. See textconv.c for more 33/* Android input methods, take number six. See textconv.c for more
@@ -37,6 +39,34 @@ public final class EmacsInputConnection extends BaseInputConnection
37 private EmacsView view; 39 private EmacsView view;
38 private short windowHandle; 40 private short windowHandle;
39 41
42 /* Whether or not to synchronize and call `updateIC' with the
43 selection position after committing text.
44
45 This helps with on screen keyboard programs found in some vendor
46 versions of Android, which rely on immediate updates to the point
47 position after text is commited in order to place the cursor
48 within that text. */
49
50 private static boolean syncAfterCommit;
51
52 /* Whether or not to return empty text with the offset set to zero
53 if a request arrives that has no flags set and has requested no
54 characters at all.
55
56 This is necessary with on screen keyboard programs found in some
57 vendor versions of Android which don't rely on the documented
58 meaning of `ExtractedText.startOffset', and instead take the
59 selection offset inside at face value. */
60
61 private static boolean extractAbsoluteOffsets;
62
63 static
64 {
65 if (Build.MANUFACTURER.equalsIgnoreCase ("Huawei")
66 || Build.MANUFACTURER.equalsIgnoreCase ("Honor"))
67 extractAbsoluteOffsets = syncAfterCommit = true;
68 };
69
40 public 70 public
41 EmacsInputConnection (EmacsView view) 71 EmacsInputConnection (EmacsView view)
42 { 72 {
@@ -85,11 +115,32 @@ public final class EmacsInputConnection extends BaseInputConnection
85 public boolean 115 public boolean
86 commitText (CharSequence text, int newCursorPosition) 116 commitText (CharSequence text, int newCursorPosition)
87 { 117 {
118 int[] selection;
119
88 if (EmacsService.DEBUG_IC) 120 if (EmacsService.DEBUG_IC)
89 Log.d (TAG, "commitText: " + text + " " + newCursorPosition); 121 Log.d (TAG, "commitText: " + text + " " + newCursorPosition);
90 122
91 EmacsNative.commitText (windowHandle, text.toString (), 123 EmacsNative.commitText (windowHandle, text.toString (),
92 newCursorPosition); 124 newCursorPosition);
125
126 if (syncAfterCommit)
127 {
128 /* Synchronize with the Emacs thread, obtain the new
129 selection, and report it immediately. */
130
131 selection = EmacsNative.getSelection (windowHandle);
132
133 if (EmacsService.DEBUG_IC && selection != null)
134 Log.d (TAG, "commitText: new selection is " + selection[0]
135 + ", by " + selection[1]);
136
137 if (selection != null)
138 /* N.B. that the composing region is removed after text is
139 committed. */
140 view.imManager.updateSelection (view, selection[0],
141 selection[1], -1, -1);
142 }
143
93 return true; 144 return true;
94 } 145 }
95 146
@@ -203,16 +254,42 @@ public final class EmacsInputConnection extends BaseInputConnection
203 getExtractedText (ExtractedTextRequest request, int flags) 254 getExtractedText (ExtractedTextRequest request, int flags)
204 { 255 {
205 ExtractedText text; 256 ExtractedText text;
257 int[] selection;
206 258
207 if (EmacsService.DEBUG_IC) 259 if (EmacsService.DEBUG_IC)
208 Log.d (TAG, "getExtractedText: " + request + " " + flags); 260 Log.d (TAG, "getExtractedText: " + request.hintMaxChars + ", "
209 261 + request.hintMaxLines + " " + flags);
210 text = EmacsNative.getExtractedText (windowHandle, request, 262
211 flags); 263 /* If a request arrives with hintMaxChars, hintMaxLines and flags
264 set to 0, and the system is known to be buggy, return an empty
265 extracted text object with the absolute selection positions. */
266
267 if (extractAbsoluteOffsets
268 && request.hintMaxChars == 0
269 && request.hintMaxLines == 0
270 && flags == 0)
271 {
272 /* Obtain the selection. */
273 selection = EmacsNative.getSelection (windowHandle);
274 if (selection == null)
275 return null;
276
277 /* Create the workaround extracted text. */
278 text = new ExtractedText ();
279 text.partialStartOffset = -1;
280 text.partialEndOffset = -1;
281 text.text = "";
282 text.selectionStart = selection[0];
283 text.selectionEnd = selection[1];
284 }
285 else
286 text = EmacsNative.getExtractedText (windowHandle, request,
287 flags);
212 288
213 if (EmacsService.DEBUG_IC) 289 if (EmacsService.DEBUG_IC)
214 Log.d (TAG, "getExtractedText: " + text.text + " @" 290 Log.d (TAG, "getExtractedText: " + text.text + " @"
215 + text.startOffset + ":" + text.selectionStart); 291 + text.startOffset + ":" + text.selectionStart
292 + ", " + text.selectionEnd);
216 293
217 return text; 294 return text;
218 } 295 }