Search in sources :

Example 1 with Milestone

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());
}
Also used : Context(android.content.Context) LocationEngine(com.mapbox.services.android.telemetry.location.LocationEngine) StepMilestone(com.mapbox.services.android.navigation.v5.milestone.StepMilestone) Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 2 with Milestone

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);
        }
    });
}
Also used : Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location)

Example 3 with Milestone

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);
    }
}
Also used : Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) NavigationHelper.buildInstructionString(com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.buildInstructionString)

Example 4 with 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());
}
Also used : Context(android.content.Context) LocationEngine(com.mapbox.services.android.telemetry.location.LocationEngine) StepMilestone(com.mapbox.services.android.navigation.v5.milestone.StepMilestone) Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) StepMilestone(com.mapbox.services.android.navigation.v5.milestone.StepMilestone) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 5 with Milestone

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());
}
Also used : Context(android.content.Context) LocationEngine(com.mapbox.services.android.telemetry.location.LocationEngine) StepMilestone(com.mapbox.services.android.navigation.v5.milestone.StepMilestone) Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) StepMilestone(com.mapbox.services.android.navigation.v5.milestone.StepMilestone) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)8 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)6 StepMilestone (com.mapbox.services.android.navigation.v5.milestone.StepMilestone)6 Test (org.junit.Test)6 Context (android.content.Context)5 LocationEngine (com.mapbox.services.android.telemetry.location.LocationEngine)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)2 Location (android.location.Location)1 GsonBuilder (com.google.gson.GsonBuilder)1 NavigationHelper.buildInstructionString (com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.buildInstructionString)1