summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-11-02 13:04:23 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-11-02 20:09:49 +0100
commita282b195d54918a7107444303a515448f7ed7614 (patch)
treeea4c78c95456ca09ed843229beadddb292284f43
parent3b9618e0253c28b280bdbf9d7bd064a909c8c86b (diff)
downloadqtlocation-mapboxgl-a282b195d54918a7107444303a515448f7ed7614.tar.gz
[android] deliver onMapReady only if mapboxMap is not null
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java16
3 files changed, 20 insertions, 10 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 3b1352e153..3d56e134f6 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
@@ -951,7 +951,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
*/
@UiThread
public void getMapAsync(final @NonNull OnMapReadyCallback callback) {
- if (mapCallback.isInitialLoad()) {
+ if (mapCallback.isInitialLoad() || mapboxMap == null) {
+ // Add callback to the list only if the style hasn't loaded, or the drawing surface isn't ready
mapCallback.addOnMapReadyCallback(callback);
} else {
callback.onMapReady(mapboxMap);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
index b1bcead8b9..a0168cc63d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
@@ -6,17 +6,21 @@ import android.support.test.espresso.IdlingRegistry;
import android.support.test.espresso.IdlingResourceTimeoutException;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
+
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.action.WaitAction;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
+
import junit.framework.Assert;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
+
import timber.log.Timber;
import static android.support.test.espresso.Espresso.onView;
@@ -38,7 +42,12 @@ public abstract class BaseActivityTest {
@Before
public void beforeTest() {
try {
- Timber.e(String.format("%s - %s", testNameRule.getMethodName(), "@Before test: register idle resource"));
+ Timber.e(String.format(
+ "%s - %s - %s",
+ getClass().getSimpleName(),
+ testNameRule.getMethodName(),
+ "@Before test: register idle resource"
+ ));
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
IdlingRegistry.getInstance().register(idlingResource);
Espresso.onIdle();
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
index 16959ed5b5..312350f28c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
@@ -11,21 +11,20 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
+import junit.framework.Assert;
+
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
private MapboxMap mapboxMap;
private IdlingResource.ResourceCallback resourceCallback;
- private final Handler handler = new Handler(Looper.getMainLooper());
@WorkerThread
public OnMapReadyIdlingResource(final Activity activity) {
- handler.post(new Runnable() {
- @Override
- public void run() {
- MapView mapView = (MapView) activity.findViewById(R.id.mapView);
- if (mapView != null) {
- mapView.getMapAsync(OnMapReadyIdlingResource.this);
- }
+ Handler handler = new Handler(Looper.getMainLooper());
+ handler.post(() -> {
+ MapView mapView = activity.findViewById(R.id.mapView);
+ if (mapView != null) {
+ mapView.getMapAsync(OnMapReadyIdlingResource.this);
}
});
}
@@ -51,6 +50,7 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
@Override
public void onMapReady(MapboxMap mapboxMap) {
+ Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
this.mapboxMap = mapboxMap;
if (resourceCallback != null) {
resourceCallback.onTransitionToIdle();