ui/app: (android) relay system focus events

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-20 16:07:19 +02:00
parent a92b97e236
commit a9199c6d23
3 changed files with 18 additions and 1 deletions
+7 -1
View File
@@ -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;
+5
View File
@@ -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) {
+6
View File
@@ -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)