diff --git a/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java b/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java
index 477d1e7ff..f3662ac85 100644
--- a/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java
+++ b/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java
@@ -41,6 +41,7 @@
import com.mapbox.mapboxandroiddemo.examples.dds.CircleToIconTransitionActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.PropertyIconDeterminationActivity;
import com.mapbox.mapboxandroiddemo.examples.camera.ZoomToShowClusterLeavesActivity;
+import com.mapbox.mapboxandroiddemo.examples.javaservices.DirectionsProfileToggleActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.KotlinBorderedCircleActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.CreateHotspotsActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.DrawGeojsonLineActivity;
@@ -1147,6 +1148,14 @@ private void initializeModels() {
null,
R.string.activity_java_services_static_image_notification_url, true, BuildConfig.MIN_SDK_VERSION));
+ exampleItemModels.add(new ExampleItemModel(
+ R.id.nav_java_services,
+ R.string.activity_java_services_directions_profile_toggle_title,
+ R.string.activity_java_services_directions_profile_toggle_description,
+ new Intent(MainActivity.this, DirectionsProfileToggleActivity.class),
+ null,
+ R.string.activity_java_services_directions_profile_toggle_url, true, BuildConfig.MIN_SDK_VERSION));
+
exampleItemModels.add(new ExampleItemModel(
R.id.nav_snapshot_image_generator,
R.string.activity_image_generator_snapshot_notification_title,
diff --git a/MapboxAndroidDemo/src/main/AndroidManifest.xml b/MapboxAndroidDemo/src/main/AndroidManifest.xml
index fb2796e86..dd0649a26 100644
--- a/MapboxAndroidDemo/src/main/AndroidManifest.xml
+++ b/MapboxAndroidDemo/src/main/AndroidManifest.xml
@@ -1015,6 +1015,14 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
+
+
+
() {
+ @Override
+ public void onResponse(Call call, Response response) {
+ // You can get the generic HTTP info about the response
+ Timber.d("Response code: " + response.code());
+ if (response.body() == null) {
+ Timber.e("No routes found, make sure you set the right user and access token.");
+ return;
+ } else if (response.body().routes().size() < 1) {
+ Timber.e("No routes found");
+ return;
+ }
+
+ switch (profile) {
+ case DirectionsCriteria.PROFILE_DRIVING:
+ drivingRoute = response.body().routes().get(0);
+ drivingButton.setText(String.format(getString(R.string.driving_profile),
+ String.valueOf(TimeUnit.SECONDS.toMinutes(drivingRoute.duration().longValue()))));
+ if (!firstRouteDrawn) {
+ showRouteLine();
+ firstRouteDrawn = true;
+ }
+ break;
+ case DirectionsCriteria.PROFILE_WALKING:
+ walkingRoute = response.body().routes().get(0);
+ walkingButton.setText(String.format(getString(R.string.walking_profile),
+ String.valueOf(TimeUnit.SECONDS
+ .toMinutes(walkingRoute.duration().longValue()))));
+ break;
+ case DirectionsCriteria.PROFILE_CYCLING:
+ cyclingRoute = response.body().routes().get(0);
+ cyclingButton.setText(String.format(getString(R.string.cycling_profile),
+ String.valueOf(TimeUnit.SECONDS
+ .toMinutes(cyclingRoute.duration().longValue()))));
+ break;
+ default:
+ break;
+ }
+ if (fromMapClick) {
+ showRouteLine();
+ }
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable throwable) {
+ Timber.e("Error: " + throwable.getMessage());
+ Toast.makeText(DirectionsProfileToggleActivity.this,
+ "Error: " + throwable.getMessage(),
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mapView.onResume();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mapView.onStart();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mapView.onPause();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // Cancel the Directions API request
+ if (client != null) {
+ client.cancelCall();
+ }
+ if (mapboxMap != null) {
+ mapboxMap.removeOnMapClickListener(this);
+ }
+ mapView.onDestroy();
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mapView.onLowMemory();
+ }
+}
diff --git a/MapboxAndroidDemo/src/main/res/layout/activity_javaservices_directions_profile_toggle.xml b/MapboxAndroidDemo/src/main/res/layout/activity_javaservices_directions_profile_toggle.xml
new file mode 100644
index 000000000..a4d5a5cbf
--- /dev/null
+++ b/MapboxAndroidDemo/src/main/res/layout/activity_javaservices_directions_profile_toggle.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml
index fd09a3e14..625bb1df5 100644
--- a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml
+++ b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml
@@ -462,4 +462,10 @@
Tap on a cluster circle to zoom and fit the bounds to its leaves
+
+
+ %1$sm\nby car
+ %1$sm\non foot
+ %1$sm\nby bike
+ Click on map or buttons to change route
diff --git a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml
index a15ae1fb9..43c8e09bb 100644
--- a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml
+++ b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml
@@ -102,6 +102,7 @@
Use Turf to generate a circle with a radius expressed in physical units and to create an adjustable border
Use Turf to calculate a straight line distance ("as the crow flies") between the device location and the map camera\'s target.
Use the Static Image API to eventually place and continually update an notification image
+ Retrieve Mapbox Directions API routes for different profiles and toggle between them.
Use the traffic plugin to display live car congestion data on top of a map.
Use the building plugin to easily display 3D building height
Add location search ("geocoding") functionality and UI to search for any place in the world
diff --git a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml
index 10c1b12c2..9d0949083 100644
--- a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml
+++ b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml
@@ -102,6 +102,7 @@
Bordered circle
Straight line distance
Static image notification
+ Directions route profiles
Display real-time traffic
Display buildings in 3D
Change map text to device language
diff --git a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml
index 80b68d47b..21c696aba 100644
--- a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml
+++ b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml
@@ -100,6 +100,7 @@
https://i.imgur.com/cCbwj1y.png
https://i.imgur.com/1vGQqBh.png
https://i.imgur.com/crbB91w.png
+ https://i.imgur.com/GckrLt3.png
http://i.imgur.com/HRriOVR.png
http://i.imgur.com/Vcu67UR.png
https://i.imgur.com/oKHx3bv.png