summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-04-11 14:50:36 +0200
committerTobrun <tobrun.van.nuland@gmail.com>2019-04-12 13:12:31 +0200
commit58696a0704503837014bf6612eba6d537075c15e (patch)
treea5f423e3403d2378e72547ba579a7741f5b3afc4 /platform
parent6c2948d3e68e25deea658d02190039db14a67723 (diff)
downloadqtlocation-mapboxgl-58696a0704503837014bf6612eba6d537075c15e.tar.gz
[android] - rework test to use query activity, fix attempt to render without surface crash
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java8
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java18
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/QueryRenderedFeaturesBoxCountTest.kt30
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java6
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java16
7 files changed, 62 insertions, 20 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index b671d1e4db..102c221e0a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -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
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index e1f929c0f1..094129ed5c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -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;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
index 524c1a62ee..47cb35edbc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
@@ -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();
}
});
@@ -74,6 +82,11 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
}
@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();
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/QueryRenderedFeaturesBoxCountTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/QueryRenderedFeaturesBoxCountTest.kt
new file mode 100644
index 0000000000..076bcba7e6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/QueryRenderedFeaturesBoxCountTest.kt
@@ -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()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index 017fe3ddca..0c5aa1551e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -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" />
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java
index 35ed45442c..9031240443 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java
@@ -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
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
index 8d82dbf6cf..7d2d245f6e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
@@ -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