[android] expose camera padding option
This removes the cached insets on the Android side, making the core TransformState the source of truth. This still leaves an option to lazily set the padding which is going to be applied only when the next camera animation is started.
This commit is contained in:
committed by
Łukasz Paczos
parent
e5c219d035
commit
becc705f05
@@ -1,11 +1,15 @@
|
||||
package com.mapbox.mapboxsdk.camera
|
||||
|
||||
import android.graphics.PointF
|
||||
import android.support.test.annotation.UiThreadTest
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@@ -17,127 +21,166 @@ class CameraUpdateFactoryTest : BaseTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngBoundsUntiltedUnrotated() {
|
||||
rule.runOnUiThread {
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.5, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.5, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngBoundsTilted() {
|
||||
rule.runOnUiThread {
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(45.0)
|
||||
.build()
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(45.0)
|
||||
.build()
|
||||
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 6.0, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 0.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 6.0, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngBoundsRotated() {
|
||||
rule.runOnUiThread {
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(30.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(30.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.3, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.3, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 0.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngBoundsTiltedRotated() {
|
||||
rule.runOnUiThread {
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(30.0)
|
||||
.tilt(45.0)
|
||||
.build()
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(30.0)
|
||||
.tilt(45.0)
|
||||
.build()
|
||||
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0))
|
||||
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 45.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngBoundsWithProvidedTiltAndRotation() {
|
||||
rule.runOnUiThread {
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
mapboxMap.cameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(60.0, 24.0))
|
||||
.bearing(0.0)
|
||||
.tilt(0.0)
|
||||
.build()
|
||||
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
val bounds: LatLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(62.0, 26.0))
|
||||
.include(LatLng(58.0, 22.0))
|
||||
.build()
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30.0, 40.0, 0))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30.0, 40.0, 0))
|
||||
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 40.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
val cameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals("latitude should match:", 60.0, cameraPosition.target.latitude, 0.1)
|
||||
assertEquals("longitude should match:", 24.0, cameraPosition.target.longitude, 0.1)
|
||||
assertEquals("bearing should match:", 30.0, cameraPosition.bearing, 0.1)
|
||||
assertEquals("zoom should match", 5.6, cameraPosition.zoom, 0.1)
|
||||
assertEquals("tilt should match:", 40.0, cameraPosition.tilt, 0.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun withPadding_cameraInvalidated_paddingPersisting() {
|
||||
val initialCameraPosition = mapboxMap.cameraPosition
|
||||
val initialPoint = mapboxMap.projection.toScreenLocation(initialCameraPosition.target)
|
||||
|
||||
val bottomPadding = mapView.height / 4
|
||||
val leftPadding = mapView.width / 4
|
||||
val padding = doubleArrayOf(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble())
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.paddingTo(leftPadding.toDouble(), 0.0, 0.0, bottomPadding.toDouble()))
|
||||
|
||||
Assert.assertArrayEquals(intArrayOf(leftPadding, 0, 0, bottomPadding), mapboxMap.padding)
|
||||
|
||||
val resultingCameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals(initialCameraPosition.target, resultingCameraPosition.target)
|
||||
assertEquals(
|
||||
PointF(initialPoint.x + leftPadding / 2, initialPoint.y - bottomPadding / 2),
|
||||
mapboxMap.projection.toScreenLocation(resultingCameraPosition.target)
|
||||
)
|
||||
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun withLatLngPadding_cameraInvalidated_paddingPersisting() {
|
||||
val expectedTarget = LatLng(2.0, 2.0)
|
||||
|
||||
val topPadding = mapView.height / 4
|
||||
val rightPadding = mapView.width / 4
|
||||
val padding = doubleArrayOf(0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0)
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngPadding(expectedTarget, 0.0, topPadding.toDouble(), rightPadding.toDouble(), 0.0))
|
||||
|
||||
Assert.assertArrayEquals(intArrayOf(0, topPadding, rightPadding, 0), mapboxMap.padding)
|
||||
|
||||
val resultingCameraPosition = mapboxMap.cameraPosition
|
||||
assertEquals(expectedTarget.latitude, resultingCameraPosition.target.latitude, 0.1)
|
||||
assertEquals(expectedTarget.longitude, resultingCameraPosition.target.longitude, 0.1)
|
||||
|
||||
val centerLatLng = mapboxMap.projection.fromScreenLocation(PointF((mapView.width / 2).toFloat(), (mapView.height / 2).toFloat()))
|
||||
assertTrue(centerLatLng.latitude > resultingCameraPosition.target.latitude)
|
||||
assertTrue(centerLatLng.longitude > resultingCameraPosition.target.longitude)
|
||||
Assert.assertArrayEquals(padding, resultingCameraPosition.padding, 0.0001)
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants
|
||||
import junit.framework.Assert.*
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -30,6 +31,7 @@ class NativeMapViewTest : AppCenter() {
|
||||
const val BEARING_TEST = 60.0
|
||||
const val PITCH_TEST = 40.0
|
||||
const val ZOOM_TEST = 16.0
|
||||
val PADDING_TEST = doubleArrayOf(80.0, 150.0, 0.0, 0.0)
|
||||
const val WIDTH = 500
|
||||
const val HEIGHT = WIDTH
|
||||
val LATLNG_TEST = LatLng(12.0, 34.0)
|
||||
@@ -86,6 +88,18 @@ class NativeMapViewTest : AppCenter() {
|
||||
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngPadding() {
|
||||
val expected = LATLNG_TEST
|
||||
nativeMapView.contentPadding = PADDING_TEST
|
||||
nativeMapView.setLatLng(expected, 0)
|
||||
val actual = nativeMapView.latLng
|
||||
assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA)
|
||||
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA)
|
||||
Assert.assertArrayEquals(PADDING_TEST, nativeMapView.cameraPosition.padding, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testLatLngDefault() {
|
||||
@@ -145,14 +159,18 @@ class NativeMapViewTest : AppCenter() {
|
||||
.target(LATLNG_TEST)
|
||||
.tilt(PITCH_TEST)
|
||||
.zoom(ZOOM_TEST)
|
||||
.padding(PADDING_TEST)
|
||||
.build()
|
||||
nativeMapView.jumpTo(LATLNG_TEST, ZOOM_TEST, PITCH_TEST, BEARING_TEST)
|
||||
// verify that the lazily set padding is ignored when a value is provided with the camera
|
||||
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
|
||||
nativeMapView.jumpTo(LATLNG_TEST, ZOOM_TEST, PITCH_TEST, BEARING_TEST, PADDING_TEST)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, DELTA)
|
||||
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, DELTA)
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, DELTA)
|
||||
assertEquals("Pitch should match", expected.tilt, actual.tilt, DELTA)
|
||||
assertEquals("Zoom should match", expected.zoom, actual.zoom, DELTA)
|
||||
Assert.assertArrayEquals(expected.padding, actual.padding, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,7 +224,7 @@ class NativeMapViewTest : AppCenter() {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun testSetContentPadding() {
|
||||
val expected = floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f)
|
||||
val expected = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
|
||||
nativeMapView.contentPadding = expected
|
||||
val actual = nativeMapView.contentPadding
|
||||
assertEquals("Left should match", expected[0], actual[0])
|
||||
@@ -258,14 +276,18 @@ class NativeMapViewTest : AppCenter() {
|
||||
.tilt(30.0)
|
||||
.target(LatLng(12.0, 14.0))
|
||||
.bearing(20.0)
|
||||
.padding(PADDING_TEST)
|
||||
.build()
|
||||
nativeMapView.flyTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0)
|
||||
// verify that the lazily set padding is ignored when a value is provided with the camera
|
||||
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
|
||||
nativeMapView.flyTo(expected.target, expected.zoom, expected.bearing, expected.tilt, PADDING_TEST, 0)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
|
||||
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, TestConstants.LAT_LNG_DELTA)
|
||||
assertEquals("Tilt should match", expected.tilt, actual.tilt, TestConstants.TILT_DELTA)
|
||||
assertEquals("Zoom should match", expected.zoom, actual.zoom, TestConstants.ZOOM_DELTA)
|
||||
Assert.assertArrayEquals(expected.padding, actual.padding, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -276,14 +298,18 @@ class NativeMapViewTest : AppCenter() {
|
||||
.tilt(30.0)
|
||||
.target(LatLng(12.0, 14.0))
|
||||
.bearing(20.0)
|
||||
.padding(PADDING_TEST)
|
||||
.build()
|
||||
nativeMapView.easeTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0, false)
|
||||
// verify that the lazily set padding is ignored when a value is provided with the camera
|
||||
nativeMapView.contentPadding = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
|
||||
nativeMapView.easeTo(expected.target, expected.zoom, expected.bearing, expected.tilt, PADDING_TEST, 0, false)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
|
||||
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, TestConstants.LAT_LNG_DELTA)
|
||||
assertEquals("Tilt should match", expected.tilt, actual.tilt, TestConstants.TILT_DELTA)
|
||||
assertEquals("Zoom should match", expected.zoom, actual.zoom, TestConstants.ZOOM_DELTA)
|
||||
Assert.assertArrayEquals(expected.padding, actual.padding, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,8 +320,9 @@ class NativeMapViewTest : AppCenter() {
|
||||
.tilt(0.0)
|
||||
.target(LatLng(0.0, 0.0))
|
||||
.bearing(0.0)
|
||||
.padding(PADDING_TEST)
|
||||
.build()
|
||||
nativeMapView.jumpTo(LatLng(1.0, 2.0), 12.0, 23.0, 1.0)
|
||||
nativeMapView.jumpTo(LatLng(1.0, 2.0), 12.0, 23.0, 1.0, PADDING_TEST)
|
||||
nativeMapView.resetPosition()
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
@@ -303,6 +330,7 @@ class NativeMapViewTest : AppCenter() {
|
||||
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, TestConstants.LAT_LNG_DELTA)
|
||||
assertEquals("Tilt should match", expected.tilt, actual.tilt, TestConstants.TILT_DELTA)
|
||||
assertEquals("Zoom should match", expected.zoom, actual.zoom, TestConstants.ZOOM_DELTA)
|
||||
Assert.assertArrayEquals(expected.padding, actual.padding, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,297 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.testapp.camera;
|
||||
|
||||
import android.support.test.espresso.Espresso;
|
||||
import android.support.test.espresso.IdlingRegistry;
|
||||
import android.support.test.espresso.idling.CountingIdlingResource;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CameraAnimateTest extends BaseTest {
|
||||
|
||||
private final CountingIdlingResource animationIdlingResource =
|
||||
new CountingIdlingResource("animation_idling_resource");
|
||||
|
||||
public class CameraAnimateTest extends CameraTest {
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return DeviceIndependentTestActivity.class;
|
||||
void executeCameraMovement(CameraUpdate cameraUpdate, MapboxMap.CancelableCallback callback) {
|
||||
mapboxMap.animateCamera(cameraUpdate, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTest() {
|
||||
super.beforeTest();
|
||||
IdlingRegistry.getInstance().register(animationIdlingResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToCameraPositionTarget() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
LatLng moveTarget = new LatLng(1, 1);
|
||||
CameraPosition initialPosition = new CameraPosition.Builder().target(
|
||||
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(moveTarget), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToCameraPositionTargetZoom() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float moveZoom = 15.5f;
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom), new MapboxMap
|
||||
.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToCameraPosition() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
final float moveZoom = 15.5f;
|
||||
final float moveTilt = 45.5f;
|
||||
final float moveBearing = 12.5f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(moveTarget)
|
||||
.zoom(moveZoom)
|
||||
.tilt(moveTilt)
|
||||
.bearing(moveBearing)
|
||||
.build()),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToBounds() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng centerBounds = new LatLng(1, 1);
|
||||
LatLng cornerOne = new LatLng();
|
||||
LatLng cornerTwo = new LatLng(2, 2);
|
||||
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(cornerOne);
|
||||
builder.include(cornerTwo);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0), new MapboxMap
|
||||
.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToZoomIn() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.zoomIn(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToZoomOut() {
|
||||
validateTestSetup();
|
||||
float zoom = 10.0f;
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(
|
||||
CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
invoke(mapboxMap, ((uiController, mapboxMap1) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.zoomOut(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToZoomBy() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
final float zoomBy = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(zoomBy), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnimateToZoomTo() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float zoomTo = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(zoomTo), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTest() {
|
||||
super.afterTest();
|
||||
IdlingRegistry.getInstance().unregister(animationIdlingResource);
|
||||
}
|
||||
|
||||
private void verifyCameraPosition(MapboxMap mapboxMap, LatLng moveTarget, double moveZoom, double moveBearing,
|
||||
double moveTilt) {
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
|
||||
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
|
||||
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
|
||||
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,294 +1,12 @@
|
||||
package com.mapbox.mapboxsdk.testapp.camera;
|
||||
|
||||
import android.support.test.espresso.Espresso;
|
||||
import android.support.test.espresso.IdlingRegistry;
|
||||
import android.support.test.espresso.idling.CountingIdlingResource;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CameraEaseTest extends BaseTest {
|
||||
|
||||
private final CountingIdlingResource animationIdlingResource =
|
||||
new CountingIdlingResource("animation_idling_resource");
|
||||
public class CameraEaseTest extends CameraTest {
|
||||
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return DeviceIndependentTestActivity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTest() {
|
||||
super.beforeTest();
|
||||
IdlingRegistry.getInstance().register(animationIdlingResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToCameraPositionTarget() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
LatLng moveTarget = new LatLng(1, 1);
|
||||
CameraPosition initialPosition = new CameraPosition.Builder().target(
|
||||
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(moveTarget), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToCameraPositionTargetZoom() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float moveZoom = 15.5f;
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToCameraPosition() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
final float moveZoom = 15.5f;
|
||||
final float moveTilt = 45.5f;
|
||||
final float moveBearing = 12.5f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(moveTarget)
|
||||
.zoom(moveZoom)
|
||||
.tilt(moveTilt)
|
||||
.bearing(moveBearing)
|
||||
.build()),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToBounds() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng centerBounds = new LatLng(1, 1);
|
||||
LatLng cornerOne = new LatLng();
|
||||
LatLng cornerTwo = new LatLng(2, 2);
|
||||
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(cornerOne);
|
||||
builder.include(cornerTwo);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToZoomIn() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.zoomIn(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToZoomOut() {
|
||||
float zoom = 10.0f;
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.zoomOut(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToZoomBy() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
final float zoomBy = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.zoomBy(zoomBy), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEaseToZoomTo() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float zoomTo = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.zoomTo(zoomTo), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTest() {
|
||||
super.afterTest();
|
||||
IdlingRegistry.getInstance().unregister(animationIdlingResource);
|
||||
}
|
||||
|
||||
private void verifyCameraPosition(MapboxMap mapboxMap, LatLng moveTarget, double moveZoom, double moveBearing,
|
||||
double moveTilt) {
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
|
||||
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
|
||||
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
|
||||
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
|
||||
void executeCameraMovement(CameraUpdate cameraUpdate, MapboxMap.CancelableCallback callback) {
|
||||
mapboxMap.easeCamera(cameraUpdate, callback);
|
||||
}
|
||||
}
|
||||
@@ -1,294 +1,12 @@
|
||||
|
||||
package com.mapbox.mapboxsdk.testapp.camera;
|
||||
|
||||
import android.support.test.espresso.Espresso;
|
||||
import android.support.test.espresso.IdlingRegistry;
|
||||
import android.support.test.espresso.idling.CountingIdlingResource;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CameraMoveTest extends BaseTest {
|
||||
|
||||
private final CountingIdlingResource animationIdlingResource =
|
||||
new CountingIdlingResource("animation_idling_resource");
|
||||
|
||||
public class CameraMoveTest extends CameraTest {
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return DeviceIndependentTestActivity.class;
|
||||
void executeCameraMovement(CameraUpdate cameraUpdate, MapboxMap.CancelableCallback callback) {
|
||||
mapboxMap.moveCamera(cameraUpdate, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTest() {
|
||||
super.beforeTest();
|
||||
IdlingRegistry.getInstance().register(animationIdlingResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToCameraPositionTarget() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
LatLng moveTarget = new LatLng(1, 1);
|
||||
CameraPosition initialPosition = new CameraPosition.Builder().target(
|
||||
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(moveTarget), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToCameraPositionTargetZoom() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float moveZoom = 15.5f;
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToCameraPosition() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
final float moveZoom = 15.5f;
|
||||
final float moveTilt = 45.5f;
|
||||
final float moveBearing = 12.5f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(moveTarget)
|
||||
.zoom(moveZoom)
|
||||
.tilt(moveTilt)
|
||||
.bearing(moveBearing)
|
||||
.build()),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToBounds() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng centerBounds = new LatLng(1, 1);
|
||||
LatLng cornerOne = new LatLng();
|
||||
LatLng cornerTwo = new LatLng(2, 2);
|
||||
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(cornerOne);
|
||||
builder.include(cornerTwo);
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToZoomIn() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomIn(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToZoomOut() {
|
||||
float zoom = 10.0f;
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomOut(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToZoomBy() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
final float zoomBy = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(zoomBy), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveToZoomTo() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float zoomTo = 2.45f;
|
||||
|
||||
animationIdlingResource.increment();
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(zoomTo), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0);
|
||||
animationIdlingResource.decrement();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Espresso.onIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTest() {
|
||||
super.afterTest();
|
||||
IdlingRegistry.getInstance().unregister(animationIdlingResource);
|
||||
}
|
||||
|
||||
private void verifyCameraPosition(MapboxMap mapboxMap, LatLng moveTarget, double moveZoom, double moveBearing,
|
||||
double moveTilt) {
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
|
||||
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
|
||||
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
|
||||
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
package com.mapbox.mapboxsdk.testapp.camera;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class CameraTest extends BaseTest {
|
||||
|
||||
private CountDownLatch latch;
|
||||
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return DeviceIndependentTestActivity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTest() {
|
||||
super.beforeTest();
|
||||
latch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCameraPositionTarget() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
LatLng moveTarget = new LatLng(1, 1);
|
||||
CameraPosition initialPosition = new CameraPosition.Builder().target(
|
||||
new LatLng()).zoom(zoom).bearing(0).tilt(0).padding(new double[4]).build();
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.newLatLng(moveTarget), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCameraPositionTargetZoom() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float moveZoom = 15.5f;
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCameraPosition() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
|
||||
final float moveZoom = 15.5f;
|
||||
final float moveTilt = 45.5f;
|
||||
final float moveBearing = 12.5f;
|
||||
final double[] movePadding = new double[] {0, 500, 350, 1};
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(moveTarget)
|
||||
.zoom(moveZoom)
|
||||
.tilt(moveTilt)
|
||||
.bearing(moveBearing)
|
||||
.padding(movePadding)
|
||||
.build()),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt, movePadding);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, moveTarget, moveZoom, moveBearing, moveTilt, movePadding);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBounds() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final LatLng centerBounds = new LatLng(1, 1);
|
||||
LatLng cornerOne = new LatLng();
|
||||
LatLng cornerTwo = new LatLng(2, 2);
|
||||
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(cornerOne);
|
||||
builder.include(cornerTwo);
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.newLatLngBounds(builder.build(), 0),
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, centerBounds, mapboxMap.getCameraPosition().zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToZoomIn() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.zoomIn(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + 1, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToZoomOut() throws InterruptedException {
|
||||
float zoom = 10.0f;
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
executeCameraMovement(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
|
||||
latch = new CountDownLatch(1);
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
executeCameraMovement(CameraUpdateFactory.zoomOut(), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom - 1, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToZoomBy() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
float zoom = 1.0f;
|
||||
final float zoomBy = 2.45f;
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.zoomBy(zoomBy), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoom + zoomBy, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToZoomTo() throws InterruptedException {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
final float zoomTo = 2.45f;
|
||||
|
||||
executeCameraMovement(CameraUpdateFactory.zoomTo(zoomTo), new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
verifyCameraPosition(mapboxMap, mapboxMap.getCameraPosition().target, zoomTo, 0, 0, new double[4]);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
Assert.fail("timeout");
|
||||
}
|
||||
}
|
||||
|
||||
abstract void executeCameraMovement(CameraUpdate cameraUpdate, MapboxMap.CancelableCallback callback);
|
||||
|
||||
private void verifyCameraPosition(MapboxMap mapboxMap, LatLng moveTarget, double moveZoom, double moveBearing,
|
||||
double moveTilt, double[] padding) {
|
||||
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
|
||||
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
|
||||
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
|
||||
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
|
||||
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
|
||||
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
|
||||
assertArrayEquals("Moved padding should match", cameraPosition.padding, padding, TestConstants.PADDING_DELTA);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ public class TestConstants {
|
||||
public static final double BEARING_DELTA = 0.1;
|
||||
public static final double TILT_DELTA = 0.3;
|
||||
public static final double ZOOM_DELTA = 0.3;
|
||||
public static final double PADDING_DELTA = 0.0001;
|
||||
|
||||
public static final String TEXT_MARKER_TITLE = "Marker";
|
||||
public static final String TEXT_MARKER_SNIPPET = "Snippet";
|
||||
|
||||
Reference in New Issue
Block a user