forked from mapbox/mapbox-navigation-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mapbox/mapbox-navigation-…
…android into fix-build * 'master' of https://github.com/mapbox/mapbox-navigation-android: Adjust API Milestone to handle new routes (mapbox#425) Cancel notification when the service is destroyed, not just when notification button is clicked (mapbox#409) adds validation utils class (mapbox#424) Wait for map style to load before initializing run time styling (mapbox#423) Changed up NavigationRoute (mapbox#413) # Conflicts: # libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationRoute.java
- Loading branch information
Showing
12 changed files
with
527 additions
and
123 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
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
64 changes: 0 additions & 64 deletions
64
...ation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/ApiMilestone.java
This file was deleted.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
...n/java/com/mapbox/services/android/navigation/v5/milestone/VoiceInstructionMilestone.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,123 @@ | ||
package com.mapbox.services.android.navigation.v5.milestone; | ||
|
||
import android.text.TextUtils; | ||
|
||
import com.mapbox.directions.v5.models.VoiceInstructions; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.util.List; | ||
|
||
public class VoiceInstructionMilestone extends Milestone { | ||
|
||
private String announcement; | ||
private List<VoiceInstructions> stepVoiceInstructions; | ||
|
||
public VoiceInstructionMilestone(Builder builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress routeProgress) { | ||
if (shouldAddInstructions(previousRouteProgress, routeProgress)) { | ||
clearInstructionList(); | ||
stepVoiceInstructions = routeProgress.currentLegProgress().currentStep().voiceInstructions(); | ||
} | ||
for (VoiceInstructions voice : stepVoiceInstructions) { | ||
if (shouldBeVoiced(routeProgress, voice)) { | ||
announcement = voice.announcement(); | ||
stepVoiceInstructions.remove(voice); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public String announcement() { | ||
return announcement; | ||
} | ||
|
||
/** | ||
* Check if a new set of step instructions should be set. | ||
* | ||
* @param previousRouteProgress most recent progress before the current progress | ||
* @param routeProgress the current route progress | ||
* @return true if new instructions should be added to the list, false if not | ||
*/ | ||
private boolean shouldAddInstructions(RouteProgress previousRouteProgress, RouteProgress routeProgress) { | ||
return newStep(previousRouteProgress, routeProgress) | ||
|| newRoute(previousRouteProgress, routeProgress) | ||
|| stepVoiceInstructions == null; | ||
} | ||
|
||
/** | ||
* Called when adding new instructions to the list. | ||
* <p> | ||
* Make sure old announcements are not called (can happen in reroute scenarios). | ||
*/ | ||
private void clearInstructionList() { | ||
if (stepVoiceInstructions != null && !stepVoiceInstructions.isEmpty()) { | ||
stepVoiceInstructions.clear(); | ||
} | ||
} | ||
|
||
/** | ||
* Used to check for a new route. Route geometries will be the same only on the first | ||
* update. This is because the previousRouteProgress is reset and the current routeProgress is generated | ||
* from the previous. | ||
* | ||
* @param previousRouteProgress most recent progress before the current progress | ||
* @param routeProgress the current route progress | ||
* @return true if there's a new route, false if not | ||
*/ | ||
private boolean newRoute(RouteProgress previousRouteProgress, RouteProgress routeProgress) { | ||
return TextUtils.equals(previousRouteProgress.directionsRoute().geometry(), | ||
routeProgress.directionsRoute().geometry()); | ||
} | ||
|
||
/** | ||
* @param previousRouteProgress most recent progress before the current progress | ||
* @param routeProgress the current route progress | ||
* @return true if on a new step, false if not | ||
*/ | ||
private boolean newStep(RouteProgress previousRouteProgress, RouteProgress routeProgress) { | ||
return previousRouteProgress.currentLegProgress().stepIndex() | ||
< routeProgress.currentLegProgress().stepIndex(); | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
|
||
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 VoiceInstructionMilestone build() { | ||
return new VoiceInstructionMilestone(this); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.