summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-12-10 12:02:54 +0100
committerTobrun <tobrun@mapbox.com>2018-12-10 16:59:50 +0100
commita018c0f7b59a77d222b366bf6804924f51f46dc6 (patch)
tree94648436dffa1be63c5c7c0a5ab504b12791f6ff
parentaa9e6c59bb04f49360d5e7f0e19884206deb20ff (diff)
downloadqtlocation-mapboxgl-a018c0f7b59a77d222b366bf6804924f51f46dc6.tar.gz
[android] - throw exception when another style is loading, correct RuntimeStyleTest when removing layer at, add javadoc to isFullyLoaded
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java46
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java2
3 files changed, 32 insertions, 18 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
index 59ce2a900e..340e84abef 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
@@ -916,7 +916,7 @@ public final class LocationComponent {
}
if (!style.isFullyLoaded()) {
- throw new IllegalStateException("Style hasn't fully loaded yet, can't initialize LocationComponent.");
+ throw new IllegalStateException("Style is invalid, provide the most recently loaded one.");
}
this.style = style;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
index c803042242..94b5b73378 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
@@ -103,8 +103,9 @@ public class Style {
*/
public void addSource(@NonNull Source source) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addSource on old Style instance, use the more recently loaded Style instead."
+ );
}
sources.put(source.getId(), source);
@@ -195,8 +196,9 @@ public class Style {
*/
public void addLayer(@NonNull Layer layer) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addLayer on old Style instance, use the more recently loaded Style instead."
+ );
}
layers.put(layer.getId(), layer);
@@ -211,8 +213,9 @@ public class Style {
*/
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addLayerBelow on old Style instance, use the more recently loaded Style instead."
+ );
}
layers.put(layer.getId(), layer);
@@ -227,8 +230,9 @@ public class Style {
*/
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addLayerAbove on old Style instance, use the more recently loaded Style instead."
+ );
}
layers.put(layer.getId(), layer);
@@ -244,8 +248,9 @@ public class Style {
*/
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addLayerAt on old Style instance, use the more recently loaded Style instead."
+ );
}
layers.put(layer.getId(), layer);
@@ -368,8 +373,9 @@ public class Style {
*/
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addImage on old Style instance, use the more recently loaded Style instead."
+ );
}
nativeMapView.addImage(name, image, sdf);
@@ -380,8 +386,9 @@ public class Style {
*/
public void addImages(@NonNull HashMap<String, Bitmap> images) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling addImages on old Style instance, use the more recently loaded Style instead."
+ );
}
nativeMapView.addImages(images);
@@ -431,8 +438,9 @@ public class Style {
*/
public void setTransition(@NonNull TransitionOptions transitionOptions) {
if (!fullyLoaded) {
- // we are loading a new style
- return;
+ throw new IllegalStateException(
+ "Calling setTransition on old Style instance, use the more recently loaded Style instead."
+ );
}
nativeMapView.setTransitionDuration(transitionOptions.getDuration());
@@ -541,6 +549,12 @@ public class Style {
}
}
+ /**
+ * Returns true if the style is fully loaded. Returns false if style hasn't been fully loaded or a new style is
+ * underway of being loaded.
+ *
+ * @return True if fully loaded, false otherwise
+ */
public boolean isFullyLoaded() {
return fullyLoaded;
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
index 141ddb42da..e7e7c767a4 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
@@ -133,7 +133,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
// Test remove by index bounds checks
Timber.i("Remove layer at index > size");
- assertNull(mapboxMap.getStyle().removeLayerAt(Integer.MAX_VALUE));
+ assertFalse(mapboxMap.getStyle().removeLayerAt(Integer.MAX_VALUE));
}
});
}