Skip to content

Commit

Permalink
Add distance remaining buffer to show first instruction immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jun 21, 2018
1 parent 9bf66aa commit 9dd24aa
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class RouteUtils {

private static final String FORCED_LOCATION = "Forced Location";
private static final int FIRST_COORDINATE = 0;
private static final int ZERO_INSTRUCTIONS = 0;
private static final int ONE_METER_BUFFER = 1;
private static final Set<String> VALID_PROFILES = new HashSet<String>() {
{
add(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
Expand Down Expand Up @@ -177,6 +179,7 @@ public boolean isValidRouteProfile(String routeProfile) {
@Nullable
public BannerInstructions findCurrentBannerInstructions(LegStep currentStep, double stepDistanceRemaining) {
if (isValidStep(currentStep) && hasInstructions(currentStep.bannerInstructions())) {
stepDistanceRemaining = stepDistanceRemaining - ONE_METER_BUFFER; // For showing first banner immediately
List<BannerInstructions> instructions = new ArrayList<>(currentStep.bannerInstructions());
Iterator<BannerInstructions> instructionsIterator = instructions.iterator();
while (instructionsIterator.hasNext()) {
Expand All @@ -187,7 +190,7 @@ public BannerInstructions findCurrentBannerInstructions(LegStep currentStep, dou
}
}
int instructionIndex = checkValidIndex(instructions);
if (instructions.size() > 0) {
if (instructions.size() > ZERO_INSTRUCTIONS) {
return instructions.get(instructionIndex);
}
}
Expand Down Expand Up @@ -238,7 +241,7 @@ public VoiceInstructions findCurrentVoiceInstructions(LegStep currentStep, doubl
}
}
int instructionIndex = checkValidIndex(instructions);
if (instructions.size() > 0) {
if (instructions.size() > ZERO_INSTRUCTIONS) {
return instructions.get(instructionIndex);
}
}
Expand Down

0 comments on commit 9dd24aa

Please sign in to comment.