[android] - rework test to use query activity, fix attempt to render without surface crash

This commit is contained in:
tobrun
2019-04-11 14:50:36 +02:00
committed by Tobrun
parent 6c2948d3e6
commit 58696a0704
7 changed files with 62 additions and 20 deletions

View File

@@ -292,8 +292,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
@Override
protected void onSurfaceDestroyed() {
MapView.this.onSurfaceDestroyed();
super.onSurfaceDestroyed();
MapView.this.onSurfaceDestroyed();
}
};
@@ -310,8 +310,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
@Override
protected void onSurfaceDestroyed() {
MapView.this.onSurfaceDestroyed();
super.onSurfaceDestroyed();
MapView.this.onSurfaceDestroyed();
}
};
@@ -442,7 +442,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
mapboxMap.onDestroy();
}
if (nativeMapView != null && nativeMapView.hasSurface()) {
if (nativeMapView != null) {
// null when destroying an activity programmatically mapbox-navigation-android/issues/503
nativeMapView.destroy();
nativeMapView = null;
@@ -762,7 +762,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
/**
* /**
*
* Set a callback that's invoked when the style has finished loading.
*
* @param listener The callback that's invoked when the style has finished loading

View File

@@ -4,7 +4,6 @@ import android.content.Context;
import android.support.annotation.CallSuper;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.LibraryLoader;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.MapboxMap;

View File

@@ -22,6 +22,7 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
@NonNull
private final GLSurfaceView glSurfaceView;
private boolean hasSurface;
public GLSurfaceViewMapRenderer(Context context,
GLSurfaceView glSurfaceView,
@@ -33,11 +34,18 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
glSurfaceView.setRenderer(this);
glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
glSurfaceView.setPreserveEGLContextOnPause(true);
glSurfaceView.getHolder().addCallback(new SurfaceHolderCallbackAdapter() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
hasSurface = true;
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
super.surfaceDestroyed(holder);
hasSurface = false;
onSurfaceDestroyed();
}
});
@@ -73,6 +81,11 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
super.onSurfaceCreated(gl, config);
}
@Override
protected void onSurfaceDestroyed() {
super.onSurfaceDestroyed();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
super.onSurfaceChanged(gl, width, height);
@@ -90,6 +103,9 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
*/
@Override
public void requestRender() {
if (!hasSurface) {
return;
}
glSurfaceView.requestRender();
}