diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java index 68d549fc3ec..5b872a54e0a 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java @@ -282,7 +282,7 @@ private void animateCameraForRouteOverview(RouteInformation routeInformation, in CameraUpdate resetUpdate = CameraUpdateFactory.newCameraPosition(resetPosition); List routePoints = cameraEngine.overview(routeInformation); - boolean invalidPoints = routePoints == null || routePoints.isEmpty(); + boolean invalidPoints = routePoints.isEmpty(); if (invalidPoints) { return; } diff --git a/libandroid-navigation-ui/src/main/res/layout/summary_peek_layout.xml b/libandroid-navigation-ui/src/main/res/layout/summary_peek_layout.xml index 8acad1f7b21..e599e133493 100644 --- a/libandroid-navigation-ui/src/main/res/layout/summary_peek_layout.xml +++ b/libandroid-navigation-ui/src/main/res/layout/summary_peek_layout.xml @@ -41,9 +41,9 @@ android:id="@+id/divider" android:layout_width="1dp" android:layout_height="match_parent" - android:layout_marginBottom="8dp" - android:layout_marginTop="8dp" - android:background="@color/md_grey_500" + android:layout_marginBottom="16dp" + android:layout_marginTop="16dp" + android:background="?attr/navigationViewDivider" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/cancelBtn" app:layout_constraintTop_toTopOf="parent"/> diff --git a/libandroid-navigation-ui/src/main/res/values/attrs.xml b/libandroid-navigation-ui/src/main/res/values/attrs.xml index dd5be358fe4..2a3d4742c19 100644 --- a/libandroid-navigation-ui/src/main/res/values/attrs.xml +++ b/libandroid-navigation-ui/src/main/res/values/attrs.xml @@ -30,6 +30,7 @@ + diff --git a/libandroid-navigation-ui/src/main/res/values/colors.xml b/libandroid-navigation-ui/src/main/res/values/colors.xml index 2eaa28a7cdd..c361cb57955 100644 --- a/libandroid-navigation-ui/src/main/res/values/colors.xml +++ b/libandroid-navigation-ui/src/main/res/values/colors.xml @@ -18,6 +18,7 @@ #4882C6 #424242 #424242 + #D8D8D8 #2D3F53 @@ -33,6 +34,7 @@ #FFFFFF #424242 #FFFFFF + #D8D8D8 #2D3F53 diff --git a/libandroid-navigation-ui/src/main/res/values/styles.xml b/libandroid-navigation-ui/src/main/res/values/styles.xml index c91ac9e7189..0e79a6a6dd7 100644 --- a/libandroid-navigation-ui/src/main/res/values/styles.xml +++ b/libandroid-navigation-ui/src/main/res/values/styles.xml @@ -18,6 +18,7 @@ @color/mapbox_navigation_view_color_accent @color/mapbox_navigation_view_color_secondary @color/mapbox_navigation_view_color_accent_text + @color/mapbox_navigation_view_color_divider @color/mapbox_navigation_view_color_list_background @@ -45,6 +46,7 @@ @color/mapbox_navigation_view_color_accent_dark @color/mapbox_navigation_view_color_secondary_dark @color/mapbox_navigation_view_color_accent_text_dark + @color/mapbox_navigation_view_color_divider_dark @color/mapbox_navigation_view_color_list_background_dark diff --git a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenterTest.java b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenterTest.java new file mode 100644 index 00000000000..3f1b1bd3455 --- /dev/null +++ b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenterTest.java @@ -0,0 +1,49 @@ +package com.mapbox.services.android.navigation.ui.v5; + +import org.junit.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class NavigationPresenterTest { + + @Test + public void onRouteOverviewButtonClick_cameraIsAdjustedToRoute() { + NavigationContract.View view = mock(NavigationContract.View.class); + NavigationPresenter presenter = new NavigationPresenter(view); + + presenter.onRouteOverviewClick(); + + verify(view).updateCameraRouteOverview(); + } + + @Test + public void onRouteOverviewButtonClick_recenterBtnIsShown() { + NavigationContract.View view = mock(NavigationContract.View.class); + NavigationPresenter presenter = new NavigationPresenter(view); + + presenter.onRouteOverviewClick(); + + verify(view).showRecenterBtn(); + } + + @Test + public void onRecenterBtnClick_recenterBtnIsHidden() { + NavigationContract.View view = mock(NavigationContract.View.class); + NavigationPresenter presenter = new NavigationPresenter(view); + + presenter.onRecenterClick(); + + verify(view).hideRecenterBtn(); + } + + @Test + public void onRecenterBtnClick_cameraIsResetToTracking() { + NavigationContract.View view = mock(NavigationContract.View.class); + NavigationPresenter presenter = new NavigationPresenter(view); + + presenter.onRecenterClick(); + + verify(view).resetCameraPosition(); + } +} diff --git a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/camera/DynamicCameraTest.java b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/camera/DynamicCameraTest.java index eb3daf1abed..610c97775d9 100644 --- a/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/camera/DynamicCameraTest.java +++ b/libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/camera/DynamicCameraTest.java @@ -8,6 +8,8 @@ import com.mapbox.api.directions.v5.DirectionsAdapterFactory; import com.mapbox.api.directions.v5.models.DirectionsResponse; import com.mapbox.api.directions.v5.models.DirectionsRoute; +import com.mapbox.core.constants.Constants; +import com.mapbox.geojson.LineString; import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.services.android.navigation.ui.v5.BaseTest; @@ -17,9 +19,11 @@ import org.junit.Test; import java.io.IOException; +import java.util.List; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,7 +32,7 @@ public class DynamicCameraTest extends BaseTest { private static final String DIRECTIONS_PRECISION_6 = "directions_v5_precision_6.json"; @Test - public void sanity() throws Exception { + public void sanity() { MapboxMap mapboxMap = mock(MapboxMap.class); DynamicCamera cameraEngine = new DynamicCamera(mapboxMap); @@ -145,6 +149,44 @@ public void onInformationFromLocationAndProgress_engineCreatesCorrectBearing() t assertEquals(100f, bearing, DELTA); } + @Test + public void onInformationFromRoute_engineCreatesOverviewPointList() throws Exception { + MapboxMap mapboxMap = mock(MapboxMap.class); + DynamicCamera cameraEngine = new DynamicCamera(mapboxMap); + DirectionsRoute route = buildDirectionsRoute(); + List routePoints = generateRouteCoordinates(route); + RouteInformation routeInformation = RouteInformation.create(route, null, null); + + List overviewPoints = cameraEngine.overview(routeInformation); + + assertEquals(routePoints, overviewPoints); + } + + @Test + public void onInformationFromRouteProgress_engineCreatesOverviewPointList() throws Exception { + MapboxMap mapboxMap = mock(MapboxMap.class); + DynamicCamera cameraEngine = new DynamicCamera(mapboxMap); + RouteProgress routeProgress = buildDefaultRouteProgress(null); + DirectionsRoute route = routeProgress.directionsRoute(); + List routePoints = generateRouteCoordinates(route); + RouteInformation routeInformation = RouteInformation.create(null, null, routeProgress); + + List overviewPoints = cameraEngine.overview(routeInformation); + + assertEquals(routePoints, overviewPoints); + } + + @Test + public void noRouteInformation_engineCreatesEmptyOverviewPointList() { + MapboxMap mapboxMap = mock(MapboxMap.class); + DynamicCamera cameraEngine = new DynamicCamera(mapboxMap); + RouteInformation routeInformation = RouteInformation.create(null, null, null); + + List overviewPoints = cameraEngine.overview(routeInformation); + + assertTrue(overviewPoints.isEmpty()); + } + private Location buildDefaultLocationUpdate(double lng, double lat) { return buildLocationUpdate(lng, lat, System.currentTimeMillis()); } @@ -173,4 +215,12 @@ private DirectionsRoute buildDirectionsRoute() throws IOException { DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class); return response.routes().get(0); } + + private List generateRouteCoordinates(DirectionsRoute route) { + if (route != null) { + LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); + return lineString.coordinates(); + } + return null; + } } diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/camera/SimpleCamera.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/camera/SimpleCamera.java index d2bb136d677..23a1da09404 100644 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/camera/SimpleCamera.java +++ b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/camera/SimpleCamera.java @@ -6,6 +6,7 @@ import com.mapbox.geojson.Point; import com.mapbox.turf.TurfMeasurement; +import java.util.ArrayList; import java.util.List; /** @@ -18,7 +19,7 @@ public class SimpleCamera extends Camera { private static final int CAMERA_TILT = 50; private static final double CAMERA_ZOOM = 15d; - private List routeCoordinates; + private List routeCoordinates = new ArrayList<>(); private double initialBearing; private DirectionsRoute initialRoute; @@ -65,7 +66,11 @@ public double zoom(RouteInformation routeInformation) { public List overview(RouteInformation routeInformation) { boolean invalidCoordinates = routeCoordinates == null || routeCoordinates.isEmpty(); if (invalidCoordinates) { - return generateRouteCoordinates(routeInformation.route()); + if (routeInformation.route() != null) { + setupLineStringAndBearing(routeInformation.route()); + } else if (routeInformation.routeProgress() != null) { + setupLineStringAndBearing(routeInformation.routeProgress().directionsRoute()); + } } return routeCoordinates; }