Skip to content

Commit

Permalink
Create default instructions in MapboxNavigation and rename defaultMil…
Browse files Browse the repository at this point in the history
…estone boolean
  • Loading branch information
danesfeder committed Jul 11, 2017
1 parent e854588 commit 28d99c6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

import com.mapbox.services.Experimental;
import com.mapbox.services.android.location.LostLocationEngine;
import com.mapbox.services.android.navigation.v5.instruction.defaultinstructions.ArrivalInstruction;
import com.mapbox.services.android.navigation.v5.instruction.defaultinstructions.DepartureInstruction;
import com.mapbox.services.android.navigation.v5.instruction.defaultinstructions.ImminentInstruction;
import com.mapbox.services.android.navigation.v5.instruction.defaultinstructions.NewStepInstruction;
import com.mapbox.services.android.navigation.v5.instruction.defaultinstructions.UrgentInstruction;
import com.mapbox.services.android.navigation.v5.instruction.Instruction;
import com.mapbox.services.android.navigation.v5.instruction.DefaultInstructionEngine;
import com.mapbox.services.android.navigation.v5.listeners.NavigationEventListener;
import com.mapbox.services.android.navigation.v5.offroute.OffRouteListener;
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener;
Expand Down Expand Up @@ -111,7 +108,7 @@ public MapboxNavigation(@NonNull Context context, @NonNull String accessToken,
milestoneEventListeners = new CopyOnWriteArrayList<>();
milestones = new CopyOnWriteArrayList<>();

if (!options.defaultInstructionsDisabled()) {
if (options.defaultMilestonesEnabled()) {
addDefaultMilestones();
}
}
Expand Down Expand Up @@ -176,6 +173,82 @@ private void addDefaultMilestones() {
).build());
}

/**
* Used to provide the {@link String} instruction in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* for Arrival Milestones
*
* @since 0.4.0
*/
private class ArrivalInstruction extends Instruction {

@Override
public String buildInstruction(RouteProgress routeProgress) {
return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.ARRIVAL_MILESTONE);
}
}

/**
* Used to provide the {@link String} instruction in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* for Departure Milestones
*
* @since 0.4.0
*/
private class DepartureInstruction extends Instruction {

@Override
public String buildInstruction(RouteProgress routeProgress) {
return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.DEPARTURE_MILESTONE);
}
}

/**
* Used to provide the {@link String} instruction in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* for Imminent Milestones
*
* @since 0.4.0
*/
private class ImminentInstruction extends Instruction {

@Override
public String buildInstruction(RouteProgress routeProgress) {
return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.IMMINENT_MILESTONE);
}
}

/**
* Used to provide the {@link String} instruction in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* for New Step Milestones
*
* @since 0.4.0
*/
private class NewStepInstruction extends Instruction {

@Override
public String buildInstruction(RouteProgress routeProgress) {
return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.NEW_STEP_MILESTONE);
}
}

/**
* Used to provide the {@link String} instruction in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* for Urgent Milestones
*
* @since 0.4.0
*/
private class UrgentInstruction extends Instruction {

@Override
public String buildInstruction(RouteProgress routeProgress) {
return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.URGENT_MILESTONE);
}

}

@Override
public void onMilestoneEvent(RouteProgress routeProgress, String instruction, int identifier) {
if (identifier == NavigationConstants.ARRIVAL_MILESTONE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MapboxNavigationOptions {
private double userLocationSnapDistance;
private int secondsBeforeReroute;

private boolean defaultInstructionsDisabled = false;
private boolean defaultMilestonesEnabled = true;

@NavigationProfiles.Profile
private String profile;
Expand Down Expand Up @@ -115,8 +115,14 @@ public MapboxNavigationOptions setMaxManipulatedCourseAngle(
return this;
}

public void setDefaultInstructionsDisabled(boolean disabled) {
this.defaultInstructionsDisabled = disabled;
/**
* Will create a set of pre-defined Milestones for basic updates while navigating along a route.
*
* @param enabled - will create default milestones (default)
* @since 0.4.0
*/
public void setDefaultMilestonesEnabled(boolean enabled) {
this.defaultMilestonesEnabled = enabled;
}

/*
Expand Down Expand Up @@ -193,8 +199,8 @@ public double getUserLocationSnapDistance() {
return userLocationSnapDistance;
}

public boolean defaultInstructionsDisabled() {
return defaultInstructionsDisabled;
public boolean defaultMilestonesEnabled() {
return defaultMilestonesEnabled;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions;
package com.mapbox.services.android.navigation.v5.instruction;

import android.text.TextUtils;
import android.util.SparseArray;
Expand All @@ -17,7 +17,7 @@
*
* @since 0.4.0
*/
class DefaultInstructionEngine extends SparseArray<DefaultInstructionEngine.InstructionBuilder> {
public class DefaultInstructionEngine extends SparseArray<DefaultInstructionEngine.InstructionBuilder> {

private static final double MINIMUM_UPCOMING_STEP_DISTANCE = 15d;
private static final String DECIMAL_FORMAT = "###.#";
Expand All @@ -44,7 +44,7 @@ private DefaultInstructionEngine() {
* @return {@link String} instruction that has been created by the engine
* @since 0.4.0
*/
static String createInstruction(RouteProgress routeProgress, int identifier) {
public static String createInstruction(RouteProgress routeProgress, int identifier) {
DefaultInstructionEngine defaultInstructionEngine = new DefaultInstructionEngine();
if (defaultInstructionEngine.get(identifier) != null) {
return defaultInstructionEngine.get(identifier).build(routeProgress);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 28d99c6

Please sign in to comment.