Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create camera animation from time between updates #753

Merged
merged 3 commits into from
Mar 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.services.android.navigation.ui.v5.camera;

import android.location.Location;
import android.os.SystemClock;
import android.support.annotation.NonNull;

import com.mapbox.api.directions.v5.models.DirectionsRoute;
Expand All @@ -25,10 +26,13 @@
*/
public class NavigationCamera implements ProgressChangeListener {

private static final long MAX_ANIMATION_DURATION_MS = 1500;

private MapboxMap mapboxMap;
private MapboxNavigation navigation;
private RouteInformation currentRouteInformation;
private boolean trackingEnabled = true;
private long locationUpdateTimestamp;

/**
* Creates an instance of {@link NavigationCamera}.
Expand Down Expand Up @@ -184,7 +188,8 @@ private void updateMapCameraPosition(CameraPosition position, MapboxMap.Cancelab
* @param position to which the camera should animate
*/
private void easeMapCameraPosition(CameraPosition position) {
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000, false, null);
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position),
obtainLocationUpdateDuration(), false, null);
}

/**
Expand Down Expand Up @@ -252,4 +257,11 @@ private void animateCameraFromLocation(RouteInformation routeInformation) {

easeMapCameraPosition(position);
}

private int obtainLocationUpdateDuration() {
long previousUpdateTimeStamp = locationUpdateTimestamp;
locationUpdateTimestamp = SystemClock.elapsedRealtime();
long duration = locationUpdateTimestamp - previousUpdateTimeStamp;
return (int) (duration < MAX_ANIMATION_DURATION_MS ? duration : MAX_ANIMATION_DURATION_MS);
}
}