You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
ATLKeyboard: Integrate with phosh and wayland IME
This commit is contained in:
12
src/api-impl/android/app/ATLKeyboardDialog.java
Normal file
12
src/api-impl/android/app/ATLKeyboardDialog.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package android.app;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class ATLKeyboardDialog extends Dialog {
|
||||
@Override
|
||||
protected native long nativeInit();
|
||||
|
||||
public ATLKeyboardDialog(Context context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import android.view.Window;
|
||||
public class Dialog implements Window.Callback, DialogInterface {
|
||||
protected long nativePtr;
|
||||
|
||||
private native long nativeInit();
|
||||
protected native long nativeInit();
|
||||
private native void nativeSetTitle(long ptr, String title);
|
||||
private native void nativeSetContentView(long ptr, long widget);
|
||||
private native void nativeShow(long ptr);
|
||||
|
||||
@@ -29,6 +29,11 @@ public class ATLKeyboardViewer extends Activity {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
ims.launch_keyboard();
|
||||
boolean is_layershell = true;
|
||||
|
||||
if (extras.containsKey("layershell") && extras.getString("layershell").equals("off"))
|
||||
is_layershell = false;
|
||||
|
||||
ims.launch_keyboard(is_layershell);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package android.inputmethodservice;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ATLKeyboardDialog;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -30,38 +32,58 @@ public class InputMethodService extends AbstractInputMethodService {
|
||||
private Dialog kb_dialog;
|
||||
|
||||
class ATLInputConnection extends BaseInputConnection {
|
||||
protected long nativePtr;
|
||||
|
||||
private native long nativeInit();
|
||||
private native boolean nativeSetCompositingText(long ptr, String text, int newCursorPosition);
|
||||
private native boolean nativeSetCompositingRegion(long ptr, int start, int end);
|
||||
private native boolean nativeFinishComposingText(long ptr);
|
||||
private native boolean nativeCommitText(long ptr, String text, int newCursorPosition);
|
||||
private native boolean nativeDeleteSurroundingText(long ptr, int beforeLength, int afterLength);
|
||||
private native boolean nativeSetSelection(long ptr, int start, int end);
|
||||
private native boolean nativeSendKeyEvent(long ptr, long time, long key, long state);
|
||||
|
||||
|
||||
ATLInputConnection() {
|
||||
super(null, false);
|
||||
nativePtr = nativeInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
||||
System.out.println("softkeyboard preview: setComposingText(\""+text+"\", "+newCursorPosition+")");
|
||||
return true;
|
||||
return nativeSetCompositingText(nativePtr, text.toString(), newCursorPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComposingRegion(int start, int end) {
|
||||
return nativeSetCompositingRegion(nativePtr, start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finishComposingText() {
|
||||
System.out.println("softkeyboard preview: finishComposingText()");
|
||||
return true;
|
||||
return nativeFinishComposingText(nativePtr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commitText(CharSequence text, int newCursorPosition) {
|
||||
System.out.println("softkeyboard preview: commitText(\""+text+"\", "+newCursorPosition+")");
|
||||
return true;
|
||||
return nativeCommitText(nativePtr, text.toString(), newCursorPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
|
||||
System.out.println("softkeyboard preview: deleteSurroundingText("+beforeLength+", "+afterLength+")");
|
||||
return true;
|
||||
System.out.println("ATLKeyboardIMS: deleteSurroundingText("+ beforeLength + ", " + afterLength +")");
|
||||
return nativeDeleteSurroundingText(nativePtr, beforeLength, afterLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSelection(int start, int end) {
|
||||
return nativeSetSelection(nativePtr, start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendKeyEvent(KeyEvent event) {
|
||||
System.out.println("softkeyboard preview: sendKeyEvent("+event+")");
|
||||
return true;
|
||||
return nativeSendKeyEvent(nativePtr, event.getEventTime(), event.getKeyCode(), event.getAction());
|
||||
}
|
||||
|
||||
/* these functions are noop on AOSP by default, so we just add a print for debugging purposes and still return false */
|
||||
@@ -84,8 +106,11 @@ public class InputMethodService extends AbstractInputMethodService {
|
||||
super(new Context());
|
||||
}
|
||||
|
||||
public void launch_keyboard() {
|
||||
kb_dialog = new Dialog(this);
|
||||
public void launch_keyboard(boolean is_layershell) {
|
||||
if (is_layershell)
|
||||
kb_dialog = new ATLKeyboardDialog(this);
|
||||
else
|
||||
kb_dialog = new Dialog(this);
|
||||
|
||||
View decorview = kb_dialog.getWindow().getDecorView();
|
||||
decorview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
@@ -138,7 +163,7 @@ public class InputMethodService extends AbstractInputMethodService {
|
||||
}
|
||||
|
||||
public InputBinding getCurrentInputBinding() {
|
||||
return new InputBinding(new ATLInputConnection(), null, 0, 0);
|
||||
return new InputBinding(input_connection, null, 0, 0);
|
||||
}
|
||||
|
||||
public IBinder onBind(Intent intent) {
|
||||
|
||||
@@ -1363,7 +1363,8 @@ public final class MotionEvent extends InputEvent {
|
||||
int pointerIndex, PointerProperties outPointerProperties);
|
||||
|
||||
private static native void nativeScale(int nativePtr, float scale);
|
||||
private static native void nativeTransform(int nativePtr, Matrix matrix);
|
||||
private static /* native */ void nativeTransform(int nativePtr, Matrix matrix) {
|
||||
}
|
||||
|
||||
private static final int X_OFFSET = 0;
|
||||
private static final int Y_OFFSET = 1;
|
||||
|
||||
Reference in New Issue
Block a user