[android] - rework test to use query activity, fix attempt to render without surface crash
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mapbox.mapboxsdk.integration
|
||||
|
||||
import android.support.test.filters.LargeTest
|
||||
import android.support.test.rule.ActivityTestRule
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import com.mapbox.mapboxsdk.testapp.activity.feature.QueryRenderedFeaturesBoxCountActivity
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Regression test that validates reopening an Activity and querying the map before surface recreation #14394
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class QueryRenderedFeaturesBoxCountTest : BaseIntegrationTest() {
|
||||
|
||||
@get:Rule
|
||||
var activityRule: ActivityTestRule<QueryRenderedFeaturesBoxCountActivity> =
|
||||
ActivityTestRule(QueryRenderedFeaturesBoxCountActivity::class.java)
|
||||
|
||||
@Test
|
||||
@LargeTest
|
||||
fun reopenQueryRendererFeaturesActivity() {
|
||||
device.waitForIdle()
|
||||
device.pressHome()
|
||||
device.waitForIdle()
|
||||
device.launchActivity(activityRule.activity, QueryRenderedFeaturesBoxCountActivity::class.java)
|
||||
device.waitForIdle()
|
||||
}
|
||||
}
|
||||
@@ -608,7 +608,8 @@
|
||||
<activity
|
||||
android:name=".activity.feature.QueryRenderedFeaturesBoxCountActivity"
|
||||
android:description="@string/description_query_rendered_features_box_count"
|
||||
android:label="@string/activity_query_rendered_features_box_count">
|
||||
android:label="@string/activity_query_rendered_features_box_count"
|
||||
android:launchMode="singleInstance">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_features" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
@@ -89,6 +90,11 @@ public class QueryRenderedFeaturesBoxCountActivity extends AppCompatActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
|
||||
if (mapboxMap != null) {
|
||||
// Regression test for #14394
|
||||
mapboxMap.queryRenderedFeatures(new PointF(0,0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
@@ -14,7 +12,6 @@ import com.mapbox.mapboxsdk.testapp.R;
|
||||
public class SimpleMapActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -22,22 +19,15 @@ public class SimpleMapActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_map_simple);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
);
|
||||
});
|
||||
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
if (mapboxMap != null) {
|
||||
// Regression test for #14394
|
||||
mapboxMap.queryRenderedFeatures(new PointF(0,0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user