summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-07-12 08:56:21 +0200
committerTobrun <tobrun@mapbox.com>2018-07-12 10:46:57 +0200
commite16c96446584f8ee36da4722eb86f40b9cbe5659 (patch)
tree4d5ce0f5f2e17e83becbd75be38884a658ed8167
parentb79b971f56738753e79a5352a7b5d6bb8a889b22 (diff)
downloadqtlocation-mapboxgl-e16c96446584f8ee36da4722eb86f40b9cbe5659.tar.gz
[android] - add convenience method for destroyed state on MapView, can be used to determine if an asynchrous result should be set on map.
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java13
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java8
3 files changed, 19 insertions, 4 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 57f8c61f7e..0fa1072cd2 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
@@ -425,6 +425,19 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
}
+ /**
+ * Returns if the map has been destroyed.
+ * <p>
+ * This method can be used to determine if the result of an asynchronous operation should be set.
+ * </p>
+ *
+ * @return true, if the map has been destroyed
+ */
+ @UiThread
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isMapInitialized() || !isZoomButtonControllerInitialized() || !isGestureDetectorInitialized()) {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
index afeb3b8979..92c5949ec1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java
@@ -92,7 +92,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
}
private void showMarkers(int amount) {
- if (mapboxMap == null || locations == null) {
+ if (mapboxMap == null || locations == null || mapView.isDestroyed()) {
return;
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
index f32aa5faf8..3a11a7e020 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
@@ -14,7 +14,6 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
-
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -26,14 +25,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
+import timber.log.Timber;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;
-import timber.log.Timber;
-
import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
import static com.mapbox.mapboxsdk.style.expressions.Expression.division;
import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase;
@@ -240,6 +238,10 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
}
public void onDataLoaded(@NonNull FeatureCollection featureCollection) {
+ if (mapView.isDestroyed()) {
+ return;
+ }
+
// create expressions
Expression iconImageExpression = string(get(literal(FEATURE_ID)));
Expression iconSizeExpression = division(number(get(literal(FEATURE_RANK))), literal(2.0f));