diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Milestone.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Milestone.java index 6693af52188..5ccb2d63fb6 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Milestone.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Milestone.java @@ -19,8 +19,8 @@ public Milestone(Builder builder) { } /** - * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. + * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone + * invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. * * @return {@code int} representing the identifier * @since 0.4.0 @@ -31,7 +31,7 @@ public int getIdentifier() { /** * Milestone specific {@link Instruction}, which can be used to build a {@link String} - * instruction specified by the superclass + * instruction specified by the superclass. * * @return {@link Instruction} to be used to build the {@link String} passed to * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} @@ -46,13 +46,14 @@ public Instruction getInstruction() { * {@link com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation} object * (recommended) or validated directly inside your activity. * - * @param previousRouteProgress last locations generated {@link RouteProgress} object used to determine certain - * {@link TriggerProperty}s + * @param previousRouteProgress last locations generated {@link RouteProgress} object used to + * determine certain {@link TriggerProperty}s * @param routeProgress used to determine certain {@link TriggerProperty}s * @return true if the milestone trigger's valid, else false * @since 0.4.0 */ - public abstract boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress routeProgress); + public abstract boolean isOccurring(RouteProgress previousRouteProgress, + RouteProgress routeProgress); /** * Build a new {@link Milestone} @@ -68,8 +69,8 @@ public Builder() { } /** - * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. + * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone + * invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. * * @return {@code int} representing the identifier * @since 0.4.0 @@ -79,8 +80,8 @@ public int getIdentifier() { } /** - * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked - * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. + * Milestone specific identifier as an {@code int} value, useful for deciphering which milestone + * invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}. * * @param identifier an {@code int} used to identify this milestone instance * @return this builder @@ -126,7 +127,6 @@ public Builder setInstruction(Instruction instruction) { * @throws NavigationException if an invalid value has been set on the milestone * @since 0.4.0 */ - public abstract Milestone build() throws NavigationException; + public abstract Milestone build(); } - } diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Operation.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Operation.java index 563ca742135..545befc4612 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Operation.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Operation.java @@ -7,12 +7,16 @@ */ class Operation { + private Operation() { + // Private constructor to prevent initialization of class. + } + static boolean greaterThan(Number[] valueOne, Number valueTwo) { if (valueOne.length > 1) { if (valueTwo.equals(TriggerProperty.TRUE)) { return valueOne[0].doubleValue() > valueOne[1].doubleValue(); } else { - return !(valueOne[0].doubleValue() > valueOne[1].doubleValue()); + return valueOne[0].doubleValue() <= valueOne[1].doubleValue(); } } return valueOne[0].doubleValue() > valueTwo.doubleValue(); @@ -23,7 +27,7 @@ static boolean lessThan(Number[] valueOne, Number valueTwo) { if (valueTwo.equals(TriggerProperty.TRUE)) { return valueOne[0].doubleValue() < valueOne[1].doubleValue(); } else { - return !(valueOne[0].doubleValue() < valueOne[1].doubleValue()); + return valueOne[0].doubleValue() >= valueOne[1].doubleValue(); } } return valueOne[0].doubleValue() < valueTwo.doubleValue(); @@ -56,7 +60,7 @@ static boolean greaterThanEqual(Number[] valueOne, Number valueTwo) { if (valueTwo.equals(TriggerProperty.TRUE)) { return valueOne[0].doubleValue() >= valueOne[1].doubleValue(); } else { - return !(valueOne[0].doubleValue() >= valueOne[1].doubleValue()); + return valueOne[0].doubleValue() < valueOne[1].doubleValue(); } } return valueOne[0].doubleValue() >= valueTwo.doubleValue(); @@ -67,7 +71,7 @@ static boolean lessThanEqual(Number[] valueOne, Number valueTwo) { if (valueTwo.equals(TriggerProperty.TRUE)) { return valueOne[0].doubleValue() <= valueOne[1].doubleValue(); } else { - return !(valueOne[0].doubleValue() <= valueOne[1].doubleValue()); + return valueOne[0].doubleValue() > valueOne[1].doubleValue(); } } return valueOne[0].doubleValue() <= valueTwo.doubleValue(); diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/RouteMilestone.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/RouteMilestone.java index f24dd3d9ae1..cb9d9e723cc 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/RouteMilestone.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/RouteMilestone.java @@ -1,17 +1,16 @@ package com.mapbox.services.android.navigation.v5.milestone; -import com.mapbox.services.android.navigation.v5.exception.NavigationException; import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; /** - * Using a Route Milestone will result in {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} - * being invoked only once during a navigation session. + * Using a Route Milestone will result in + * {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} being invoked only + * once during a navigation session. * * @since 0.4.0 */ public class RouteMilestone extends Milestone { - private Builder builder; private boolean called; @@ -56,7 +55,7 @@ Trigger.Statement getTrigger() { } @Override - public RouteMilestone build() throws NavigationException { + public RouteMilestone build() { return new RouteMilestone(this); } } diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Trigger.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Trigger.java index 4aa8552eea2..b53b0219816 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Trigger.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/milestone/Trigger.java @@ -11,6 +11,10 @@ */ public class Trigger { + private Trigger() { + // Empty private constructor to prevent users creating an instance of this class. + } + /** * Base Trigger statement. Subclassed to provide concrete statements. * diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.java index 6b3ccdf021e..299224918de 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.java @@ -7,58 +7,118 @@ */ public class NavigationConstants { + private NavigationConstants() { + // Empty private constructor to prevent users creating an instance of this class. + } + + /** + * Identifier value for the default departure milestone event. If additional milestones are added, + * avoid using the 1-5 integer values as identifiers. + * + * @since 0.4.0 + */ public static final int DEPARTURE_MILESTONE = 1; + + /** + * Identifier value for the default new step milestone event. If additional milestones are added, + * avoid using the 1-5 integer values as identifiers. + * + * @since 0.4.0 + */ public static final int NEW_STEP_MILESTONE = 2; + + /** + * Identifier value for the default imminent milestone event. If additional milestones are added, + * avoid using the 1-5 integer values as identifiers. + * + * @since 0.4.0 + */ public static final int IMMINENT_MILESTONE = 3; + + /** + * Identifier value for the default urgent milestone event. If additional milestones are added, + * avoid using the 1-5 integer values as identifiers. + * + * @since 0.4.0 + */ public static final int URGENT_MILESTONE = 4; + + /** + * Identifier value for the default arrival milestone event. If additional milestones are added, + * avoid using the 1-5 integer values as identifiers. + * + * @since 0.4.0 + */ public static final int ARRIVAL_MILESTONE = 5; /** * Random integer value used for identifying the navigation notification. + * + * @since 0.5.0 */ static final int NAVIGATION_NOTIFICATION_ID = 5678; /** - * Threshold user must be in within to count as completing a step. One of two heuristics used to know when a user - * completes a step, see `RouteControllerManeuverZoneRadius`. The users `heading` and the `finalHeading` are - * compared. If this number is within `RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion`, the user has + * Threshold user must be within to count as completing a step. One of two heuristics used to know + * when a user completes a step, see {@link #MANEUVER_ZONE_RADIUS}. The users heading and the + * finalHeading are compared. If this number is within this defined constant, the user has * completed the step. + * + * @since 0.1.0 */ static final int MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION = 30; /** - * Radius in meters the user must enter to count as completing a step. One of two heuristics used to know when a user - * completes a step, see `RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion`. + * Radius in meters the user must enter to count as completing a step. One of two heuristics used + * to know when a user completes a step, see + * {@link #MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION}. + * + * @since 0.1.0 */ static final int MANEUVER_ZONE_RADIUS = 40; /** * Maximum number of meters the user can travel away from step before the * {@link OffRouteListener}'s called. + * + * @since 0.2.0 */ static final double MAXIMUM_DISTANCE_BEFORE_OFF_ROUTE = 20; /** * Seconds used before a reroute occurs. + * + * @since 0.2.0 */ static final int SECONDS_BEFORE_REROUTE = 3; /** * Accepted deviation excluding horizontal accuracy before the user is considered to be off route. + * + * @since 0.1.0 */ static final double USER_LOCATION_SNAPPING_DISTANCE = 10; /** - * When calculating whether or not the user is on the route, we look where the user will be given their speed and - * this variable. + * When calculating whether or not the user is on the route, we look where the user will be given + * their speed and this variable. + * + * @since 0.2.0 */ static final double DEAD_RECKONING_TIME_INTERVAL = 1.0; /** * Maximum angle the user puck will be rotated when snapping the user's course to the route line. + * + * @since 0.3.0 */ static final int MAX_MANIPULATED_COURSE_ANGLE = 25; + /** + * Meter radius which the user must be inside for an arrival milestone to be triggered and + * navigation to end. + * + */ static final double METERS_REMAINING_TILL_ARRIVAL = 40; // Bundle variable keys diff --git a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationHelper.java b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationHelper.java index f0ba15750a3..846bb7cb94f 100644 --- a/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationHelper.java +++ b/navigation/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationHelper.java @@ -28,6 +28,10 @@ */ class NavigationHelper { + private NavigationHelper() { + // Empty private constructor to prevent users creating an instance of this class. + } + /** * Takes in a raw location, converts it to a point, and snaps it to the closest point along the * route. This is isolated as separate logic from the snap logic provided because we will always @@ -121,7 +125,8 @@ static double routeDistanceRemaining(double legDistanceRemaining, int legIndex, * @return boolean true if the user location matches (using a tolerance) the final heading * @since 0.2.0 */ - static boolean bearingMatchesManeuverFinalHeading(Location userLocation, RouteProgress routeProgress, + static boolean bearingMatchesManeuverFinalHeading(Location userLocation, + RouteProgress routeProgress, double maxTurnCompletionOffset) { if (routeProgress.currentLegProgress().upComingStep() == null) { return false; @@ -129,7 +134,8 @@ static boolean bearingMatchesManeuverFinalHeading(Location userLocation, RoutePr // Bearings need to be normalized so when the bearingAfter is 359 and the user heading is 1, we // count this as within the MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION. - double finalHeading = routeProgress.currentLegProgress().upComingStep().getManeuver().getBearingAfter(); + double finalHeading = routeProgress.currentLegProgress().upComingStep().getManeuver() + .getBearingAfter(); double finalHeadingNormalized = MathUtils.wrap(finalHeading, 0, 360); double userHeadingNormalized = MathUtils.wrap(userLocation.getBearing(), 0, 360); return MathUtils.differenceBetweenAngles(finalHeadingNormalized, userHeadingNormalized) @@ -150,10 +156,12 @@ static boolean bearingMatchesManeuverFinalHeading(Location userLocation, RoutePr * @param previousIndices used for adjusting the indices * @return a {@link NavigationIndices} object which contains the new leg and step indices */ - static NavigationIndices increaseIndex(RouteProgress routeProgress, NavigationIndices previousIndices) { + static NavigationIndices increaseIndex(RouteProgress routeProgress, + NavigationIndices previousIndices) { // Check if we are in the last step in the current routeLeg and iterate it if needed. if (previousIndices.stepIndex() - >= routeProgress.directionsRoute().getLegs().get(routeProgress.legIndex()).getSteps().size() - 2 + >= routeProgress.directionsRoute().getLegs().get(routeProgress.legIndex()) + .getSteps().size() - 2 && previousIndices.legIndex() < routeProgress.directionsRoute().getLegs().size() - 1) { return NavigationIndices.create((previousIndices.legIndex() + 1), 0); } @@ -161,7 +169,8 @@ static NavigationIndices increaseIndex(RouteProgress routeProgress, NavigationIn } static List checkMilestones(RouteProgress previousRouteProgress, - RouteProgress routeProgress, MapboxNavigation mapboxNavigation) { + RouteProgress routeProgress, + MapboxNavigation mapboxNavigation) { List milestones = new ArrayList<>(); for (Milestone milestone : mapboxNavigation.getMilestones()) { if (milestone.isOccurring(previousRouteProgress, routeProgress)) { @@ -192,6 +201,6 @@ static Position nextManeuverPosition(int stepIndex, List steps, List (stepIndex + 1)) { return steps.get(stepIndex + 1).getManeuver().asPosition(); } - return coords.size() >= 1 ? coords.get(coords.size() - 1) : coords.get(coords.size()); + return !coords.isEmpty() ? coords.get(coords.size() - 1) : coords.get(coords.size()); } }