From 9ad492e93b0b427d289d8aeacc18d43cf1dff822 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 19 May 2021 15:06:12 +0200 Subject: [PATCH] app/internal/wm: [Android] make GioView delegate methods public GioActivity is final to avoid the brittle base class problem. However, to permit replacement of GioActivity the GioView delegate methods must be public. While here fix a function signature, rename lowMemory to onLowMemory and make it static. Also move view specific setup to GioView, simplifying the host activity further. Signed-off-by: Elias Naur --- app/internal/wm/GioActivity.java | 15 +++------------ app/internal/wm/GioView.java | 21 +++++++++++---------- app/internal/wm/os_android.go | 2 +- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/internal/wm/GioActivity.java b/app/internal/wm/GioActivity.java index 260d4b69..4565e380 100644 --- a/app/internal/wm/GioActivity.java +++ b/app/internal/wm/GioActivity.java @@ -3,12 +3,8 @@ package org.gioui; 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; +import android.content.res.Configuration; public final class GioActivity extends Activity { private GioView view; @@ -16,13 +12,8 @@ public final class GioActivity extends Activity { @Override public void onCreate(Bundle state) { super.onCreate(state); - Window w = getWindow(); - this.view = new GioView(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - this.view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); - } - this.view.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); + setContentView(view); } @@ -48,7 +39,7 @@ public final class GioActivity extends Activity { @Override public void onLowMemory() { super.onLowMemory(); - view.lowMemory(); + GioView.onLowMemory(); } @Override public void onBackPressed() { diff --git a/app/internal/wm/GioView.java b/app/internal/wm/GioView.java index 4dc842e4..42e5c531 100644 --- a/app/internal/wm/GioView.java +++ b/app/internal/wm/GioView.java @@ -31,6 +31,7 @@ import android.view.SurfaceView; import android.view.SurfaceHolder; import android.view.Window; import android.view.WindowInsetsController; +import android.view.WindowManager; import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; @@ -55,6 +56,10 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal public GioView(Context context, AttributeSet attrs) { super(context, attrs); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + } + setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); // Late initialization of the Go runtime to wait for a valid context. Gio.init(context.getApplicationContext()); @@ -277,30 +282,26 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal return getResources().getConfiguration().fontScale; } - void start() { + public void start() { onStartView(nhandle); } - void stop() { + public void stop() { onStopView(nhandle); } - void destroy() { + public void destroy() { setOnFocusChangeListener(null); getHolder().removeCallback(surfCallbacks); onDestroyView(nhandle); nhandle = 0; } - void configurationChanged() { + public void configurationChanged() { onConfigurationChanged(nhandle); } - void lowMemory() { - onLowMemory(); - } - - boolean backPressed() { + public boolean backPressed() { return onBack(nhandle); } @@ -312,7 +313,7 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal 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 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 onKeyEvent(long handle, int code, int character, long time); static private native void onFrameCallback(long handle, long nanos); diff --git a/app/internal/wm/os_android.go b/app/internal/wm/os_android.go index 080f67b2..b3e2d57a 100644 --- a/app/internal/wm/os_android.go +++ b/app/internal/wm/os_android.go @@ -283,7 +283,7 @@ func Java_org_gioui_GioView_onSurfaceChanged(env *C.JNIEnv, class C.jclass, hand } //export Java_org_gioui_GioView_onLowMemory -func Java_org_gioui_GioView_onLowMemory() { +func Java_org_gioui_GioView_onLowMemory(env *C.JNIEnv, class C.jclass) { runtime.GC() debug.FreeOSMemory() }