use of com.mapbox.services.android.navigation.v5.milestone.Milestone in project mapbox-navigation-android by mapbox.
the class MapboxNavigationTest method removeMilestone_correctMilestoneWithIdentifierGetsRemoved.
@Test
public void removeMilestone_correctMilestoneWithIdentifierGetsRemoved() throws Exception {
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build();
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class));
Milestone milestone = new StepMilestone.Builder().setIdentifier(5678).build();
navigationWithOptions.addMilestone(milestone);
assertEquals(1, navigationWithOptions.getMilestones().size());
navigationWithOptions.removeMilestone(5678);
assertEquals(0, navigationWithOptions.getMilestones().size());
}
use of com.mapbox.services.android.navigation.v5.milestone.Milestone in project mapbox-navigation-android by mapbox.
the class NavigationEngine method handleRequest.
/**
* Takes a new location model and runs all related engine checks against it
* (off-route, milestones, snapped location, and faster-route).
* <p>
* After running through the engines, all data is submitted to {@link NavigationService} via
* {@link NavigationEngine.Callback}.
*
* @param newLocationModel hold location, navigation (with options), and distances away from maneuver
*/
private void handleRequest(final NewLocationModel newLocationModel) {
final MapboxNavigation mapboxNavigation = newLocationModel.mapboxNavigation();
boolean snapToRouteEnabled = mapboxNavigation.options().snapToRoute();
final Location rawLocation = newLocationModel.location();
RouteProgress routeProgress = routeProcessor.buildNewRouteProgress(mapboxNavigation, rawLocation);
final boolean userOffRoute = isUserOffRoute(newLocationModel, routeProgress, routeProcessor);
routeProcessor.checkIncreaseIndex(mapboxNavigation);
RouteProgress previousRouteProgress = routeProcessor.getPreviousRouteProgress();
final List<Milestone> milestones = checkMilestones(previousRouteProgress, routeProgress, mapboxNavigation);
final Location location = routeProcessor.buildSnappedLocation(mapboxNavigation, snapToRouteEnabled, rawLocation, routeProgress, userOffRoute);
boolean fasterRouteEnabled = mapboxNavigation.options().enableFasterRouteDetection();
final boolean checkFasterRoute = fasterRouteEnabled && !userOffRoute && shouldCheckFasterRoute(newLocationModel, routeProgress);
final RouteProgress finalRouteProgress = routeProgress;
routeProcessor.setPreviousRouteProgress(finalRouteProgress);
responseHandler.post(new Runnable() {
@Override
public void run() {
callback.onNewRouteProgress(location, finalRouteProgress);
callback.onMilestoneTrigger(milestones, finalRouteProgress);
callback.onUserOffRoute(location, userOffRoute);
callback.onCheckFasterRoute(location, finalRouteProgress, checkFasterRoute);
}
});
}
use of com.mapbox.services.android.navigation.v5.milestone.Milestone in project mapbox-navigation-android by mapbox.
the class NavigationService method onMilestoneTrigger.
/**
* With each valid and successful rawLocation update, this will get called once the work on the
* navigation engine thread has finished. Depending on whether or not a milestone gets triggered
* or not, the navigation event dispatcher will be called to notify the developer.
*/
@Override
public void onMilestoneTrigger(List<Milestone> triggeredMilestones, RouteProgress routeProgress) {
for (Milestone milestone : triggeredMilestones) {
String instruction = buildInstructionString(routeProgress, milestone);
mapboxNavigation.getEventDispatcher().onMilestoneEvent(routeProgress, instruction, milestone);
}
}
use of com.mapbox.services.android.navigation.v5.milestone.Milestone in project mapbox-navigation-android by mapbox.
the class MapboxNavigationTest method addMilestone_milestoneOnlyGetsAddedOnce.
@Test
public void addMilestone_milestoneOnlyGetsAddedOnce() throws Exception {
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build();
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class));
Milestone milestone = new StepMilestone.Builder().build();
navigationWithOptions.addMilestone(milestone);
navigationWithOptions.addMilestone(milestone);
assertEquals(1, navigationWithOptions.getMilestones().size());
}
use of com.mapbox.services.android.navigation.v5.milestone.Milestone in project mapbox-navigation-android by mapbox.
the class MapboxNavigationTest method removeMilestone_milestoneDidGetRemoved.
@Test
public void removeMilestone_milestoneDidGetRemoved() throws Exception {
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build();
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class));
Milestone milestone = new StepMilestone.Builder().build();
navigationWithOptions.addMilestone(milestone);
assertEquals(1, navigationWithOptions.getMilestones().size());
navigationWithOptions.removeMilestone(milestone);
assertEquals(0, navigationWithOptions.getMilestones().size());
}
Aggregations