Skip to content

Commit

Permalink
Update to MAS 3.3.0 and add approaches NavigationRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jun 21, 2018
1 parent 08ffefc commit 0b6d774
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {

version = [
mapboxMapSdk : '6.1.3',
mapboxSdkServices : '3.2.0',
mapboxSdkServices : '3.3.0',
mapboxEvents : '3.1.2',
locationLayerPlugin: '0.5.3',
autoValue : '1.5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,41 @@ public Builder baseUrl(String baseUrl) {
return this;
}

/**
* Indicates from which side of the road to approach a waypoint.
* Accepts unrestricted (default), curb or null.
* If set to unrestricted , the route can approach waypoints
* from either side of the road. If set to curb , the route will be returned
* so that on arrival, the waypoint will be found on the side that corresponds with the
* driving_side of the region in which the returned route is located.
* If provided, the list of approaches must be the same length as the list of waypoints.
*
* @param approaches null if you'd like the default approaches,
* else one of the options found in
* {@link com.mapbox.api.directions.v5.DirectionsCriteria.ApproachesCriteria}.
* @return this builder for chaining options together
* @since 0.15.0
*/
public Builder addApproaches(String... approaches) {
directionsBuilder.addApproaches(approaches);
return this;
}

/**
* Custom names for waypoints used for the arrival instruction,
* each separated by <tt>;</tt>. Values can be any string and total number of all characters cannot
* exceed 500. If provided, the list of waypointNames must be the same length as the list of
* coordinates, but you can skip a coordinate and show its position with the <tt>;</tt> separator.
*
* @param waypointNames Custom names for waypoints used for the arrival instruction.
* @return this builder for chaining options together
* @since 0.15.0
*/
public Builder addWaypointNames(@Nullable String... waypointNames) {
directionsBuilder.addWaypointNames(waypointNames);
return this;
}

/**
* Optionally create a {@link Builder} based on all variables
* from given {@link RouteOptions}.
Expand Down Expand Up @@ -490,6 +525,16 @@ public Builder routeOptions(RouteOptions options) {
directionsBuilder.annotations(options.annotations());
}

if (!TextUtils.isEmpty(options.approaches())) {
String[] approaches = options.approaches().split(";");
directionsBuilder.addApproaches(approaches);
}

if (!TextUtils.isEmpty(options.waypointNames())) {
String[] waypointNames = options.waypointNames().split(";");
directionsBuilder.addWaypointNames(waypointNames);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.Mockito.when;

public class NavigationRouteTest extends BaseTest {

@Mock
private Context context;
@Mock
Expand Down Expand Up @@ -59,6 +60,34 @@ public void changingDefaultValueToCustomWorksProperly() throws Exception {
containsString("/cycling/"));
}

@Test
public void addApproachesIncludedInRequest() {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
.accessToken(ACCESS_TOKEN)
.origin(Point.fromLngLat(1.0, 2.0))
.destination(Point.fromLngLat(1.0, 5.0))
.profile(DirectionsCriteria.PROFILE_CYCLING)
.addApproaches(DirectionsCriteria.APPROACH_CURB, DirectionsCriteria.APPROACH_UNRESTRICTED)
.build();

assertThat(navigationRoute.getCall().request().url().toString(),
containsString("curb"));
}

@Test
public void addWaypointNamesIncludedInRequest() {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
.accessToken(ACCESS_TOKEN)
.origin(Point.fromLngLat(1.0, 2.0))
.destination(Point.fromLngLat(1.0, 5.0))
.profile(DirectionsCriteria.PROFILE_CYCLING)
.addWaypointNames("Origin", "Destination")
.build();

assertThat(navigationRoute.getCall().request().url().toString(),
containsString("Destination"));
}

@Test
public void addingPointAndBearingKeepsCorrectOrder() throws Exception {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
Expand Down Expand Up @@ -102,6 +131,8 @@ public void addRouteOptionsIncludedInRequest() throws Exception {
.voiceUnits(DirectionsCriteria.METRIC)
.user("example_user")
.geometries("mocked_geometries")
.approaches("curb;unrestricted")
.waypointNames("Origin;Destination")
.build();

NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
Expand All @@ -118,5 +149,7 @@ public void addRouteOptionsIncludedInRequest() throws Exception {
assertThat(request, containsString("example_user"));
assertThat(request, containsString("language=en"));
assertThat(request, containsString("walking"));
assertThat(request, containsString("curb"));
assertThat(request, containsString("Origin"));
}
}

0 comments on commit 0b6d774

Please sign in to comment.