From 7aaf492ef2147afc3efcc081b21df343a6f2cb77 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 25 May 2018 11:46:04 +0200 Subject: UI thread checking (#12000) * [android] - add UI thread checking --- .../java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java index 38d5277a80..641c283798 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java @@ -16,7 +16,6 @@ import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.attribution.AttributionLayout; import com.mapbox.mapboxsdk.attribution.AttributionMeasure; @@ -25,7 +24,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.storage.FileSource; - +import com.mapbox.mapboxsdk.utils.ThreadUtils; import timber.log.Timber; /** @@ -213,6 +212,7 @@ public class MapSnapshotter { * @param options the options to use for the snapshot */ public MapSnapshotter(@NonNull Context context, @NonNull Options options) { + checkThread(); this.context = context.getApplicationContext(); FileSource fileSource = FileSource.getInstance(context); String programCacheDir = context.getCacheDir().getAbsolutePath(); @@ -243,7 +243,7 @@ public class MapSnapshotter { if (this.callback != null) { throw new IllegalStateException("Snapshotter was already started"); } - + checkThread(); this.callback = callback; this.errorHandler = errorHandler; nativeStart(); @@ -284,6 +284,7 @@ public class MapSnapshotter { * the object was created on. */ public void cancel() { + checkThread(); reset(); nativeCancel(); } @@ -465,6 +466,10 @@ public class MapSnapshotter { } } + private void checkThread() { + ThreadUtils.checkThread("MapSnapshotter"); + } + protected void reset() { callback = null; errorHandler = null; -- cgit v1.2.1