mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
ui/app: introduce DrawEvent.Insets and add Android implementation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -15,12 +16,13 @@ public class GioActivity extends Activity {
|
||||
@Override public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
Window w = getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Window w = getWindow();
|
||||
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
this.view = new GioView(this);
|
||||
this.view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
|
||||
setContentView(view);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package org.gioui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
@@ -12,6 +13,7 @@ import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.SurfaceHolder;
|
||||
@@ -157,6 +159,11 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
});
|
||||
}
|
||||
|
||||
@Override protected boolean fitSystemWindows(Rect insets) {
|
||||
onWindowInsets(nhandle, insets.top, insets.right, insets.bottom, insets.left);
|
||||
return true;
|
||||
}
|
||||
|
||||
void postFrameCallback() {
|
||||
Choreographer.getInstance().removeFrameCallback(this);
|
||||
Choreographer.getInstance().postFrameCallback(this);
|
||||
@@ -207,6 +214,7 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
static private native void onSurfaceDestroyed(long handle);
|
||||
static private native void onSurfaceChanged(long handle, Surface surface);
|
||||
static private native void onConfigurationChanged(long handle);
|
||||
static private native void onWindowInsets(long handle, int top, int right, int bottom, int left);
|
||||
static private native void onLowMemory();
|
||||
static private native void onTouchEvent(long handle, int action, int pointerID, int tool, float x, float y, long time);
|
||||
static private native void onKeyEvent(long handle, int code, int character, long time);
|
||||
|
||||
@@ -17,6 +17,10 @@ type Event interface {
|
||||
type DrawEvent struct {
|
||||
Config ui.Config
|
||||
Size image.Point
|
||||
// Insets is the window space taken up by
|
||||
// system decoration such as translucent
|
||||
// system bars and software keyboards.
|
||||
Insets image.Rectangle
|
||||
// Whether this draw is system generated
|
||||
// and needs a complete frame before
|
||||
// proceeding.
|
||||
|
||||
@@ -15,4 +15,3 @@ func setDataDir(cdir *C.char) {
|
||||
return dir, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
.signature = "(J)V",
|
||||
.fnPtr = onConfigurationChanged
|
||||
},
|
||||
{
|
||||
.name = "onWindowInsets",
|
||||
.signature = "(JIIII)V",
|
||||
.fnPtr = onWindowInsets
|
||||
},
|
||||
{
|
||||
.name = "onLowMemory",
|
||||
.signature = "()V",
|
||||
|
||||
@@ -37,6 +37,7 @@ type window struct {
|
||||
|
||||
dpi int
|
||||
fontScale float32
|
||||
insets image.Rectangle
|
||||
|
||||
stage Stage
|
||||
started bool
|
||||
@@ -197,6 +198,18 @@ func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean
|
||||
w.event(key.FocusEvent{Focus: focus == C.JNI_TRUE})
|
||||
}
|
||||
|
||||
//export onWindowInsets
|
||||
func onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
|
||||
w := views[view]
|
||||
w.insets = image.Rectangle{
|
||||
Min: image.Point{X: int(left), Y: int(top)},
|
||||
Max: image.Point{X: int(right), Y: int(bottom)},
|
||||
}
|
||||
if w.stage >= StageRunning {
|
||||
w.draw(true)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *window) setVisible() {
|
||||
win := w.aNativeWindow()
|
||||
width, height := C.ANativeWindow_getWidth(win), C.ANativeWindow_getHeight(win)
|
||||
@@ -275,6 +288,7 @@ func (w *window) draw(sync bool) {
|
||||
X: int(width),
|
||||
Y: int(height),
|
||||
},
|
||||
Insets: w.insets,
|
||||
Config: ui.Config{
|
||||
PxPerDp: ppdp,
|
||||
PxPerSp: w.fontScale * ppdp,
|
||||
|
||||
Reference in New Issue
Block a user