use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationEventDispatcherTest method setup.
@Before
public void setup() throws IOException {
MockitoAnnotations.initMocks(this);
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, mock(NavigationTelemetry.class), mock(LocationEngine.class));
navigationEventDispatcher = navigation.getEventDispatcher();
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(PRECISION_6);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
route = response.routes().get(0);
routeProgress = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(100).distanceRemaining(100).directionsRoute(route).stepIndex(0).legIndex(0).build();
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationEventDispatcherTest method setNavigationMetricListener_didNotGetTriggeredUntilArrival.
@Test
public void setNavigationMetricListener_didNotGetTriggeredUntilArrival() throws Exception {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
navigationEventDispatcher.addMetricEventListeners(eventListeners);
navigationEventDispatcher.addMetricArrivalListener(arrivalListener);
// Progress that hasn't arrived
RouteProgress routeProgressDidNotArrive = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(100).distanceRemaining(100).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
navigationEventDispatcher.onProgressChange(location, routeProgressDidNotArrive);
verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidNotArrive);
verify(arrivalListener, times(0)).onArrival(location, routeProgressDidNotArrive);
// Progress that has arrived
RouteProgress routeProgressDidArrive = RouteProgress.builder().stepDistanceRemaining(30).legDistanceRemaining(30).distanceRemaining(30).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
navigationEventDispatcher.onProgressChange(location, routeProgressDidArrive);
verify(eventListeners, times(1)).onRouteProgressUpdate(routeProgressDidArrive);
verify(arrivalListener, times(1)).onArrival(location, routeProgressDidArrive);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationHelperTest method setUp.
@Before
public void setUp() throws Exception {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(MULTI_LEG_ROUTE);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
route = response.routes().get(0);
Location location = new Location("test");
List<Point> coords = PolylineUtils.decode(route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6);
location.setLatitude(coords.get(0).latitude());
location.setLongitude(coords.get(0).longitude());
routeProgressBuilder = RouteProgress.builder().directionsRoute(route).distanceRemaining(1000).stepDistanceRemaining(1000).legDistanceRemaining(1000).stepIndex(0).legIndex(0);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteProgressTest method setup.
@Before
public void setup() throws IOException {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_PRECISION_6);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
route = response.routes().get(0);
RouteLeg firstLeg = route.legs().get(0);
// Multiple leg route
body = loadJsonFixture(MULTI_LEG_ROUTE);
response = gson.fromJson(body, DirectionsResponse.class);
multiLegRoute = response.routes().get(0);
beginningRouteProgress = RouteProgress.builder().stepDistanceRemaining(route.legs().get(0).steps().get(0).distance()).legDistanceRemaining(route.legs().get(0).distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
lastRouteProgress = RouteProgress.builder().stepDistanceRemaining(route.legs().get(0).steps().get(firstLeg.steps().size() - 1).distance()).legDistanceRemaining(route.legs().get(0).distance()).distanceRemaining(0).directionsRoute(route).stepIndex(firstLeg.steps().size() - 1).legIndex(route.legs().size() - 1).build();
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteStepProgressTest method stepDistance_equalsZeroOnOneCoordSteps.
@Test
public void stepDistance_equalsZeroOnOneCoordSteps() throws IOException {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DCMAPBOX_CHIPOLTLE);
response = gson.fromJson(body, DirectionsResponse.class);
DirectionsRoute route = response.routes().get(0);
RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(0).legDistanceRemaining(0).distanceRemaining(0).directionsRoute(route).stepIndex(route.legs().get(0).steps().size() - 1).legIndex(0).build();
RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
assertNotNull("should not be null", routeStepProgress);
assertEquals(1, routeStepProgress.fractionTraveled(), DELTA);
assertEquals(0, routeStepProgress.distanceRemaining(), DELTA);
assertEquals(0, routeStepProgress.distanceTraveled(), DELTA);
assertEquals(0, routeStepProgress.durationRemaining(), DELTA);
}
Aggregations