summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerConstants.java10
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java56
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt20
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt37
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java60
7 files changed, 117 insertions, 77 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 588a327839..7dddcae993 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -132,6 +132,7 @@ public final class MapboxMap {
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, nativeMapView.getDebug());
outState.putString(MapboxConstants.STATE_STYLE_URL, nativeMapView.getStyleUrl());
uiSettings.onSaveInstanceState(outState);
+ locationLayerPlugin.onSaveInstanceState(outState);
}
/**
@@ -156,6 +157,7 @@ public final class MapboxMap {
if (!TextUtils.isEmpty(styleUrl)) {
nativeMapView.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
}
+ locationLayerPlugin.onRestoreInstanceState(savedInstanceState);
}
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerConstants.java
index b6e4f568af..6e5f9bf4c6 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerConstants.java
@@ -5,6 +5,12 @@ package com.mapbox.mapboxsdk.plugins.locationlayer;
*/
final class LocationLayerConstants {
+ static final String STATE_LOCATION_ENABLED = "mapbox_location_locationEnabled";
+ static final String STATE_LOCATION_OPTIONS = "mapbox_location_options";
+ static final String STATE_LOCATION_LAST_LOCATION = "mapbox_location_lastLocation";
+ static final String STATE_LOCATION_RENDER_MODE = "mapbox_location_renderMode";
+ static final String STATE_LOCATION_CAMERA_MODE = "mapbox_location_cameraMode";
+
// Controls the compass update rate in milliseconds
static final int COMPASS_UPDATE_RATE_MS = 500;
@@ -18,10 +24,10 @@ final class LocationLayerConstants {
static final long ACCURACY_RADIUS_ANIMATION_DURATION = 250;
// Default animation duration for zooming while tracking.
- static final long DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION = 750;
+ static final long DEFAULT_TRACKING_ZOOM_ANIM_DURATION = 750;
// Default animation duration for tilting while tracking.
- static final long DEFAULT_TRACKING_TILT_ANIMATION_DURATION = 1250;
+ static final long DEFAULT_TRACKING_TILT_ANIM_DURATION = 1250;
// Sources
static final String LOCATION_SOURCE = "mapbox-location-source";
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
index 1fcdaa7c76..c98ee9c4ce 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
+import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
@@ -31,8 +32,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
-import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_TILT_ANIMATION_DURATION;
-import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.STATE_LOCATION_CAMERA_MODE;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.STATE_LOCATION_ENABLED;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.STATE_LOCATION_LAST_LOCATION;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.STATE_LOCATION_OPTIONS;
+import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.STATE_LOCATION_RENDER_MODE;
/**
* The Location layer plugin provides location awareness to your mobile application. Enabling this
@@ -59,6 +65,16 @@ import static com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.
* When instantiating the plugin for the first time, the map's max/min zoom levels will be set to
* {@link LocationLayerOptions#MAX_ZOOM_DEFAULT} and {@link LocationLayerOptions#MIN_ZOOM_DEFAULT} respectively.
* You can adjust the zoom range with {@link LocationLayerOptions#maxZoom()} and {@link LocationLayerOptions#minZoom()}.
+ * <p>
+ * When an activity, or a fragment, that contains the plugin is destroyed and recreated,
+ * the plugin will restore its state, which is:
+ * <br/>
+ * - If the plugin was enabled, last location will be displayed.
+ * You still need to activate the plugin, or just provide the {@link LocationEngine}.
+ * <br/>
+ * - {@link CameraMode} and {@link RenderMode} will be restored.
+ * <br/>
+ * - {@link LocationLayerOptions} will be restored.
*/
public final class LocationLayerPlugin {
private static final String TAG = "Mbgl-LocationLayerPlugin";
@@ -265,9 +281,9 @@ public final class LocationLayerPlugin {
* @param cameraMode one of the modes found in {@link CameraMode}
*/
public void setCameraMode(@CameraMode.Mode int cameraMode) {
+ locationLayerCamera.setCameraMode(cameraMode);
boolean isGpsNorth = cameraMode == CameraMode.TRACKING_GPS_NORTH;
pluginAnimatorCoordinator.resetAllCameraAnimations(mapboxMap.getCameraPosition(), isGpsNorth);
- locationLayerCamera.setCameraMode(cameraMode);
}
/**
@@ -387,7 +403,7 @@ public final class LocationLayerPlugin {
* @param zoomLevel The desired zoom level.
*/
public void zoomWhileTracking(double zoomLevel) {
- zoomWhileTracking(zoomLevel, DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION, null);
+ zoomWhileTracking(zoomLevel, DEFAULT_TRACKING_ZOOM_ANIM_DURATION, null);
}
/**
@@ -445,7 +461,7 @@ public final class LocationLayerPlugin {
* @param tilt The desired camera tilt.
*/
public void tiltWhileTracking(double tilt) {
- tiltWhileTracking(tilt, DEFAULT_TRACKING_TILT_ANIMATION_DURATION, null);
+ tiltWhileTracking(tilt, DEFAULT_TRACKING_TILT_ANIM_DURATION, null);
}
/**
@@ -668,6 +684,28 @@ public final class LocationLayerPlugin {
/**
* Internal use.
*/
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ outState.putBoolean(STATE_LOCATION_ENABLED, isEnabled);
+ outState.putParcelable(STATE_LOCATION_OPTIONS, options);
+ outState.putInt(STATE_LOCATION_RENDER_MODE, locationLayer.getRenderMode());
+ outState.putInt(STATE_LOCATION_CAMERA_MODE, locationLayerCamera.getCameraMode());
+ outState.putParcelable(STATE_LOCATION_LAST_LOCATION, lastLocation);
+ }
+
+ /**
+ * Internal use.
+ */
+ public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
+ updateLocation(savedInstanceState.getParcelable(STATE_LOCATION_LAST_LOCATION), true);
+ setCameraMode(savedInstanceState.getInt(STATE_LOCATION_CAMERA_MODE));
+ setRenderMode(savedInstanceState.getInt(STATE_LOCATION_RENDER_MODE));
+ applyStyle(savedInstanceState.getParcelable(STATE_LOCATION_OPTIONS));
+ setLocationLayerEnabled(savedInstanceState.getBoolean(STATE_LOCATION_ENABLED));
+ }
+
+ /**
+ * Internal use.
+ */
public void onDestroy() {
if (locationEngine != null && usingInternalLocationEngine) {
locationEngine.deactivate();
@@ -772,6 +810,14 @@ public final class LocationLayerPlugin {
}
private void initializeLocationEngine(@NonNull Context context) {
+ if (this.locationEngine != null) {
+ if (usingInternalLocationEngine) {
+ this.locationEngine.removeLocationUpdates();
+ this.locationEngine.deactivate();
+ }
+ this.locationEngine.removeLocationEngineListener(locationEngineListener);
+ }
+
usingInternalLocationEngine = true;
locationEngine = new LocationEngineProvider(context).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt
index 738b7b7a20..2d7dc5b1a2 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/PluginAnimatorCoordinatorTest.kt
@@ -3,8 +3,8 @@ package com.mapbox.mapboxsdk.plugins.locationlayer
import android.location.Location
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
-import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_TILT_ANIMATION_DURATION
-import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION
import com.mapbox.mapboxsdk.plugins.locationlayer.PluginAnimator.*
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
@@ -154,7 +154,7 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewZoomLevel(
15.0,
cameraPosition,
- DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION,
+ DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
null
)
@@ -167,12 +167,12 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewZoomLevel(
zoom.toDouble(),
cameraPosition,
- DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION,
+ DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
null
)
val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM]?.duration as Long
- assertEquals(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION, animationDuration)
+ assertEquals(DEFAULT_TRACKING_ZOOM_ANIM_DURATION, animationDuration)
val target = pluginAnimatorCoordinator.animatorMap[ANIMATOR_ZOOM]?.target as Float
assertEquals(zoom, target)
@@ -183,7 +183,7 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewTilt(
30.0,
cameraPosition,
- DEFAULT_TRACKING_TILT_ANIMATION_DURATION,
+ DEFAULT_TRACKING_TILT_ANIM_DURATION,
null
)
@@ -196,12 +196,12 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewTilt(
tilt.toDouble(),
cameraPosition,
- DEFAULT_TRACKING_TILT_ANIMATION_DURATION,
+ DEFAULT_TRACKING_TILT_ANIM_DURATION,
null
)
val animationDuration = pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT]?.duration as Long
- assertEquals(DEFAULT_TRACKING_TILT_ANIMATION_DURATION, animationDuration)
+ assertEquals(DEFAULT_TRACKING_TILT_ANIM_DURATION, animationDuration)
val target = pluginAnimatorCoordinator.animatorMap[ANIMATOR_TILT]?.target as Float
assertEquals(tilt, target)
@@ -220,7 +220,7 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewZoomLevel(
15.0,
cameraPosition,
- DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION,
+ DEFAULT_TRACKING_ZOOM_ANIM_DURATION,
null
)
pluginAnimatorCoordinator.cancelZoomAnimation()
@@ -233,7 +233,7 @@ class PluginAnimatorCoordinatorTest {
pluginAnimatorCoordinator.feedNewTilt(
30.0,
cameraPosition,
- DEFAULT_TRACKING_TILT_ANIMATION_DURATION,
+ DEFAULT_TRACKING_TILT_ANIM_DURATION,
null
)
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt
index 1820d56d95..e9552f974b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt
@@ -12,6 +12,7 @@ import android.support.test.espresso.UiController
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.rule.GrantPermissionRule
+import android.support.test.runner.AndroidJUnit4
import android.support.v4.content.ContextCompat
import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
@@ -33,7 +34,9 @@ import org.hamcrest.CoreMatchers.*
import org.junit.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
+import org.junit.runner.RunWith
+@RunWith(AndroidJUnit4::class)
class LocationLayerPluginTest : BaseActivityTest() {
@Rule
@@ -57,12 +60,6 @@ class LocationLayerPluginTest : BaseActivityTest() {
@Before
override fun beforeTest() {
super.beforeTest()
-
- location.latitude = 15.0
- location.longitude = 17.0
- location.bearing = 10f
- location.accuracy = 150f
-
styleChangeIdlingResource = StyleChangeIdlingResource()
IdlingRegistry.getInstance().register(styleChangeIdlingResource)
}
@@ -839,7 +836,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.cameraMode = CameraMode.NONE
val zoom = mapboxMap.cameraPosition.zoom
plugin.zoomWhileTracking(10.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
assertEquals(zoom, mapboxMap.cameraPosition.zoom, 0.1)
}
@@ -856,7 +853,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.zoomWhileTracking(10.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
assertEquals(10.0, mapboxMap.cameraPosition.zoom, 0.1)
}
@@ -874,9 +871,9 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.zoomWhileTracking(15.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
plugin.cameraMode = CameraMode.NONE
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
assertEquals(15.0 / 2.0, mapboxMap.cameraPosition.zoom, 3.0)
}
@@ -898,7 +895,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.onStop()
plugin.zoomWhileTracking(10.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
assertEquals(zoom, mapboxMap.cameraPosition.zoom, 0.1)
}
@@ -916,9 +913,9 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.zoomWhileTracking(15.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
plugin.cancelZoomWhileTrackingAnimation()
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
assertEquals(15.0 / 2.0, mapboxMap.cameraPosition.zoom, 3.0)
}
@@ -936,7 +933,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.cameraMode = CameraMode.NONE
val tilt = mapboxMap.cameraPosition.tilt
plugin.tiltWhileTracking(30.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
assertEquals(tilt, mapboxMap.cameraPosition.tilt, 0.1)
}
@@ -953,7 +950,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.tiltWhileTracking(30.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
assertEquals(30.0, mapboxMap.cameraPosition.tilt, 0.1)
}
@@ -971,9 +968,9 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.tiltWhileTracking(30.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
plugin.cameraMode = CameraMode.NONE
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
assertEquals(30.0 / 2.0, mapboxMap.cameraPosition.tilt, 3.0)
}
@@ -993,7 +990,7 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.onStop()
plugin.tiltWhileTracking(30.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
assertEquals(tilt, mapboxMap.cameraPosition.tilt, 0.1)
}
@@ -1011,9 +1008,9 @@ class LocationLayerPluginTest : BaseActivityTest() {
plugin.activateLocationLayerPlugin(context, false)
plugin.cameraMode = CameraMode.TRACKING
plugin.tiltWhileTracking(30.0)
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
plugin.cancelTiltWhileTrackingAnimation()
- uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIMATION_DURATION / 2)
+ uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
assertEquals(30.0 / 2.0, mapboxMap.cameraPosition.tilt, 3.0)
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt
index d7823031fc..a0f23ce485 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt
@@ -12,6 +12,7 @@ import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.rule.GrantPermissionRule
import android.support.test.rule.GrantPermissionRule.grant
+import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.constants.Style
import com.mapbox.mapboxsdk.geometry.LatLng
@@ -35,7 +36,9 @@ import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
+import org.junit.runner.RunWith
+@RunWith(AndroidJUnit4::class)
class LocationLayerTest : BaseActivityTest() {
@Rule
@@ -52,7 +55,7 @@ class LocationLayerTest : BaseActivityTest() {
initLocation.latitude = 15.0
initLocation.longitude = 17.0
initLocation.bearing = 10f
- initLocation.accuracy = 2000f
+ initLocation.accuracy = 150f
initLocation
}
@@ -219,10 +222,6 @@ class LocationLayerTest : BaseActivityTest() {
executePluginTest(pluginAction)
}
-//
-// Stale state test
-//
-
@Test
fun whenStyleChanged_continuesUsingStaleIcons() {
val pluginAction = object : LocationLayerPluginAction.OnPerformLocationLayerPluginAction {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java
index ce005c1825..4c8c8eda4b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java
@@ -50,14 +50,7 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
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.TRACKING;
-
- @RenderMode.Mode
- private int renderMode = RenderMode.NORMAL;
+ private Bundle savedInstanceState;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -88,12 +81,6 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
}
});
-
- if (savedInstanceState != null) {
- cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA);
- renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER);
- }
-
mapView.onCreate(savedInstanceState);
if (PermissionsManager.areLocationPermissionsGranted(this)) {
@@ -117,6 +104,8 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
});
permissionsManager.requestLocationPermissions(this);
}
+
+ this.savedInstanceState = savedInstanceState;
}
@Override
@@ -139,8 +128,7 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
locationLayerPlugin = mapboxMap.getLocationLayerPlugin();
locationLayerPlugin.addOnLocationClickListener(this);
locationLayerPlugin.addOnCameraTrackingChangedListener(this);
- locationLayerPlugin.setCameraMode(cameraMode);
- setRendererMode(renderMode);
+
activateLocationLayer();
}
@@ -184,12 +172,23 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
padding = new int[] {0, 250, 0, 0};
}
- LocationLayerOptions options = LocationLayerOptions.builder(this)
- .padding(padding)
- .layerBelow("waterway-label")
- .build();
+ if (savedInstanceState == null) {
+ LocationLayerOptions options = LocationLayerOptions.builder(this)
+ .padding(padding)
+ .layerBelow("waterway-label")
+ .build();
- locationLayerPlugin.activateLocationLayerPlugin(locationEngine, options);
+ locationLayerPlugin.activateLocationLayerPlugin(locationEngine, options);
+ } else {
+ LocationLayerOptions options = locationLayerPlugin
+ .getLocationLayerOptions()
+ .toBuilder()
+ .padding(padding)
+ .build();
+
+ locationLayerPlugin.setLocationEngine(locationEngine);
+ locationLayerPlugin.applyStyle(options);
+ }
}
}
@@ -205,10 +204,6 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
mapboxMap.setStyle(styleUrl);
}
- public LocationLayerPlugin getLocationLayerPlugin() {
- return locationLayerPlugin;
- }
-
@Override
@SuppressWarnings( {"MissingPermission"})
protected void onStart() {
@@ -250,8 +245,6 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
- outState.putInt(SAVED_STATE_CAMERA, cameraMode);
- outState.putInt(SAVED_STATE_RENDER, renderMode);
}
@Override
@@ -311,7 +304,6 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
}
private void setRendererMode(@RenderMode.Mode int mode) {
- renderMode = mode;
locationLayerPlugin.setRenderMode(mode);
if (mode == RenderMode.NORMAL) {
locationModeBtn.setText("Normal");
@@ -376,17 +368,15 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
@Override
public void onCameraTrackingChanged(int currentMode) {
- this.cameraMode = currentMode;
-
- if (cameraMode == CameraMode.NONE) {
+ if (currentMode == CameraMode.NONE) {
locationTrackingBtn.setText("None");
- } else if (cameraMode == CameraMode.TRACKING) {
+ } else if (currentMode == CameraMode.TRACKING) {
locationTrackingBtn.setText("Tracking");
- } else if (cameraMode == CameraMode.TRACKING_COMPASS) {
+ } else if (currentMode == CameraMode.TRACKING_COMPASS) {
locationTrackingBtn.setText("Tracking Compass");
- } else if (cameraMode == CameraMode.TRACKING_GPS) {
+ } else if (currentMode == CameraMode.TRACKING_GPS) {
locationTrackingBtn.setText("Tracking GPS");
- } else if (cameraMode == CameraMode.TRACKING_GPS_NORTH) {
+ } else if (currentMode == CameraMode.TRACKING_GPS_NORTH) {
locationTrackingBtn.setText("Tracking GPS North");
}
}