diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigation.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigation.java index 155bda21aab..3575e2ecdd2 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigation.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigation.java @@ -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; @@ -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(); } } @@ -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) { diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigationOptions.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigationOptions.java index cb534eea452..fe8d067ebf2 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigationOptions.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/MapboxNavigationOptions.java @@ -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; @@ -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; } /* @@ -193,8 +199,8 @@ public double getUserLocationSnapDistance() { return userLocationSnapDistance; } - public boolean defaultInstructionsDisabled() { - return defaultInstructionsDisabled; + public boolean defaultMilestonesEnabled() { + return defaultMilestonesEnabled; } /** diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DefaultInstructionEngine.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/DefaultInstructionEngine.java similarity index 97% rename from navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DefaultInstructionEngine.java rename to navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/DefaultInstructionEngine.java index c1dedcd4fc4..db559b5149e 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DefaultInstructionEngine.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/DefaultInstructionEngine.java @@ -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; @@ -17,7 +17,7 @@ * * @since 0.4.0 */ -class DefaultInstructionEngine extends SparseArray { +public class DefaultInstructionEngine extends SparseArray { private static final double MINIMUM_UPCOMING_STEP_DISTANCE = 15d; private static final String DECIMAL_FORMAT = "###.#"; @@ -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); diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ArrivalInstruction.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ArrivalInstruction.java deleted file mode 100644 index bba51415e21..00000000000 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ArrivalInstruction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions; - -import com.mapbox.services.android.navigation.v5.NavigationConstants; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; - -/** - * Used to provide the {@link String} instruction in - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * for Arrival Milestones - * - * @since 0.4.0 - */ -public class ArrivalInstruction extends Instruction { - - @Override - public String buildInstruction(RouteProgress routeProgress) { - return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.ARRIVAL_MILESTONE); - } -} diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DepartureInstruction.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DepartureInstruction.java deleted file mode 100644 index 98455aacc6e..00000000000 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/DepartureInstruction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions; - -import com.mapbox.services.android.navigation.v5.NavigationConstants; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; - -/** - * Used to provide the {@link String} instruction in - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * for Departure Milestones - * - * @since 0.4.0 - */ -public class DepartureInstruction extends Instruction { - - @Override - public String buildInstruction(RouteProgress routeProgress) { - return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.DEPARTURE_MILESTONE); - } -} diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ImminentInstruction.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ImminentInstruction.java deleted file mode 100644 index 97683792b1b..00000000000 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/ImminentInstruction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions; - -import com.mapbox.services.android.navigation.v5.NavigationConstants; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; - -/** - * Used to provide the {@link String} instruction in - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * for Imminent Milestones - * - * @since 0.4.0 - */ -public class ImminentInstruction extends Instruction { - - @Override - public String buildInstruction(RouteProgress routeProgress) { - return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.IMMINENT_MILESTONE); - } -} diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/NewStepInstruction.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/NewStepInstruction.java deleted file mode 100644 index 6b22915d747..00000000000 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/NewStepInstruction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions; - -import com.mapbox.services.android.navigation.v5.NavigationConstants; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; - -/** - * Used to provide the {@link String} instruction in - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * for New Step Milestones - * - * @since 0.4.0 - */ -public class NewStepInstruction extends Instruction { - - @Override - public String buildInstruction(RouteProgress routeProgress) { - return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.NEW_STEP_MILESTONE); - } -} diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/UrgentInstruction.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/UrgentInstruction.java deleted file mode 100644 index cffea12c355..00000000000 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/instruction/defaultinstructions/UrgentInstruction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.services.android.navigation.v5.instruction.defaultinstructions; - -import com.mapbox.services.android.navigation.v5.NavigationConstants; -import com.mapbox.services.android.navigation.v5.instruction.Instruction; -import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; -import com.mapbox.services.android.navigation.v5.milestone.MilestoneEventListener; - -/** - * Used to provide the {@link String} instruction in - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * for Urgent Milestones - * - * @since 0.4.0 - */ -public class UrgentInstruction extends Instruction { - - @Override - public String buildInstruction(RouteProgress routeProgress) { - return DefaultInstructionEngine.createInstruction(routeProgress, NavigationConstants.URGENT_MILESTONE); - } -}