mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
ui/app: (android) relay system focus events
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-1
@@ -32,10 +32,16 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
|||||||
|
|
||||||
public GioView(Context context, AttributeSet attrs) {
|
public GioView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
nhandle = onCreateView(this);
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setFocusableInTouchMode(true);
|
setFocusableInTouchMode(true);
|
||||||
|
setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
|
@Override public void onFocusChange(View v, boolean focus) {
|
||||||
|
GioView.this.onFocusChange(nhandle, focus);
|
||||||
|
}
|
||||||
|
});
|
||||||
callbacks = new SurfaceHolder.Callback() {
|
callbacks = new SurfaceHolder.Callback() {
|
||||||
@Override public void surfaceCreated(SurfaceHolder holder) {
|
@Override public void surfaceCreated(SurfaceHolder holder) {
|
||||||
// Ignore; surfaceChanged is guaranteed to be called immediately after this.
|
// 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);
|
getHolder().addCallback(callbacks);
|
||||||
nhandle = onCreateView(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
|
@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 onKeyEvent(long handle, int code, int character, long time);
|
||||||
static private native void onFrameCallback(long handle, long nanos);
|
static private native void onFrameCallback(long handle, long nanos);
|
||||||
static private native boolean onBack(long handle);
|
static private native boolean onBack(long handle);
|
||||||
|
static private native void onFocusChange(long handle, boolean focus);
|
||||||
|
|
||||||
private static class InputConnection extends BaseInputConnection {
|
private static class InputConnection extends BaseInputConnection {
|
||||||
private final Editable editable;
|
private final Editable editable;
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserver) {
|
|||||||
.name = "onBack",
|
.name = "onBack",
|
||||||
.signature = "(J)Z",
|
.signature = "(J)Z",
|
||||||
.fnPtr = onBack
|
.fnPtr = onBack
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "onFocusChange",
|
||||||
|
.signature = "(JZ)V",
|
||||||
|
.fnPtr = onFocusChange
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if ((*env)->RegisterNatives(env, viewClass, methods, sizeof(methods)/sizeof(methods[0])) != 0) {
|
if ((*env)->RegisterNatives(env, viewClass, methods, sizeof(methods)/sizeof(methods[0])) != 0) {
|
||||||
|
|||||||
@@ -191,6 +191,12 @@ func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
|||||||
return C.JNI_FALSE
|
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() {
|
func (w *window) setVisible() {
|
||||||
win := w.aNativeWindow()
|
win := w.aNativeWindow()
|
||||||
width, height := C.ANativeWindow_getWidth(win), C.ANativeWindow_getHeight(win)
|
width, height := C.ANativeWindow_getWidth(win), C.ANativeWindow_getHeight(win)
|
||||||
|
|||||||
Reference in New Issue
Block a user