diff --git a/ui/app/GioActivity.java b/ui/app/GioActivity.java index 537a693f..1b97c51d 100644 --- a/ui/app/GioActivity.java +++ b/ui/app/GioActivity.java @@ -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); } diff --git a/ui/app/GioView.java b/ui/app/GioView.java index bbaf7124..2b24264d 100644 --- a/ui/app/GioView.java +++ b/ui/app/GioView.java @@ -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); diff --git a/ui/app/app.go b/ui/app/app.go index 5051cb7c..fcbed16a 100644 --- a/ui/app/app.go +++ b/ui/app/app.go @@ -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. diff --git a/ui/app/datadir_android.go b/ui/app/datadir_android.go index e4a02891..ad206637 100644 --- a/ui/app/datadir_android.go +++ b/ui/app/datadir_android.go @@ -15,4 +15,3 @@ func setDataDir(cdir *C.char) { return dir, nil } } - diff --git a/ui/app/os_android.c b/ui/app/os_android.c index 7aafb106..1ab1f7ce 100644 --- a/ui/app/os_android.c +++ b/ui/app/os_android.c @@ -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", diff --git a/ui/app/os_android.go b/ui/app/os_android.go index e358f6ee..4fb9a35e 100644 --- a/ui/app/os_android.go +++ b/ui/app/os_android.go @@ -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,