Search in sources :

Example 1 with MapboxNavigation

use of com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation 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 MapboxNavigation

use of com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation 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 MapboxNavigation

use of com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation in project mapbox-navigation-android by mapbox.

the class NavigationService method initializeNotification.

/**
 * Builds a new navigation notification instance (either custom or our default implementation)
 * and attaches it to this service.
 */
private void initializeNotification(MapboxNavigationOptions options) {
    if (options.navigationNotification() != null) {
        navigationNotification = options.navigationNotification();
        Notification notification = navigationNotification.getNotification();
        int notificationId = navigationNotification.getNotificationId();
        startForegroundNotification(notification, notificationId);
    } else {
        navigationNotification = new MapboxNavigationNotification(this, mapboxNavigation);
        Notification notification = navigationNotification.getNotification();
        int notificationId = navigationNotification.getNotificationId();
        startForegroundNotification(notification, notificationId);
    }
}
Also used : NavigationNotification(com.mapbox.services.android.navigation.v5.navigation.notification.NavigationNotification) Notification(android.app.Notification)

Example 4 with MapboxNavigation

use of com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method cancelFeedback.

/**
 * Cancels an existing feedback event generated by {@link MapboxNavigation#recordFeedback(String, String, String)}.
 * <p>
 * Uses a feedback ID to find the correct event and then cancels it (will no longer be recorded).
 *
 * @param feedbackId generated from {@link MapboxNavigation#recordFeedback(String, String, String)}
 */
void cancelFeedback(String feedbackId) {
    // Find the event and remove it from the queue
    FeedbackEvent feedbackEvent = (FeedbackEvent) findQueuedTelemetryEvent(feedbackId);
    queuedFeedbackEvents.remove(feedbackEvent);
}
Also used : FeedbackEvent(com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent)

Example 5 with MapboxNavigation

use of com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation in project mapbox-navigation-android by mapbox.

the class MockNavigationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mock_navigation);
    ButterKnife.bind(this);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);
    // Use a custom notification
    CustomNavigationNotification customNavigationNotification = new CustomNavigationNotification(this);
    MapboxNavigationOptions options = MapboxNavigationOptions.builder().navigationNotification(customNavigationNotification).build();
    navigation = new MapboxNavigation(this, Mapbox.getAccessToken(), options);
    navigation.addMilestone(new RouteMilestone.Builder().setIdentifier(BEGIN_ROUTE_MILESTONE).setInstruction(new BeginRouteInstruction()).setTrigger(Trigger.all(Trigger.lt(TriggerProperty.STEP_INDEX, 3), Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200), Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75))).build());
}
Also used : CustomNavigationNotification(com.mapbox.services.android.navigation.testapp.activity.notification.CustomNavigationNotification) MapboxNavigationOptions(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigationOptions) MapboxNavigation(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation) RouteMilestone(com.mapbox.services.android.navigation.v5.milestone.RouteMilestone)

Aggregations

Test (org.junit.Test)7 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)6 Context (android.content.Context)5 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)5 StepMilestone (com.mapbox.services.android.navigation.v5.milestone.StepMilestone)5 MapboxNavigation (com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation)5 LocationEngine (com.mapbox.services.android.telemetry.location.LocationEngine)5 MapboxNavigationOptions (com.mapbox.services.android.navigation.v5.navigation.MapboxNavigationOptions)2 FeedbackEvent (com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent)2 ProgressChangeListener (com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener)2 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)2 Notification (android.app.Notification)1 Location (android.location.Location)1 GsonBuilder (com.google.gson.GsonBuilder)1 CustomNavigationNotification (com.mapbox.services.android.navigation.testapp.activity.notification.CustomNavigationNotification)1 RouteMilestone (com.mapbox.services.android.navigation.v5.milestone.RouteMilestone)1 SessionState (com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState)1 NavigationNotification (com.mapbox.services.android.navigation.v5.navigation.notification.NavigationNotification)1 Date (java.util.Date)1