mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Update Android port
* java/org/gnu/emacs/EmacsInputConnection.java (beginBatchEdit) (endBatchEdit, commitCompletion, commitText, deleteSurroundingText) (finishComposingText, getSelectedText, getTextAfterCursor) (getTextBeforeCursor, setComposingText, setComposingRegion) (performEditorAction, performContextMenuAction, getExtractedText) (setSelection, sendKeyEvent, deleteSurroundingTextInCodePoints) (requestCursorUpdates): Ensure that the input connection is up to date. (getSurroundingText): New function. * java/org/gnu/emacs/EmacsNative.java (getSurroundingText): Export new C function. * java/org/gnu/emacs/EmacsService.java (resetIC): Invalidate previously created input connections. * java/org/gnu/emacs/EmacsView.java (EmacsView) (onCreateInputConnection): Signify that input connections are now up to date. * src/androidterm.c (struct android_get_surrounding_text_context): New structure. (android_get_surrounding_text, NATIVE_NAME): * src/textconv.c (get_surrounding_text): * src/textconv.h: New functions.
This commit is contained in:
parent
9a68041f2c
commit
63339a9577
7 changed files with 370 additions and 0 deletions
|
|
@ -23,7 +23,9 @@ import android.view.inputmethod.BaseInputConnection;
|
|||
import android.view.inputmethod.CompletionInfo;
|
||||
import android.view.inputmethod.ExtractedText;
|
||||
import android.view.inputmethod.ExtractedTextRequest;
|
||||
import android.view.inputmethod.SurroundingText;
|
||||
import android.view.inputmethod.TextSnapshot;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import android.os.Build;
|
||||
|
|
@ -88,6 +90,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
beginBatchEdit ()
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "beginBatchEdit");
|
||||
|
||||
|
|
@ -99,6 +105,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
endBatchEdit ()
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "endBatchEdit");
|
||||
|
||||
|
|
@ -110,6 +120,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
commitCompletion (CompletionInfo info)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "commitCompletion: " + info);
|
||||
|
||||
|
|
@ -125,6 +139,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
{
|
||||
int[] selection;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "commitText: " + text + " " + newCursorPosition);
|
||||
|
||||
|
|
@ -156,6 +174,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
deleteSurroundingText (int leftLength, int rightLength)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, ("deleteSurroundingText: "
|
||||
+ leftLength + " " + rightLength));
|
||||
|
|
@ -169,6 +191,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
finishComposingText ()
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "finishComposingText");
|
||||
|
||||
|
|
@ -180,6 +206,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public String
|
||||
getSelectedText (int flags)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return null;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "getSelectedText: " + flags);
|
||||
|
||||
|
|
@ -192,6 +222,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
{
|
||||
String string;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return null;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "getTextAfterCursor: " + length + " " + flags);
|
||||
|
||||
|
|
@ -210,6 +244,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
{
|
||||
String string;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return null;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "getTextBeforeCursor: " + length + " " + flags);
|
||||
|
||||
|
|
@ -226,6 +264,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
setComposingText (CharSequence text, int newCursorPosition)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, ("setComposingText: "
|
||||
+ text + " ## " + newCursorPosition));
|
||||
|
|
@ -239,6 +281,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
setComposingRegion (int start, int end)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "setComposingRegion: " + start + " " + end);
|
||||
|
||||
|
|
@ -250,6 +296,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
performEditorAction (int editorAction)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "performEditorAction: " + editorAction);
|
||||
|
||||
|
|
@ -263,6 +313,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
{
|
||||
int action;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "performContextMenuAction: " + contextMenuAction);
|
||||
|
||||
|
|
@ -310,6 +364,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
ExtractedText text;
|
||||
int[] selection;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return null;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "getExtractedText: " + request.hintMaxChars + ", "
|
||||
+ request.hintMaxLines + " " + flags);
|
||||
|
|
@ -360,6 +418,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
setSelection (int start, int end)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "setSelection: " + start + " " + end);
|
||||
|
||||
|
|
@ -371,6 +433,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
sendKeyEvent (KeyEvent key)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "sendKeyEvent: " + key);
|
||||
|
||||
|
|
@ -381,6 +447,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
deleteSurroundingTextInCodePoints (int beforeLength, int afterLength)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
/* This can be implemented the same way as
|
||||
deleteSurroundingText. */
|
||||
return this.deleteSurroundingText (beforeLength, afterLength);
|
||||
|
|
@ -390,6 +460,10 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
public boolean
|
||||
requestCursorUpdates (int cursorUpdateMode)
|
||||
{
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return false;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, "requestCursorUpdates: " + cursorUpdateMode);
|
||||
|
||||
|
|
@ -397,6 +471,37 @@ public final class EmacsInputConnection extends BaseInputConnection
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SurroundingText
|
||||
getSurroundingText (int beforeLength, int afterLength,
|
||||
int flags)
|
||||
{
|
||||
SurroundingText text;
|
||||
|
||||
/* Return if the input connection is out of date. */
|
||||
if (view.icSerial < view.icGeneration)
|
||||
return null;
|
||||
|
||||
if (EmacsService.DEBUG_IC)
|
||||
Log.d (TAG, ("getSurroundingText: " + beforeLength + ", "
|
||||
+ afterLength));
|
||||
|
||||
text = EmacsNative.getSurroundingText (windowHandle, beforeLength,
|
||||
afterLength, flags);
|
||||
|
||||
if (text != null)
|
||||
Log.d (TAG, ("getSurroundingText: "
|
||||
+ text.getSelectionStart ()
|
||||
+ ","
|
||||
+ text.getSelectionEnd ()
|
||||
+ "+"
|
||||
+ text.getOffset ()
|
||||
+ ": "
|
||||
+ text.getText ()));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/* Override functions which are not implemented. */
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import android.graphics.Bitmap;
|
|||
|
||||
import android.view.inputmethod.ExtractedText;
|
||||
import android.view.inputmethod.ExtractedTextRequest;
|
||||
import android.view.inputmethod.SurroundingText;
|
||||
|
||||
public final class EmacsNative
|
||||
{
|
||||
|
|
@ -222,6 +223,9 @@ public final class EmacsNative
|
|||
public static native void requestSelectionUpdate (short window);
|
||||
public static native void requestCursorUpdates (short window, int mode);
|
||||
public static native void clearInputFlags (short window);
|
||||
public static native SurroundingText getSurroundingText (short window,
|
||||
int left, int right,
|
||||
int flags);
|
||||
|
||||
|
||||
/* Return the current value of the selection, or -1 upon
|
||||
|
|
|
|||
|
|
@ -748,6 +748,7 @@ public final class EmacsService extends Service
|
|||
window.view.setICMode (icMode);
|
||||
|
||||
icBeginSynchronous ();
|
||||
window.view.icGeneration++;
|
||||
window.view.imManager.restartInput (window.view);
|
||||
icEndSynchronous ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,13 @@ public final class EmacsView extends ViewGroup
|
|||
details. */
|
||||
private int icMode;
|
||||
|
||||
/* The number of calls to `resetIC' to have taken place the last
|
||||
time an InputConnection was created. */
|
||||
public long icSerial;
|
||||
|
||||
/* The number of calls to `recetIC' that have taken place. */
|
||||
public volatile long icGeneration;
|
||||
|
||||
public
|
||||
EmacsView (EmacsWindow window)
|
||||
{
|
||||
|
|
@ -627,6 +634,12 @@ public final class EmacsView extends ViewGroup
|
|||
return null;
|
||||
}
|
||||
|
||||
/* Set icSerial. If icSerial < icGeneration, the input connection
|
||||
has been reset, and future input should be ignored until a new
|
||||
connection is created. */
|
||||
|
||||
icSerial = icGeneration;
|
||||
|
||||
/* Reset flags set by the previous input method. */
|
||||
|
||||
EmacsNative.clearInputFlags (window.handle);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue