app: [Android] detach previous View when another is created

The Android system can in some cases replace the GioView of our Android
Activity before destroying the previous one. This change makes sure the
previous view is ignored, in particular its destroy event.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-29 18:58:53 +02:00
parent b86928ceec
commit 07e1df3676
2 changed files with 45 additions and 12 deletions
+30 -7
View File
@@ -113,7 +113,9 @@ public final class GioView extends SurfaceView {
}
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
onKeyEvent(nhandle, keyCode, event.getUnicodeChar(), event.getEventTime());
if (nhandle != 0) {
onKeyEvent(nhandle, keyCode, event.getUnicodeChar(), event.getEventTime());
}
return false;
}
@@ -229,6 +231,9 @@ public final class GioView extends SurfaceView {
}
private void dispatchMotionEvent(MotionEvent event) {
if (nhandle == 0) {
return;
}
for (int j = 0; j < event.getHistorySize(); j++) {
long time = event.getHistoricalEventTime(j);
for (int i = 0; i < event.getPointerCount(); i++) {
@@ -289,12 +294,16 @@ public final class GioView extends SurfaceView {
}
@Override protected boolean fitSystemWindows(Rect insets) {
onWindowInsets(nhandle, insets.top, insets.right, insets.bottom, insets.left);
if (nhandle != 0) {
onWindowInsets(nhandle, insets.top, insets.right, insets.bottom, insets.left);
}
return true;
}
@Override protected void onDraw(Canvas canvas) {
onFrameCallback(nhandle);
if (nhandle != 0) {
onFrameCallback(nhandle);
}
}
int getDensity() {
@@ -306,25 +315,39 @@ public final class GioView extends SurfaceView {
}
public void start() {
onStartView(nhandle);
if (nhandle != 0) {
onStartView(nhandle);
}
}
public void stop() {
onStopView(nhandle);
if (nhandle != 0) {
onStopView(nhandle);
}
}
public void destroy() {
if (nhandle != 0) {
onDestroyView(nhandle);
}
}
protected void unregister() {
setOnFocusChangeListener(null);
getHolder().removeCallback(surfCallbacks);
onDestroyView(nhandle);
nhandle = 0;
}
public void configurationChanged() {
onConfigurationChanged(nhandle);
if (nhandle != 0) {
onConfigurationChanged(nhandle);
}
}
public boolean backPressed() {
if (nhandle == 0) {
return false;
}
return onBack(nhandle);
}