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 @@ + + + + + +