From 8f532eeefa72ec92bbb61d6f3a12c78e2bd181cd Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Sun, 20 Dec 2015 09:19:03 -0600 Subject: [PATCH] [android] #3358 - Making Core GL camera methods private. Adding moveCamera() API method. Updating CameraActivity to use only animateCamera() and moveCamera() API. --- .../com/mapbox/mapboxsdk/views/MapView.java | 44 ++++++++++++++++--- .../mapboxsdk/testapp/CameraActivity.java | 26 +++-------- .../src/main/res/layout/activity_camera.xml | 16 +++---- .../src/main/res/values/strings.xml | 4 +- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 4ef021936..b2ea99792 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -1521,7 +1521,7 @@ public final class MapView extends FrameLayout { public final void animateCamera (CameraUpdate update, int durationMs, final MapView.CancelableCallback callback) { if (update.getTarget() == null) { - Log.w(TAG, "animateCamera with null target coordinate passed in. Will immediatele return without animating camera."); + Log.w(TAG, "animateCamera with null target coordinate passed in. Will immediately return without animating camera."); return; } @@ -1565,8 +1565,8 @@ public final class MapView extends FrameLayout { if (durationMs == 0) { // Route To `jumpTo` - Log.i(TAG, "jumpTo() called with angle = " + angle + "; target = " + update.getTarget() + "; durationNano = " + durationNano + "; Pitch = " + pitch + "; Zoom = " + update.getZoom()); - jumpTo(angle, update.getTarget(), pitch, zoom); + Log.i(TAG, "easeTo() called with angle = " + angle + "; target = " + update.getTarget() + "; durationNano = " + durationNano + "; Pitch = " + pitch + "; Zoom = " + update.getZoom()); + easeTo(angle, update.getTarget(), 0, pitch, zoom); } else { // Use `flyTo` Log.i(TAG, "flyTo() called with angle = " + angle + "; target = " + update.getTarget() + "; durationNano = " + durationNano + "; Pitch = " + pitch + "; Zoom = " + update.getZoom()); @@ -1574,6 +1574,38 @@ public final class MapView extends FrameLayout { } } + /** + * Repositions the camera according to the instructions defined in the update. + * The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position. + * See CameraUpdateFactory for a set of updates. + * @param update The change that should be applied to the camera. + */ + public final void moveCamera (CameraUpdate update) { + if (update.getTarget() == null) { + Log.w(TAG, "moveCamera with null target coordinate passed in. Will immediately return without moving camera."); + return; + } + + mNativeMapView.cancelTransitions(); + + // Convert Degrees To Radians + double angle = -1; + if (update.getBearing() >= 0) { + angle = (-update.getBearing()) * MathConstants.DEG2RAD; + } + double pitch = -1; + if (update.getTilt() >= 0) { + double dp = MathUtils.clamp(update.getTilt(), MINIMUM_TILT, MAXIMUM_TILT); + pitch = dp * MathConstants.DEG2RAD; + } + double zoom = -1; + if (update.getZoom() >= 0) { + zoom = update.getZoom(); + } + + jumpTo(angle, update.getTarget(), pitch, zoom); + } + // // InfoWindows // @@ -2411,7 +2443,7 @@ public final class MapView extends FrameLayout { * @param zoom Zoom Level */ @UiThread - public void jumpTo(double bearing, LatLng center, double pitch, double zoom) { + private void jumpTo(double bearing, LatLng center, double pitch, double zoom) { mNativeMapView.jumpTo(bearing, center, pitch, zoom); } @@ -2426,7 +2458,7 @@ public final class MapView extends FrameLayout { * @param zoom Zoom Level */ @UiThread - public void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom) { + private void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom) { mNativeMapView.easeTo(bearing, center, duration, pitch, zoom); } @@ -2439,7 +2471,7 @@ public final class MapView extends FrameLayout { * @param zoom Zoom Level */ @UiThread - public void flyTo(double bearing, LatLng center, long duration, double pitch, double zoom) { + private void flyTo(double bearing, LatLng center, long duration, double pitch, double zoom) { mNativeMapView.flyTo(bearing, center, duration, pitch, zoom); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java index 5bd03da1d..24974c120 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java @@ -43,7 +43,7 @@ public class CameraActivity extends AppCompatActivity { mMapView.setCompassEnabled(true); mMapView.onCreate(savedInstanceState); - Button cameraButton = (Button) findViewById(R.id.cameraAnimateButton); + Button cameraButton = (Button) findViewById(R.id.cameraMoveButton); cameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -52,11 +52,11 @@ public class CameraActivity extends AppCompatActivity { .zoom(14) // Sets the zoom .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder - mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); + mMapView.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } }); - Button cameraCallbackButton = (Button) findViewById(R.id.cameraAnimateCallbackButton); + Button cameraCallbackButton = (Button) findViewById(R.id.cameraEaseButton); cameraCallbackButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -67,27 +67,11 @@ public class CameraActivity extends AppCompatActivity { .bearing(180) // Sets the orientation of the camera to south .build(); // Creates a CameraPosition from the builder - MapView.CancelableCallback callback = new MapView.CancelableCallback() { - @Override - public void onCancel() { - // NOTE: This shouldn't appear - Log.i(TAG, "onCancel Callback called."); - Toast.makeText(CameraActivity.this, "onCancel Callback called.", Toast.LENGTH_LONG).show(); - } - - @Override - public void onFinish() { - Log.i(TAG, "onFinish Callback called."); - Toast.makeText(CameraActivity.this, "onFinish Callback called.", Toast.LENGTH_LONG).show(); - } - }; - - mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), callback); - + mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } }); - Button cameraDurationButton = (Button) findViewById(R.id.cameraAnimateDurationButton); + Button cameraDurationButton = (Button) findViewById(R.id.cameraAnimateButton); cameraDurationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml index 86e7199f7..7c2501555 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml @@ -21,8 +21,8 @@