From a9199c6d23232cc2be6d467d33ad285e60557d5f Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 20 Jun 2019 16:07:19 +0200 Subject: [PATCH] ui/app: (android) relay system focus events Signed-off-by: Elias Naur --- ui/app/GioView.java | 8 +++++++- ui/app/os_android.c | 5 +++++ ui/app/os_android.go | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ui/app/GioView.java b/ui/app/GioView.java index f7c7a154..fc7fd0ac 100644 --- a/ui/app/GioView.java +++ b/ui/app/GioView.java @@ -32,10 +32,16 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback public GioView(Context context, AttributeSet attrs) { super(context, attrs); + nhandle = onCreateView(this); handler = new Handler(); imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); setFocusable(true); setFocusableInTouchMode(true); + setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override public void onFocusChange(View v, boolean focus) { + GioView.this.onFocusChange(nhandle, focus); + } + }); callbacks = new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { // Ignore; surfaceChanged is guaranteed to be called immediately after this. @@ -48,7 +54,6 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback } }; getHolder().addCallback(callbacks); - nhandle = onCreateView(this); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { @@ -179,6 +184,7 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback static private native void onKeyEvent(long handle, int code, int character, long time); static private native void onFrameCallback(long handle, long nanos); static private native boolean onBack(long handle); + static private native void onFocusChange(long handle, boolean focus); private static class InputConnection extends BaseInputConnection { private final Editable editable; diff --git a/ui/app/os_android.c b/ui/app/os_android.c index f67cf627..c27f7553 100644 --- a/ui/app/os_android.c +++ b/ui/app/os_android.c @@ -77,6 +77,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserver) { .name = "onBack", .signature = "(J)Z", .fnPtr = onBack + }, + { + .name = "onFocusChange", + .signature = "(JZ)V", + .fnPtr = onFocusChange } }; if ((*env)->RegisterNatives(env, viewClass, methods, sizeof(methods)/sizeof(methods[0])) != 0) { diff --git a/ui/app/os_android.go b/ui/app/os_android.go index c86bff19..d416ad1b 100644 --- a/ui/app/os_android.go +++ b/ui/app/os_android.go @@ -191,6 +191,12 @@ func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean { return C.JNI_FALSE } +//export onFocusChange +func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) { + w := views[view] + w.event(key.Focus{Focus: focus == C.JNI_TRUE}) +} + func (w *window) setVisible() { win := w.aNativeWindow() width, height := C.ANativeWindow_getWidth(win), C.ANativeWindow_getHeight(win)