diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/TunnelMilestone.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/TunnelMilestone.java deleted file mode 100644 index 42db29852d3..00000000000 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/TunnelMilestone.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.mapbox.services.android.navigation.v5.milestone; - -import android.support.annotation.NonNull; -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.api.directions.v5.models.VoiceInstructions; -import com.mapbox.geojson.LineString; -import com.mapbox.geojson.Point; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; -import com.mapbox.turf.TurfConstants; -import com.mapbox.turf.TurfMeasurement; -import com.mapbox.turf.TurfMisc; - -import java.util.ArrayList; -import java.util.List; - -public class TunnelMilestone extends Milestone { - - private static final int FIRST_STEP_INDEX = 0; - private static final String CLASS_TUNNEL = "tunnel"; - - private String announcement; - private String ssmlAnnouncement; - private DirectionsRoute currentRoute; - private LegStep currentStep; - private List stepVoiceInstructions; - - TunnelMilestone(Builder builder) { - super(builder); - } - - @Override - public boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress routeProgress) { - if (newRoute(routeProgress)) { - clearInstructionList(); - } - if (shouldAddInstructions(routeProgress)) { - stepVoiceInstructions = routeProgress.currentLegProgress().currentStep().voiceInstructions(); - } - for (VoiceInstructions voice : stepVoiceInstructions) { - if (shouldBeVoiced(routeProgress, voice)) { - announcement = voice.announcement(); - ssmlAnnouncement = voice.ssmlAnnouncement(); - stepVoiceInstructions.remove(voice); - return true; - } - } - return false; - } - - @Override - public Instruction getInstruction() { - return new Instruction() { - @Override - public String buildInstruction(RouteProgress routeProgress) { - return announcement; - } - }; - } - - /** - * Provide the SSML instruction that can be used with Amazon's AWS Polly. - *

- * This String will provide special markup denoting how certain portions of the announcement - * should be pronounced. - * - * @return announcement with SSML markup - * @since 0.8.0 - */ - public String getSsmlAnnouncement() { - return ssmlAnnouncement; - } - - /** - * Check if a new set of step instructions should be set. - * - * @param routeProgress the current route progress - * @return true if new instructions should be added to the list, false if not - */ - private boolean shouldAddInstructions(RouteProgress routeProgress) { - return newStep(routeProgress) || stepVoiceInstructions == null; - } - - /** - * Called when adding new instructions to the list. - *

- * Make sure old announcements are not called (can happen in reroute scenarios). - */ - private void clearInstructionList() { - if (stepVoiceInstructions != null && !stepVoiceInstructions.isEmpty()) { - stepVoiceInstructions.clear(); - } - } - - /** - * Looks to see if we have a new step. - * - * @param routeProgress provides updated step information - * @return true if new step, false if not - */ - private boolean newStep(RouteProgress routeProgress) { - boolean newStep = currentStep == null || !currentStep.equals(routeProgress.currentLegProgress().currentStep()); - currentStep = routeProgress.currentLegProgress().currentStep(); - return newStep; - } - - /** - * Looks to see if we have a new route. - * - * @param routeProgress provides updated route information - * @return true if new route, false if not - */ - private boolean newRoute(RouteProgress routeProgress) { - boolean newRoute = currentRoute == null || !currentRoute.equals(routeProgress.directionsRoute()); - currentRoute = routeProgress.directionsRoute(); - return newRoute; - } - - /** - * Uses the current step distance remaining to check against voice instruction distance. - * - * @param routeProgress the current route progress - * @param voice a given voice instruction from the list of step instructions - * @return true if time to voice the announcement, false if not - */ - private boolean shouldBeVoiced(RouteProgress routeProgress, VoiceInstructions voice) { - return voice.distanceAlongGeometry() - >= routeProgress.currentLegProgress().currentStepProgress().distanceRemaining(); - } - - @NonNull - private List createTunnelIntersectionsList(LegStep step) { - List tunnelIntersections = new ArrayList<>(); - if (step.intersections().isEmpty()) { - return tunnelIntersections; - } - for (StepIntersection intersection : step.intersections()) { - boolean hasValidClasses = intersection.classes() != null && !intersection.classes().isEmpty(); - if (hasValidClasses) { - for (String intersectionClass : intersection.classes()) { - if (intersectionClass.contentEquals(CLASS_TUNNEL)) { - tunnelIntersections.add(intersection); - } - } - } - } - return tunnelIntersections; - } - - @NonNull - private List> createDistancesToTunnelIntersections(LegStep step, - List stepPoints, - List tunnels) { - List> distancesToTunnelIntersections = new ArrayList<>(); - if (stepPoints.isEmpty()) { - return distancesToTunnelIntersections; - } - if (tunnels.isEmpty()) { - return distancesToTunnelIntersections; - } - List stepIntersections = step.intersections(); - if (stepIntersections == null || stepIntersections.isEmpty()) { - return distancesToTunnelIntersections; - } - - LineString stepLineString = LineString.fromLngLats(stepPoints); - Point firstStepPoint = stepPoints.get(FIRST_STEP_INDEX); - - for (int i = 0; i < tunnels.size(); i++) { - StepIntersection tunnelIntersection = tunnels.get(i); - - Point tunnelBeginningPoint = tunnelIntersection.location(); - LineString beginningLineString = TurfMisc.lineSlice(firstStepPoint, tunnelBeginningPoint, stepLineString); - double distanceToBeginningOfTunnel = TurfMeasurement.length(beginningLineString, TurfConstants.UNIT_METERS); - - int tunnelIntersectionIndex = stepIntersections.indexOf(tunnelIntersection); - Point tunnelEndingPoint = stepIntersections.get(tunnelIntersectionIndex + 1).location(); - LineString endLineString = TurfMisc.lineSlice(firstStepPoint, tunnelEndingPoint, stepLineString); - double distanceToEndOfTunnel = TurfMeasurement.length(endLineString, TurfConstants.UNIT_METERS); - - distancesToTunnelIntersections.add(new Pair<>(distanceToBeginningOfTunnel, distanceToEndOfTunnel)); - } - return distancesToTunnelIntersections; - } - - public static final class Builder extends Milestone.Builder { - - private Trigger.Statement trigger; - - public Builder() { - super(); - } - - @Override - Trigger.Statement getTrigger() { - return trigger; - } - - @Override - public Builder setTrigger(Trigger.Statement trigger) { - this.trigger = trigger; - return this; - } - - @Override - public TunnelMilestone build() { - return new TunnelMilestone(this); - } - } -} \ No newline at end of file