diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2018-02-14 12:36:23 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-02-20 16:22:09 +0100 |
commit | d9e4c61923813b61ffccb6439d0fd3e9993a1a05 (patch) | |
tree | 8ecd311f0ee45f6371f5c4bde08e8a79ea134150 /platform/android | |
parent | 2e3145db475e296552db9d1c65c483b3f51b5237 (diff) | |
download | qtlocation-mapboxgl-d9e4c61923813b61ffccb6439d0fd3e9993a1a05.tar.gz |
[android] - remove camera api from MapboxMap, refactor test app code to CameraUpdateFactory api
Diffstat (limited to 'platform/android')
5 files changed, 37 insertions, 256 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java index 50e33f4f9f..8ef0d5b523 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java @@ -148,6 +148,26 @@ public final class CameraUpdateFactory { return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom); } + /** + * Returns a CameraUpdate that moves the camera viewpoint to a particular bearing. + * + * @param bearing Bearing to change to + * @return CameraUpdate Final Camera Position + */ + public static CameraUpdate bearingTo(double bearing) { + return new CameraPositionUpdate(bearing, null, -1, -1); + } + + /** + * Returns a CameraUpdate that moves the camera viewpoint to a particular tilt. + * + * @param tilt Tilt to change to + * @return CameraUpdate Final Camera Position + */ + public static CameraUpdate tiltTo(double tilt) { + return new CameraPositionUpdate(-1, null, tilt, -1); + } + // // CameraUpdate types // 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 4f2c940ea3..6085e2c2d8 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 @@ -16,6 +16,7 @@ import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; +import com.mapbox.android.core.location.LocationEngine; import com.mapbox.geojson.Feature; import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.annotations.Annotation; @@ -43,7 +44,6 @@ import com.mapbox.mapboxsdk.style.layers.Filter; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.Source; -import com.mapbox.android.core.location.LocationEngine; import java.lang.reflect.ParameterizedType; import java.util.HashMap; @@ -601,7 +601,7 @@ public final class MapboxMap { } // - // + // Light // /** @@ -619,65 +619,6 @@ public final class MapboxMap { // /** - * Moves the center of the screen to a latitude and longitude specified by a LatLng object. This centers the - * camera on the LatLng object. - * <p> - * Note that at low zoom levels, setLatLng is constrained so that the entire viewport shows map data. - * </p> - * - * @param latLng Target location to change to - */ - public void setLatLng(@NonNull LatLng latLng) { - nativeMapView.setLatLng(latLng); - } - - /** - * Moves the camera viewpoint to a particular zoom level. - * - * @param zoom Zoom level to change to - */ - public void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoom) { - if (focalPoint == null) { - focalPoint = new PointF(nativeMapView.getWidth() / 2, nativeMapView.getHeight() / 2); - } - nativeMapView.setZoom(zoom, focalPoint, 0); - } - - /** - * Moves the center and the zoom of the camera specified by a LatLng object and double zoom. - * <p> - * Note that at low zoom levels, setLatLng is constrained so that the entire viewport shows map data. - * </p> - * - * @param latLng Target location to change to - */ - public void setLatLngZoom(@NonNull LatLng latLng, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) double zoom) { - setZoom(zoom); - setLatLng(latLng); - } - - /** - * Moves the camera viewpoint angle to a particular angle in degrees. - * - * @param tilt Tilt angle to change to - */ - public void setTilt(@FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT) double tilt) { - nativeMapView.setPitch(tilt, 0); - } - - /** - * Moves the camera viewpoint direction to a particular angle in degrees. - * - * @param bearing Direction angle to change to - */ - public void setBearing(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) - double bearing) { - nativeMapView.setBearing(bearing); - } - - /** * Cancels ongoing animations. * <p> * This invokes the {@link CancelableCallback} for ongoing camera updates. diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java deleted file mode 100644 index 38d5297291..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -/** - * Utility class to bypass package visibility - */ -public class MapViewUtils { - - public static void setDirection(MapboxMap mapboxMap, float direction) { - mapboxMap.getTransform().setBearing(direction); - } - - public static float getDirection(MapboxMap mapboxMap) { - return (float) mapboxMap.getTransform().getBearing(); - } - - public static void setTilt(MapboxMap mapboxMap, float tilt) { - mapboxMap.getTransform().setTilt((double) tilt); - } - - public static float getTilt(MapboxMap mapboxMap) { - return (float) mapboxMap.getTransform().getTilt(); - } - - public static void setLatLng(MapboxMap mapboxMap, LatLng latLng) { - mapboxMap.getTransform().setCenterCoordinate(latLng); - } - - public static LatLng getLatLng(MapboxMap mapboxMap) { - return mapboxMap.getTransform().getCenterCoordinate(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java deleted file mode 100644 index 883e76653d..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.camera; - -import android.support.test.espresso.Espresso; -import android.support.test.espresso.UiController; -import android.support.test.espresso.ViewAction; -import android.view.View; - -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapViewUtils; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; -import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.TestConstants; - -import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static org.junit.Assert.assertEquals; - -/** - * Tests camera transformations that aren't part of our public API - */ -public class CameraInternalApiTest extends BaseActivityTest { - - @Override - protected Class getActivityClass() { - return EspressoTestActivity.class; - } - - @Test - @Ignore - public void testBearing() { - validateTestSetup(); - - CameraPosition initialPosition = new - CameraPosition.Builder().target(new LatLng()).zoom(1).bearing(0).tilt(0).build(); - CameraPosition cameraPosition = mapboxMap.getCameraPosition(); - assertEquals("Default camera position should match default", cameraPosition, initialPosition); - - onView(withId(R.id.mapView)).perform(new BearingAction(mapboxMap)); - assertEquals("Bearing should match", 45.1f, MapViewUtils.getDirection(mapboxMap), TestConstants.BEARING_DELTA); - } - - @Test - @Ignore - public void testTilt() { - validateTestSetup(); - - CameraPosition initialPosition = new CameraPosition.Builder().target( - new LatLng()).zoom(1).bearing(0).tilt(0).build(); - CameraPosition cameraPosition = mapboxMap.getCameraPosition(); - assertEquals("Default camera position should match default", cameraPosition, initialPosition); - - onView(withId(R.id.mapView)).perform(new TiltAction(mapboxMap)); - assertEquals("Tilt should match", 40.0f, MapViewUtils.getTilt(mapboxMap), TestConstants.TILT_DELTA); - } - - @Test - @Ignore - public void testLatLng() { - validateTestSetup(); - - CameraPosition initialPosition = new CameraPosition.Builder().target( - new LatLng()).zoom(1).bearing(0).tilt(0).build(); - CameraPosition cameraPosition = mapboxMap.getCameraPosition(); - assertEquals("Default camera position should match default", cameraPosition, initialPosition); - - onView(withId(R.id.mapView)).perform(new LatLngAction(mapboxMap)); - LatLng centerCoordinate = MapViewUtils.getLatLng(mapboxMap); - assertEquals("Latitude should match", 1.1f, centerCoordinate.getLatitude(), TestConstants.LAT_LNG_DELTA); - assertEquals("Longitude should match", 2.2f, centerCoordinate.getLongitude(), TestConstants.LAT_LNG_DELTA); - } - - @After - public void unregisterIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } - - private class BearingAction implements ViewAction { - - private MapboxMap mapboxMap; - - BearingAction(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - } - - @Override - public Matcher<View> getConstraints() { - return isDisplayed(); - } - - @Override - public String getDescription() { - return getClass().getSimpleName(); - } - - @Override - public void perform(UiController uiController, View view) { - MapViewUtils.setDirection(mapboxMap, -45.1f); - } - } - - private class TiltAction implements ViewAction { - - private MapboxMap mapboxMap; - - TiltAction(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - } - - @Override - public Matcher<View> getConstraints() { - return isDisplayed(); - } - - @Override - public String getDescription() { - return getClass().getSimpleName(); - } - - @Override - public void perform(UiController uiController, View view) { - MapViewUtils.setTilt(mapboxMap, 40.0f); - } - } - - private class LatLngAction implements ViewAction { - - private MapboxMap mapboxMap; - - LatLngAction(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - } - - @Override - public Matcher<View> getConstraints() { - return isDisplayed(); - } - - @Override - public String getDescription() { - return getClass().getSimpleName(); - } - - @Override - public void perform(UiController uiController, View view) { - MapViewUtils.setLatLng(mapboxMap, new LatLng(1.1, 2.2)); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java index f25fd6ab27..6277dffe91 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java @@ -115,7 +115,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe ValueAnimator latLngAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), currentPosition, targetPosition); latLngAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); latLngAnimator.setInterpolator(new FastOutSlowInInterpolator()); - latLngAnimator.addUpdateListener(animation -> mapboxMap.setLatLng((LatLng) animation.getAnimatedValue())); + latLngAnimator.addUpdateListener(animation -> mapboxMap.moveCamera( + CameraUpdateFactory.newLatLng((LatLng) animation.getAnimatedValue())) + ); return latLngAnimator; } @@ -124,7 +126,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe zoomAnimator.setDuration((long) (2200 * ANIMATION_DELAY_FACTOR)); zoomAnimator.setStartDelay((long) (600 * ANIMATION_DELAY_FACTOR)); zoomAnimator.setInterpolator(new AnticipateOvershootInterpolator()); - zoomAnimator.addUpdateListener(animation -> mapboxMap.setZoom((Float) animation.getAnimatedValue())); + zoomAnimator.addUpdateListener(animation -> mapboxMap.moveCamera( + CameraUpdateFactory.zoomTo((Float) animation.getAnimatedValue())) + ); return zoomAnimator; } @@ -133,7 +137,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe bearingAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); bearingAnimator.setStartDelay((long) (1000 * ANIMATION_DELAY_FACTOR)); bearingAnimator.setInterpolator(new FastOutLinearInInterpolator()); - bearingAnimator.addUpdateListener(animation -> mapboxMap.setBearing((Float) animation.getAnimatedValue())); + bearingAnimator.addUpdateListener(animation -> mapboxMap.moveCamera( + CameraUpdateFactory.bearingTo((Float) animation.getAnimatedValue())) + ); return bearingAnimator; } @@ -141,7 +147,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe ValueAnimator tiltAnimator = ValueAnimator.ofFloat((float) currentTilt, (float) targetTilt); tiltAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); tiltAnimator.setStartDelay((long) (1500 * ANIMATION_DELAY_FACTOR)); - tiltAnimator.addUpdateListener(animation -> mapboxMap.setTilt((Float) animation.getAnimatedValue())); + tiltAnimator.addUpdateListener(animation -> mapboxMap.moveCamera( + CameraUpdateFactory.tiltTo((Float) animation.getAnimatedValue())) + ); return tiltAnimator; } @@ -192,7 +200,9 @@ public class CameraAnimatorActivity extends AppCompatActivity implements OnMapRe ValueAnimator zoomAnimator = ValueAnimator.ofFloat(11.0f, 16.0f); zoomAnimator.setDuration((long) (duration * ANIMATION_DELAY_FACTOR)); zoomAnimator.setInterpolator(interpolator); - zoomAnimator.addUpdateListener(animation -> mapboxMap.setZoom((Float) animation.getAnimatedValue())); + zoomAnimator.addUpdateListener(animation -> mapboxMap.moveCamera( + CameraUpdateFactory.zoomTo((Float) animation.getAnimatedValue())) + ); return zoomAnimator; } |