-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b978cd
commit 75fc29f
Showing
25 changed files
with
849 additions
and
646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/TestRouteBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Scanner; | ||
|
||
import static okhttp3.internal.Util.UTF_8; | ||
|
||
class TestRouteBuilder { | ||
|
||
String loadJsonFixture(String filename) throws IOException { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
InputStream inputStream = classLoader.getResourceAsStream(filename); | ||
Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A"); | ||
return scanner.hasNext() ? scanner.next() : ""; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
.../src/test/java/com/mapbox/services/android/navigation/ui/v5/TestRouteProgressBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.support.v4.util.Pair; | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
import com.mapbox.api.directions.v5.models.LegStep; | ||
import com.mapbox.api.directions.v5.models.StepIntersection; | ||
import com.mapbox.geojson.Point; | ||
import com.mapbox.geojson.utils.PolylineUtils; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.util.List; | ||
|
||
import static com.mapbox.core.constants.Constants.PRECISION_6; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.createDistancesToIntersections; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.createIntersectionsList; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.findCurrentIntersection; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.findUpcomingIntersection; | ||
|
||
class TestRouteProgressBuilder { | ||
|
||
RouteProgress buildTestRouteProgress(DirectionsRoute route, | ||
double stepDistanceRemaining, | ||
double legDistanceRemaining, | ||
double distanceRemaining, | ||
int stepIndex, | ||
int legIndex) throws Exception { | ||
List<LegStep> steps = route.legs().get(legIndex).steps(); | ||
LegStep currentStep = steps.get(stepIndex); | ||
String currentStepGeometry = currentStep.geometry(); | ||
List<Point> currentStepPoints = buildStepPointsFromGeometry(currentStepGeometry); | ||
int upcomingStepIndex = stepIndex + 1; | ||
List<Point> upcomingStepPoints = null; | ||
LegStep upcomingStep = null; | ||
if (upcomingStepIndex < steps.size()) { | ||
upcomingStep = steps.get(upcomingStepIndex); | ||
String upcomingStepGeometry = upcomingStep.geometry(); | ||
upcomingStepPoints = buildStepPointsFromGeometry(upcomingStepGeometry); | ||
} | ||
List<StepIntersection> intersections = createIntersectionsList(currentStep, upcomingStep); | ||
List<Pair<StepIntersection, Double>> intersectionDistances = createDistancesToIntersections( | ||
currentStepPoints, intersections | ||
); | ||
|
||
double stepDistanceTraveled = currentStep.distance() - stepDistanceRemaining; | ||
StepIntersection currentIntersection = findCurrentIntersection(intersections, | ||
intersectionDistances, stepDistanceTraveled | ||
); | ||
StepIntersection upcomingIntersection = findUpcomingIntersection( | ||
intersections, upcomingStep, currentIntersection | ||
); | ||
|
||
return RouteProgress.builder() | ||
.stepDistanceRemaining(stepDistanceRemaining) | ||
.legDistanceRemaining(legDistanceRemaining) | ||
.distanceRemaining(distanceRemaining) | ||
.directionsRoute(route) | ||
.currentStepPoints(currentStepPoints) | ||
.upcomingStepPoints(upcomingStepPoints) | ||
.intersections(intersections) | ||
.currentIntersection(currentIntersection) | ||
.upcomingIntersection(upcomingIntersection) | ||
.intersectionDistancesAlongStep(intersectionDistances) | ||
.stepIndex(stepIndex) | ||
.legIndex(legIndex) | ||
.build(); | ||
} | ||
|
||
private List<Point> buildStepPointsFromGeometry(String stepGeometry) { | ||
return PolylineUtils.decode(stepGeometry, PRECISION_6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.