diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-01-17 17:43:49 +0200 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-02 09:44:42 -0800 |
commit | f562ecdfc3a08f7b9b0c2be938f237852a82d374 (patch) | |
tree | 71c3ceb4b2a877d124f4b069fa80156d701a6125 /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java | |
parent | 8a5bff8ee630673c6ebc496322eab94a41ae9353 (diff) | |
download | qtlocation-mapboxgl-f562ecdfc3a08f7b9b0c2be938f237852a82d374.tar.gz |
[android] data driven style implementation
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java | 137 |
1 files changed, 101 insertions, 36 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java index 82d2ecfa39..4637989dd5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import timber.log.Timber; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.functions.CompositeFunction; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.functions.SourceFunction; +import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; +import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; +import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,16 +29,14 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static com.mapbox.mapboxsdk.style.functions.Function.*; +import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; +import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for BackgroundLayer @@ -48,17 +57,16 @@ public class BackgroundLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); + mapboxMap = rule.getActivity().getMapboxMap(); + + Timber.i("Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); } @Test public void testSetVisibility() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("visibility"); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -70,13 +78,8 @@ public class BackgroundLayerTest extends BaseStyleTest { } @Test - public void testBackgroundColor() { + public void testBackgroundColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-color"); assertNotNull(layer); @@ -86,13 +89,34 @@ public class BackgroundLayerTest extends BaseStyleTest { } @Test - public void testBackgroundColorAsInt() { + public void testBackgroundColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + backgroundColor( + zoom( + exponential( + stop(2, backgroundColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundColor()); + assertNotNull(layer.getBackgroundColor().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getBackgroundColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).size()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-color"); assertNotNull(layer); @@ -102,13 +126,8 @@ public class BackgroundLayerTest extends BaseStyleTest { } @Test - public void testBackgroundPattern() { + public void testBackgroundPatternAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-pattern"); assertNotNull(layer); @@ -118,13 +137,33 @@ public class BackgroundLayerTest extends BaseStyleTest { } @Test - public void testBackgroundOpacity() { + public void testBackgroundPatternAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-pattern"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + backgroundPattern( + zoom( + interval( + stop(2, backgroundPattern("pedestrian-polygon")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundPattern()); + assertNotNull(layer.getBackgroundPattern().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundPattern().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getBackgroundPattern().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getBackgroundPattern().getFunction().getStops()).size()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-opacity"); assertNotNull(layer); @@ -133,6 +172,32 @@ public class BackgroundLayerTest extends BaseStyleTest { assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); } + @Test + public void testBackgroundOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("background-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + backgroundOpacity( + zoom( + exponential( + stop(2, backgroundOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getBackgroundOpacity()); + assertNotNull(layer.getBackgroundOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getBackgroundOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getBackgroundOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { |