diff --git a/app/build.gradle b/app/build.gradle index 90fee0c93..0500c99d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,6 +14,8 @@ android { buildTypes { debug { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' testCoverageEnabled true } release { diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java index 76afe38d8..9e3a79431 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java @@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.mapboxsdk.plugins.testapp.activity.location.LocationLayerModesActivity; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; @@ -38,7 +39,6 @@ import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.FOREGROUND_LAYER; import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.FOREGROUND_STALE_ICON; import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.LOCATION_SOURCE; -import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.NAVIGATION_LAYER; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; @@ -91,7 +91,7 @@ public void locationSourceAdded() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); assertTrue(mapboxMap.getSource(LOCATION_SOURCE) != null); } }); @@ -103,7 +103,7 @@ public void locationTrackingLayersAdded() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); assertTrue(mapboxMap.getLayer(ACCURACY_LAYER) != null); assertTrue(mapboxMap.getLayer(BACKGROUND_LAYER) != null); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); @@ -117,7 +117,7 @@ public void locationBearingLayersAdded() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); + locationLayerPlugin.setRenderMode(RenderMode.COMPASS); assertTrue(mapboxMap.getLayer(ACCURACY_LAYER) != null); assertTrue(mapboxMap.getLayer(BACKGROUND_LAYER) != null); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); @@ -132,8 +132,8 @@ public void locationNavigationLayersAdded() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); - assertTrue(mapboxMap.getLayer(NAVIGATION_LAYER) != null); + locationLayerPlugin.setRenderMode(RenderMode.COMPASS); + assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); } }); } @@ -144,9 +144,9 @@ public void locationLayerModeCorrectlySetToNone() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE); + locationLayerPlugin.setLocationLayerEnabled(false); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER).getVisibility().getValue() .equals(Property.NONE)); } @@ -159,11 +159,11 @@ public void onMapChangeLocationLayerRedrawn() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); mapboxMap.setStyleUrl(Style.SATELLITE); uiController.loopMainThreadForAtLeast(500); - assertEquals(locationLayerPlugin.getLocationLayerMode(), LocationLayerMode.TRACKING); + assertEquals(locationLayerPlugin.getRenderMode(), RenderMode.NORMAL); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null); assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER).getVisibility().getValue() .equals(Property.VISIBLE)); @@ -181,11 +181,11 @@ public void whenStaleTimeSet_iconsDoChangeAtAppropriateTime() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); SymbolLayer symbolLayer = mapboxMap.getLayerAs(FOREGROUND_LAYER); assert symbolLayer != null; assertThat(symbolLayer.getIconImage().getValue(), equalTo(FOREGROUND_ICON)); - locationLayerPlugin.applyStyle(LocationLayerOptions.builder(context).staleStateDelay(400).build()); + locationLayerPlugin.applyStyle(LocationLayerOptions.builder(context).staleStateTimeout(400).build()); locationLayerPlugin.forceLocationUpdate(location); uiController.loopMainThreadForAtLeast(500); assertThat(symbolLayer.getIconImage().getValue(), equalTo(FOREGROUND_STALE_ICON)); @@ -199,8 +199,8 @@ public void whenDrawableChanged_continuesUsingStaleIcons() throws Exception { @Override public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); - locationLayerPlugin.applyStyle(LocationLayerOptions.builder(context).staleStateDelay(100).build()); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); + locationLayerPlugin.applyStyle(LocationLayerOptions.builder(context).staleStateTimeout(100).build()); locationLayerPlugin.forceLocationUpdate(location); uiController.loopMainThreadForAtLeast(200); rule.getActivity().toggleStyle(); @@ -215,9 +215,10 @@ public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, Mapbo public void whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset() throws Exception { executeLocationLayerTest((locationLayerPlugin, mapboxMap, uiController, context) -> { mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(60).build())); - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); locationLayerPlugin.forceLocationUpdate(location); SymbolLayer layer = mapboxMap.getLayerAs(FOREGROUND_LAYER); + uiController.loopMainThreadForAtLeast(200); Float[] value = layer.getIconOffset().getValue(); Assert.assertEquals((-0.05 * 60), value[1], 0.1); }); diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java index 11fd20898..cad3e330c 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java @@ -9,8 +9,6 @@ import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.plugins.testapp.activity.TrafficActivity; -import com.mapbox.mapboxsdk.style.functions.CameraFunction; -import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource; @@ -822,11 +820,7 @@ public void lineWidthFunctionLocalBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -838,11 +832,7 @@ public void lineWidthFunctionLocalCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -855,11 +845,7 @@ public void lineWidthFunctionSecondaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -871,11 +857,7 @@ public void lineWidthFunctionSecondaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -887,11 +869,7 @@ public void lineWidthFunctionPrimaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -903,11 +881,7 @@ public void lineWidthFunctionPrimaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -919,11 +893,7 @@ public void lineWidthFunctionTrunkBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -935,11 +905,7 @@ public void lineWidthFunctionTrunkCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -951,11 +917,7 @@ public void lineWidthFunctionMotorwayBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -967,11 +929,7 @@ public void lineWidthFunctionMotorwayCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -983,11 +941,7 @@ public void lineOffsetFunctionLocalBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -999,11 +953,7 @@ public void lineOffsetFunctionLocalCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1016,11 +966,7 @@ public void lineOffsetFunctionSecondaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1032,11 +978,7 @@ public void lineOffsetFunctionSecondaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1048,11 +990,7 @@ public void lineOffsetFunctionPrimaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1064,11 +1002,7 @@ public void lineOffsetFunctionPrimaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1080,11 +1014,7 @@ public void lineOffsetFunctionTrunkBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1096,11 +1026,7 @@ public void lineOffsetFunctionTrunkCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1112,11 +1038,7 @@ public void lineOffsetFunctionMotorwayBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(5, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1128,11 +1050,7 @@ public void lineOffsetFunctionMotorwayCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(5, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java index 31c699b4b..ff3ab5e4a 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java @@ -3,20 +3,25 @@ import android.app.Activity; import android.support.test.espresso.IdlingResource; -import timber.log.Timber; - +import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import java.lang.reflect.Field; -public class OnMapReadyIdlingResource implements IdlingResource { +public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback { - private final Activity activity; private MapboxMap mapboxMap; private IdlingResource.ResourceCallback resourceCallback; public OnMapReadyIdlingResource(Activity activity) { - this.activity = activity; + try { + Field field = activity.getClass().getDeclaredField("mapView"); + field.setAccessible(true); + ((MapView) field.get(activity)).getMapAsync(this); + } catch (Exception err) { + throw new RuntimeException(err); + } } @Override @@ -26,11 +31,7 @@ public String getName() { @Override public boolean isIdleNow() { - boolean idle = isMapboxMapReady(); - if (idle && resourceCallback != null) { - resourceCallback.onTransitionToIdle(); - } - return idle; + return mapboxMap != null; } @Override @@ -38,20 +39,15 @@ public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } - private boolean isMapboxMapReady() { - try { - Field field = activity.getClass().getDeclaredField("mapboxMap"); - field.setAccessible(true); - mapboxMap = (MapboxMap) field.get(activity); - Timber.e("isMapboxReady called with value " + (mapboxMap != null)); - return mapboxMap != null; - } catch (Exception exception) { - Timber.e("could not reflect", exception); - return false; - } - } - public MapboxMap getMapboxMap() { return mapboxMap; } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + if (resourceCallback != null) { + resourceCallback.onTransitionToIdle(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java index 76a5f01a2..c081b2084 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java @@ -117,7 +117,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - switch (item.getItemId()) { case R.id.menu_building_min_zoom: buildingPlugin.setMinZoomLevel(14); diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/FeatureOverviewActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/FeatureOverviewActivity.java index 1be6e6ec5..1c8932779 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/FeatureOverviewActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/FeatureOverviewActivity.java @@ -26,9 +26,9 @@ import android.widget.TextView; import android.widget.Toast; +import com.mapbox.android.core.permissions.PermissionsListener; +import com.mapbox.android.core.permissions.PermissionsManager; import com.mapbox.mapboxsdk.plugins.testapp.R; -import com.mapbox.services.android.telemetry.permissions.PermissionsListener; -import com.mapbox.services.android.telemetry.permissions.PermissionsManager; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/CompassListenerActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/CompassListenerActivity.java index 16dbc5992..2a66e011c 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/CompassListenerActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/CompassListenerActivity.java @@ -3,17 +3,17 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineProvider; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.plugins.locationlayer.CompassListener; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerMode; import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.mapboxsdk.plugins.testapp.R; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LostLocationEngine; import butterknife.BindView; import butterknife.ButterKnife; @@ -39,9 +39,9 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onMapReady(final MapboxMap mapboxMap) { - LocationEngine locationEngine = new LostLocationEngine(this); + LocationEngine locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable(); locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); + locationLayerPlugin.setRenderMode(RenderMode.COMPASS); locationLayerPlugin.addCompassListener(new CompassListener() { @Override public void onCompassChanged(float userHeading) { @@ -96,7 +96,7 @@ public void onLowMemory() { protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); - locationLayerPlugin.removeCompassListener(null); + //locationLayerPlugin.removeCompassListener(); } @Override diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java index d6e5e8a25..37f31f058 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java @@ -6,16 +6,16 @@ import android.view.Menu; import android.view.MenuItem; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEnginePriority; +import com.mapbox.android.core.location.LocationEngineProvider; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerMode; import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.mapboxsdk.plugins.testapp.Utils; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEnginePriority; -import com.mapbox.services.android.telemetry.location.LostLocationEngine; import butterknife.BindView; import butterknife.ButterKnife; @@ -48,11 +48,12 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - locationEngine = LostLocationEngine.getLocationEngine(this); + locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable(); locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); locationEngine.activate(); locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); - locationPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); + locationPlugin.setRenderMode(RenderMode.COMPASS); + getLifecycle().addObserver(locationPlugin); } @OnClick(R.id.fabStyles) @@ -65,9 +66,6 @@ public void onStyleFabClick() { @Override protected void onStart() { super.onStart(); - if (locationPlugin != null) { - locationPlugin.onStart(); - } mapView.onStart(); } @@ -86,9 +84,6 @@ protected void onPause() { @Override protected void onStop() { super.onStop(); - if (locationPlugin != null) { - locationPlugin.onStop(); - } if (locationEngine != null) { locationEngine.removeLocationUpdates(); } diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerModesActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerModesActivity.java index c66993be9..1dec7753e 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerModesActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerModesActivity.java @@ -1,43 +1,72 @@ package com.mapbox.mapboxsdk.plugins.testapp.activity.location; +import android.annotation.SuppressLint; +import android.content.res.Configuration; import android.location.Location; import android.os.Bundle; import android.support.annotation.VisibleForTesting; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.ListPopupWindow; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.TextView; import android.widget.Toast; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineListener; +import com.mapbox.android.core.location.LocationEnginePriority; +import com.mapbox.android.core.location.LocationEngineProvider; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerMode; +import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerOptions; import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; +import com.mapbox.mapboxsdk.plugins.locationlayer.OnCameraTrackingChangedListener; import com.mapbox.mapboxsdk.plugins.locationlayer.OnLocationLayerClickListener; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.mapboxsdk.plugins.testapp.R; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; -import com.mapbox.services.android.telemetry.location.LocationEnginePriority; -import com.mapbox.services.android.telemetry.location.LostLocationEngine; + +import java.util.ArrayList; +import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class LocationLayerModesActivity extends AppCompatActivity implements OnMapReadyCallback, - LocationEngineListener, OnLocationLayerClickListener { + LocationEngineListener, OnLocationLayerClickListener, OnCameraTrackingChangedListener { @BindView(R.id.map_view) MapView mapView; + @BindView(R.id.tv_mode) + TextView modeText; + @BindView(R.id.tv_tracking) + TextView trackingText; + @BindView(R.id.button_location_mode) + Button locationModeBtn; + @BindView(R.id.button_location_tracking) + Button locationTrackingBtn; private LocationLayerPlugin locationLayerPlugin; private LocationEngine locationEngine; private MapboxMap mapboxMap; private boolean customStyle; + private static final String SAVED_STATE_CAMERA = "saved_state_camera"; + private static final String SAVED_STATE_RENDER = "saved_state_render"; + + @CameraMode.Mode + private int cameraMode = CameraMode.NONE; + + @RenderMode.Mode + private int renderMode = RenderMode.NORMAL; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -46,53 +75,56 @@ protected void onCreate(Bundle savedInstanceState) { mapView.onCreate(savedInstanceState); mapView.getMapAsync(this); - } - @SuppressWarnings( {"MissingPermission"}) - @OnClick(R.id.button_location_mode_none) - public void locationModeNone(View view) { - if (locationLayerPlugin == null) { - return; + if (savedInstanceState != null) { + cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA); + renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER); } - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE); } @SuppressWarnings( {"MissingPermission"}) - @OnClick(R.id.button_location_mode_compass) - public void locationModeCompass(View view) { + @OnClick(R.id.button_location_mode) + public void locationMode(View view) { if (locationLayerPlugin == null) { return; } - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); + showModeListDialog(); } - @SuppressWarnings( {"MissingPermission"}) - @OnClick(R.id.button_location_mode_tracking) - public void locationModeTracking(View view) { - if (locationLayerPlugin == null) { - return; - } - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); - } - - @SuppressWarnings( {"MissingPermission"}) - @OnClick(R.id.button_location_mode_navigation) - public void locationModeNavigation(View view) { + @OnClick(R.id.button_location_tracking) + public void locationModeCompass(View view) { if (locationLayerPlugin == null) { return; } - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NAVIGATION); + showTrackingListDialog(); } + @SuppressLint("MissingPermission") @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - locationEngine = new LostLocationEngine(this); + + locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable(); locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); + locationEngine.setFastestInterval(1000); locationEngine.addLocationEngineListener(this); locationEngine.activate(); - locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); - locationLayerPlugin.setOnLocationClickListener(this); + + int[] padding; + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + padding = new int[] {0, 750, 0, 0}; + } else { + padding = new int[] {0, 250, 0, 0}; + } + LocationLayerOptions options = LocationLayerOptions.builder(this) + .padding(padding) + .build(); + locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine, options); + locationLayerPlugin.addOnLocationClickListener(this); + locationLayerPlugin.addOnCameraTrackingChangedListener(this); + locationLayerPlugin.setCameraMode(cameraMode); + setRendererMode(renderMode); + getLifecycle().addObserver(locationLayerPlugin); } @@ -102,6 +134,7 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } + @SuppressLint("MissingPermission") @Override public boolean onOptionsItemSelected(MenuItem item) { if (locationLayerPlugin == null) { @@ -111,6 +144,12 @@ public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_style_change) { toggleStyle(); return true; + } else if (item.getItemId() == R.id.action_plugin_disable) { + locationLayerPlugin.setLocationLayerEnabled(false); + return true; + } else if (item.getItemId() == R.id.action_plugin_enabled) { + locationLayerPlugin.setLocationLayerEnabled(true); + return true; } return super.onOptionsItemSelected(item); @@ -165,6 +204,8 @@ protected void onStop() { protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); + outState.putInt(SAVED_STATE_CAMERA, cameraMode); + outState.putInt(SAVED_STATE_RENDER, renderMode); } @Override @@ -192,10 +233,101 @@ public void onConnected() { public void onLocationChanged(Location location) { mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(location.getLatitude(), location.getLongitude()), 16)); + locationEngine.removeLocationEngineListener(this); } @Override public void onLocationLayerClick() { Toast.makeText(this, "OnLocationLayerClick", Toast.LENGTH_LONG).show(); } + + private void showModeListDialog() { + List modes = new ArrayList<>(); + modes.add("Normal"); + modes.add("Compass"); + modes.add("GPS"); + ArrayAdapter profileAdapter = new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, modes); + ListPopupWindow listPopup = new ListPopupWindow(this); + listPopup.setAdapter(profileAdapter); + listPopup.setAnchorView(locationModeBtn); + listPopup.setOnItemClickListener((parent, itemView, position, id) -> { + String selectedMode = modes.get(position); + locationModeBtn.setText(selectedMode); + if (selectedMode.contentEquals("Normal")) { + setRendererMode(RenderMode.NORMAL); + } else if (selectedMode.contentEquals("Compass")) { + setRendererMode(RenderMode.COMPASS); + } else if (selectedMode.contentEquals("GPS")) { + setRendererMode(RenderMode.GPS); + } + listPopup.dismiss(); + }); + listPopup.show(); + } + + private void setRendererMode(@RenderMode.Mode int mode) { + renderMode = mode; + locationLayerPlugin.setRenderMode(mode); + if (mode == RenderMode.NORMAL) { + locationModeBtn.setText("Normal"); + } else if (mode == RenderMode.COMPASS) { + locationModeBtn.setText("Compass"); + } else if (mode == RenderMode.GPS) { + locationModeBtn.setText("Gps"); + } + } + + private void showTrackingListDialog() { + List trackingTypes = new ArrayList<>(); + trackingTypes.add("None"); + trackingTypes.add("Tracking"); + trackingTypes.add("Tracking Compass"); + trackingTypes.add("Tracking GPS"); + trackingTypes.add("Tracking GPS North"); + ArrayAdapter profileAdapter = new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, trackingTypes); + ListPopupWindow listPopup = new ListPopupWindow(this); + listPopup.setAdapter(profileAdapter); + listPopup.setAnchorView(locationTrackingBtn); + listPopup.setOnItemClickListener((parent, itemView, position, id) -> { + String selectedTrackingType = trackingTypes.get(position); + locationTrackingBtn.setText(selectedTrackingType); + if (selectedTrackingType.contentEquals("None")) { + locationLayerPlugin.setCameraMode(CameraMode.NONE); + } else if (selectedTrackingType.contentEquals("Tracking")) { + locationLayerPlugin.setCameraMode(CameraMode.TRACKING); + } else if (selectedTrackingType.contentEquals("Tracking Compass")) { + locationLayerPlugin.setCameraMode(CameraMode.TRACKING_COMPASS); + } else if (selectedTrackingType.contentEquals("Tracking GPS")) { + locationLayerPlugin.setCameraMode(CameraMode.TRACKING_GPS); + } else if (selectedTrackingType.contentEquals("Tracking GPS North")) { + locationLayerPlugin.setCameraMode(CameraMode.TRACKING_GPS_NORTH); + } + listPopup.dismiss(); + }); + listPopup.show(); + } + + @Override + public void onCameraTrackingDismissed() { + locationTrackingBtn.setText("None"); + } + + @Override + public void onCameraTrackingChanged(int currentMode) { + this.cameraMode = currentMode; + + if (cameraMode == CameraMode.NONE) { + locationTrackingBtn.setText("None"); + } else if (cameraMode == CameraMode.TRACKING) { + locationTrackingBtn.setText("Tracking"); + } else if (cameraMode == CameraMode.TRACKING_COMPASS) { + locationTrackingBtn.setText("Tracking Compass"); + } else if (cameraMode == CameraMode.TRACKING_GPS) { + locationTrackingBtn.setText("Tracking GPS"); + } else if (cameraMode == CameraMode.TRACKING_GPS_NORTH) { + locationTrackingBtn.setText("Tracking GPS North"); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/ManualLocationUpdatesActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/ManualLocationUpdatesActivity.java index c50fd06b2..4ff8fb234 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/ManualLocationUpdatesActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/ManualLocationUpdatesActivity.java @@ -7,17 +7,17 @@ import android.support.v7.app.AppCompatActivity; import android.view.View; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineListener; +import com.mapbox.android.core.location.LocationEnginePriority; +import com.mapbox.android.core.location.LocationEngineProvider; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerMode; import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; +import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.mapboxsdk.plugins.testapp.Utils; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; -import com.mapbox.services.android.telemetry.location.LocationEnginePriority; -import com.mapbox.services.android.telemetry.location.LostLocationEngine; import butterknife.BindView; import butterknife.ButterKnife; @@ -66,12 +66,12 @@ public void manualLocationChangeFabClick(View view) { @SuppressWarnings( {"MissingPermission"}) public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - locationEngine = new LostLocationEngine(this); + locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable(); locationEngine.addLocationEngineListener(this); locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); locationEngine.activate(); locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, null); - locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); + locationLayerPlugin.setRenderMode(RenderMode.NORMAL); getLifecycle().addObserver(locationLayerPlugin); } diff --git a/app/src/main/res/layout/activity_location_layer_mode.xml b/app/src/main/res/layout/activity_location_layer_mode.xml index 69fdc4ede..3266fae4e 100644 --- a/app/src/main/res/layout/activity_location_layer_mode.xml +++ b/app/src/main/res/layout/activity_location_layer_mode.xml @@ -32,40 +32,46 @@ tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1"> -