[android] - harden query invocations, move hasSurface handling to NativeMapView
This commit is contained in:
@@ -19,7 +19,6 @@ import android.view.TextureView;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.android.gestures.AndroidGesturesManager;
|
||||
import com.mapbox.mapboxsdk.MapStrictMode;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
@@ -36,13 +35,12 @@ import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
|
||||
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
|
||||
|
||||
@@ -74,7 +72,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
private MapboxMapOptions mapboxMapOptions;
|
||||
private MapRenderer mapRenderer;
|
||||
private boolean destroyed;
|
||||
private boolean hasSurface;
|
||||
|
||||
private CompassView compassView;
|
||||
private PointF focalPoint;
|
||||
@@ -292,6 +289,12 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
MapView.this.onSurfaceCreated();
|
||||
super.onSurfaceCreated(gl, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSurfaceDestroyed() {
|
||||
MapView.this.onSurfaceDestroyed();
|
||||
super.onSurfaceDestroyed();
|
||||
}
|
||||
};
|
||||
|
||||
addView(textureView, 0);
|
||||
@@ -304,6 +307,12 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
MapView.this.onSurfaceCreated();
|
||||
super.onSurfaceCreated(gl, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSurfaceDestroyed() {
|
||||
MapView.this.onSurfaceDestroyed();
|
||||
super.onSurfaceDestroyed();
|
||||
}
|
||||
};
|
||||
|
||||
addView(glSurfaceView, 0);
|
||||
@@ -316,7 +325,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
private void onSurfaceCreated() {
|
||||
hasSurface = true;
|
||||
nativeMapView.setHasSurface(true);
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -329,6 +338,12 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
});
|
||||
}
|
||||
|
||||
private void onSurfaceDestroyed() {
|
||||
if (nativeMapView != null) {
|
||||
nativeMapView.setHasSurface(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's Activity#onSaveInstanceState(Bundle)
|
||||
* or Fragment#onSaveInstanceState(Bundle).
|
||||
@@ -427,7 +442,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
mapboxMap.onDestroy();
|
||||
}
|
||||
|
||||
if (nativeMapView != null && hasSurface) {
|
||||
if (nativeMapView != null && nativeMapView.hasSurface()) {
|
||||
// null when destroying an activity programmatically mapbox-navigation-android/issues/503
|
||||
nativeMapView.destroy();
|
||||
nativeMapView = null;
|
||||
@@ -439,10 +454,10 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum frame rate at which the map view is rendered,
|
||||
* but it can't excess the ability of device hardware.
|
||||
* The maximum frame rate at which the map view is rendered,
|
||||
* but it can't excess the ability of device hardware.
|
||||
*
|
||||
* @param maximumFps Can be set to arbitrary integer values.
|
||||
* @param maximumFps Can be set to arbitrary integer values.
|
||||
*/
|
||||
public void setMaximumFps(int maximumFps) {
|
||||
if (mapRenderer != null) {
|
||||
@@ -747,8 +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
|
||||
|
||||
@@ -37,6 +37,10 @@ interface NativeMap {
|
||||
|
||||
boolean isDestroyed();
|
||||
|
||||
boolean hasSurface();
|
||||
|
||||
void setHasSurface(boolean hasSurface);
|
||||
|
||||
//
|
||||
// Camera API
|
||||
//
|
||||
|
||||
@@ -65,9 +65,12 @@ final class NativeMapView implements NativeMap {
|
||||
// Device density
|
||||
private final float pixelRatio;
|
||||
|
||||
// Flag to indicating destroy was called
|
||||
// Flag to indicate destroy was called
|
||||
private boolean destroyed = false;
|
||||
|
||||
// Flag to indicate surface was destroyed
|
||||
private boolean hasSurface = false;
|
||||
|
||||
// Holds the pointer to JNI NativeMapView
|
||||
@Keep
|
||||
private long nativePtr = 0;
|
||||
@@ -890,7 +893,7 @@ final class NativeMapView implements NativeMap {
|
||||
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter) {
|
||||
if (checkState("queryRenderedFeatures")) {
|
||||
if (checkState("queryRenderedFeatures") || !hasSurface) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Feature[] features = nativeQueryRenderedFeaturesForPoint(coordinates.x / pixelRatio,
|
||||
@@ -903,7 +906,7 @@ final class NativeMapView implements NativeMap {
|
||||
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter) {
|
||||
if (checkState("queryRenderedFeatures")) {
|
||||
if (checkState("queryRenderedFeatures") || !hasSurface) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Feature[] features = nativeQueryRenderedFeaturesForBox(
|
||||
@@ -1418,6 +1421,16 @@ final class NativeMapView implements NativeMap {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSurface() {
|
||||
return hasSurface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHasSurface(boolean hasSurface) {
|
||||
this.hasSurface = hasSurface;
|
||||
}
|
||||
|
||||
public interface ViewCallback {
|
||||
int getWidth();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user