[android] save location state
This commit is contained in:
committed by
Łukasz Paczos
parent
fa3f6f055c
commit
cf7752c80c
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user