summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2015-12-20 09:19:03 -0600
committerBrad Leege <bleege@gmail.com>2015-12-20 09:19:03 -0600
commit8f532eeefa72ec92bbb61d6f3a12c78e2bd181cd (patch)
treecc63626f928148dc46c15ab4467816dc4efe90d3 /platform
parentf3de446bd9faf99103d967343b802cf2ccdc6920 (diff)
downloadqtlocation-mapboxgl-8f532eeefa72ec92bbb61d6f3a12c78e2bd181cd.tar.gz
[android] #3358 - Making Core GL camera methods private. Adding moveCamera() API method. Updating CameraActivity to use only animateCamera() and moveCamera() API.
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java44
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java26
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml16
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml4
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 4ef0219362..b2ea997928 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 5bd03da1df..24974c120b 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 86e7199f77..7c2501555b 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 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/button_camera_animate"
- android:id="@+id/cameraAnimateButton"
+ android:text="@string/button_camera_move"
+ android:id="@+id/cameraMoveButton"
android:layout_margin="@dimen/fab_margin"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
@@ -32,18 +32,18 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/button_camera_animate_callback"
- android:id="@+id/cameraAnimateCallbackButton"
- android:layout_alignTop="@+id/cameraAnimateButton"
+ android:text="@string/button_camera_ease"
+ android:id="@+id/cameraEaseButton"
+ android:layout_alignTop="@+id/cameraMoveButton"
android:layout_centerHorizontal="true"
android:background="@color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/button_camera_animate_duration"
- android:id="@+id/cameraAnimateDurationButton"
- android:layout_alignBottom="@+id/cameraAnimateCallbackButton"
+ android:text="@string/button_camera_animate"
+ android:id="@+id/cameraAnimateButton"
+ android:layout_alignBottom="@+id/cameraEaseButton"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/fab_margin"
android:background="@color/white"/>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
index ab28c93e3f..909e61a39b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
@@ -42,9 +42,9 @@
<string name="action_visible_bounds_explanation">Center map around 2 markers</string>
<string name="action_remove_polylines">Remove polylines</string>
+ <string name="button_camera_move">Move</string>
+ <string name="button_camera_ease">Ease</string>
<string name="button_camera_animate">Animate</string>
- <string name="button_camera_animate_callback">Callback</string>
- <string name="button_camera_animate_duration">Duration</string>
<string name="label_fps">FPS:</string>