app: [Android] implement key release events

Not terribly useful on Android, but easy to do.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-01-20 14:21:44 +01:00
parent 8c2d9a9a57
commit 30daaef4ab
2 changed files with 16 additions and 5 deletions
+9 -2
View File
@@ -121,7 +121,14 @@ public final class GioView extends SurfaceView {
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if (nhandle != 0) { if (nhandle != 0) {
onKeyEvent(nhandle, keyCode, event.getUnicodeChar(), event.getEventTime()); onKeyEvent(nhandle, keyCode, event.getUnicodeChar(), true, event.getEventTime());
}
return false;
}
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
if (nhandle != 0) {
onKeyEvent(nhandle, keyCode, event.getUnicodeChar(), false, event.getEventTime());
} }
return false; return false;
} }
@@ -415,7 +422,7 @@ public final class GioView extends SurfaceView {
static private native void onWindowInsets(long handle, int top, int right, int bottom, int left); static private native void onWindowInsets(long handle, int top, int right, int bottom, int left);
static public native void onLowMemory(); static public native void onLowMemory();
static private native void onTouchEvent(long handle, int action, int pointerID, int tool, float x, float y, float scrollX, float scrollY, int buttons, long time); static private native void onTouchEvent(long handle, int action, int pointerID, int tool, float x, float y, float scrollX, float scrollY, int buttons, long time);
static private native void onKeyEvent(long handle, int code, int character, long time); static private native void onKeyEvent(long handle, int code, int character, boolean pressed, long time);
static private native void onFrameCallback(long handle); static private native void onFrameCallback(long handle);
static private native boolean onBack(long handle); static private native boolean onBack(long handle);
static private native void onFocusChange(long handle, boolean focus); static private native void onFocusChange(long handle, boolean focus);
+7 -3
View File
@@ -920,12 +920,16 @@ func convertKeyCode(code C.jint) (string, bool) {
} }
//export Java_org_gioui_GioView_onKeyEvent //export Java_org_gioui_GioView_onKeyEvent
func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, t C.jlong) { func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, pressed C.jboolean, t C.jlong) {
w := views[handle] w := views[handle]
if n, ok := convertKeyCode(keyCode); ok { if n, ok := convertKeyCode(keyCode); ok {
w.callbacks.Event(key.Event{Name: n}) state := key.Release
if pressed == C.JNI_TRUE {
state = key.Press
}
w.callbacks.Event(key.Event{Name: n, State: state})
} }
if r != 0 && r != '\n' { // Checking for "\n" to prevent duplication with key.NameEnter (gio#224). if pressed == C.JNI_TRUE && r != 0 && r != '\n' { // Checking for "\n" to prevent duplication with key.NameEnter (gio#224).
w.callbacks.Event(key.EditEvent{Text: string(rune(r))}) w.callbacks.Event(key.EditEvent{Text: string(rune(r))})
} }
} }