Skip to content

Commit

Permalink
Add divider attribute and adjust divider padding
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jun 6, 2018
1 parent a53f870 commit 386c01d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private void animateCameraForRouteOverview(RouteInformation routeInformation, in
CameraUpdate resetUpdate = CameraUpdateFactory.newCameraPosition(resetPosition);

List<Point> routePoints = cameraEngine.overview(routeInformation);
boolean invalidPoints = routePoints == null || routePoints.isEmpty();
boolean invalidPoints = routePoints.isEmpty();
if (invalidPoints) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
1 change: 1 addition & 0 deletions libandroid-navigation-ui/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<attr name="navigationViewAccent" format="color"/>
<attr name="navigationViewPrimaryText" format="color"/>
<attr name="navigationViewSecondaryText" format="color"/>
<attr name="navigationViewDivider" format="color"/>

<!-- Instruction List -->
<attr name="navigationViewListBackground" format="color"/>
Expand Down
2 changes: 2 additions & 0 deletions libandroid-navigation-ui/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<color name="mapbox_navigation_view_color_accent">#4882C6</color>
<color name="mapbox_navigation_view_color_primary_text">#424242</color>
<color name="mapbox_navigation_view_color_accent_text">#424242</color>
<color name="mapbox_navigation_view_color_divider">#D8D8D8</color>

<color name="mapbox_navigation_view_color_list_background">#2D3F53</color>

Expand All @@ -33,6 +34,7 @@
<color name="mapbox_navigation_view_color_accent_dark">#FFFFFF</color>
<color name="mapbox_navigation_view_color_primary_text_dark">#424242</color>
<color name="mapbox_navigation_view_color_accent_text_dark">#FFFFFF</color>
<color name="mapbox_navigation_view_color_divider_dark">#D8D8D8</color>

<color name="mapbox_navigation_view_color_list_background_dark">#2D3F53</color>

Expand Down
2 changes: 2 additions & 0 deletions libandroid-navigation-ui/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<item name="navigationViewAccent">@color/mapbox_navigation_view_color_accent</item>
<item name="navigationViewPrimaryText">@color/mapbox_navigation_view_color_secondary</item>
<item name="navigationViewSecondaryText">@color/mapbox_navigation_view_color_accent_text</item>
<item name="navigationViewDivider">@color/mapbox_navigation_view_color_divider</item>

<item name="navigationViewListBackground">@color/mapbox_navigation_view_color_list_background</item>

Expand Down Expand Up @@ -45,6 +46,7 @@
<item name="navigationViewAccent">@color/mapbox_navigation_view_color_accent_dark</item>
<item name="navigationViewPrimaryText">@color/mapbox_navigation_view_color_secondary_dark</item>
<item name="navigationViewSecondaryText">@color/mapbox_navigation_view_color_accent_text_dark</item>
<item name="navigationViewDivider">@color/mapbox_navigation_view_color_divider_dark</item>

<item name="navigationViewListBackground">@color/mapbox_navigation_view_color_list_background_dark</item>

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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<Point> routePoints = generateRouteCoordinates(route);
RouteInformation routeInformation = RouteInformation.create(route, null, null);

List<Point> 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<Point> routePoints = generateRouteCoordinates(route);
RouteInformation routeInformation = RouteInformation.create(null, null, routeProgress);

List<Point> 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<Point> overviewPoints = cameraEngine.overview(routeInformation);

assertTrue(overviewPoints.isEmpty());
}

private Location buildDefaultLocationUpdate(double lng, double lat) {
return buildLocationUpdate(lng, lat, System.currentTimeMillis());
}
Expand Down Expand Up @@ -173,4 +215,12 @@ private DirectionsRoute buildDirectionsRoute() throws IOException {
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
return response.routes().get(0);
}

private List<Point> generateRouteCoordinates(DirectionsRoute route) {
if (route != null) {
LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
return lineString.coordinates();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mapbox.geojson.Point;
import com.mapbox.turf.TurfMeasurement;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -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<Point> routeCoordinates;
private List<Point> routeCoordinates = new ArrayList<>();
private double initialBearing;
private DirectionsRoute initialRoute;

Expand Down Expand Up @@ -65,7 +66,11 @@ public double zoom(RouteInformation routeInformation) {
public List<Point> 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;
}
Expand Down

0 comments on commit 386c01d

Please sign in to comment.