use of com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener in project mapbox-navigation-android by mapbox.
the class NavigationEventDispatcher method onProgressChange.
void onProgressChange(Location location, RouteProgress routeProgress) {
if (metricEventListeners != null) {
// Update RouteProgress
metricEventListeners.onRouteProgressUpdate(routeProgress);
// Check if user has arrived and notify metric listener if so
if (RouteUtils.isArrivalEvent(routeProgress) && metricArrivalListener != null) {
metricArrivalListener.onArrival(location, routeProgress);
metricArrivalListener = null;
// If a this is the last leg, navigation is ending - remove listeners
if (RouteUtils.isLastLeg(routeProgress)) {
// Remove off route listeners
removeOffRouteListener(null);
// Remove metric listener
metricEventListeners = null;
}
}
}
for (ProgressChangeListener progressChangeListener : progressChangeListeners) {
progressChangeListener.onProgressChange(location, routeProgress);
}
}
use of com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener in project mapbox-navigation-android by mapbox.
the class NavigationCameraTest method onStartWithNullRoute_progressListenerIsAdded.
@Test
public void onStartWithNullRoute_progressListenerIsAdded() throws Exception {
MapboxNavigation navigation = mock(MapboxNavigation.class);
ProgressChangeListener listener = mock(ProgressChangeListener.class);
NavigationCamera camera = buildCamera(navigation, listener);
camera.start(null);
verify(navigation, times(1)).addProgressChangeListener(listener);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener in project mapbox-navigation-android by mapbox.
the class NavigationCameraTest method onResumeWithNullLocation_progressListenerIsAdded.
@Test
public void onResumeWithNullLocation_progressListenerIsAdded() throws Exception {
MapboxNavigation navigation = mock(MapboxNavigation.class);
ProgressChangeListener listener = mock(ProgressChangeListener.class);
NavigationCamera camera = buildCamera(navigation, listener);
camera.resume(null);
verify(navigation, times(1)).addProgressChangeListener(listener);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener in project mapbox-navigation-android by mapbox.
the class NavigationCamera method animateCameraFromRoute.
/**
* Creates an initial animation with the given {@link RouteInformation#route()}.
* <p>
* This is the first animation that fires prior to receiving progress updates.
* <p>
* If a user interacts with the {@link MapboxMap} while the animation is in progress,
* the animation will be cancelled. So it's important to add the {@link ProgressChangeListener}
* in both onCancel() and onFinish() scenarios.
*
* @param routeInformation with route data
*/
private void animateCameraFromRoute(RouteInformation routeInformation) {
Camera cameraEngine = navigation.getCameraEngine();
Point targetPoint = cameraEngine.target(routeInformation);
LatLng targetLatLng = new LatLng(targetPoint.latitude(), targetPoint.longitude());
double bearing = cameraEngine.bearing(routeInformation);
double zoom = cameraEngine.zoom(routeInformation);
CameraPosition position = new CameraPosition.Builder().target(targetLatLng).bearing(bearing).zoom(zoom).build();
updateMapCameraPosition(position, new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
navigation.addProgressChangeListener(progressChangeListener);
}
@Override
public void onFinish() {
navigation.addProgressChangeListener(progressChangeListener);
}
});
}
Aggregations