Skip to content

Commit

Permalink
Create camera animation from time between updates (#753)
Browse files Browse the repository at this point in the history
* Create camera animation from time between updates

* Fixup checkstyle

* Updates per review
  • Loading branch information
danesfeder authored Mar 13, 2018
1 parent cf93796 commit 5ac54b7
Showing 1 changed file with 13 additions and 1 deletion.
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);
}
}

0 comments on commit 5ac54b7

Please sign in to comment.