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());
}
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);
}
});
}
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);
}
}
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);
}
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());
}
Aggregations