clean up RoutingHelper's isDeviatedFromRoute status

This commit is contained in:
sonora 2016-07-20 10:30:17 +02:00
parent a1c2d57356
commit 90144f3871
3 changed files with 17 additions and 14 deletions

View file

@ -73,7 +73,7 @@ public class RoutingHelper {
private OsmandSettings settings;
private RouteProvider provider;
private VoiceRouter voiceRouter;
private static VoiceRouter voiceRouter;
private boolean isDeviatedFromRoute = false;
private long deviateFromRouteDetected = 0;
@ -295,6 +295,9 @@ public class RoutingHelper {
}
boolean calculateRoute = false;
synchronized (this) {
isDeviatedFromRoute = false;
double distOrth = 0;
// 0. Route empty or needs to be extended? Then re-calculate route.
if(route.isEmpty()) {
calculateRoute = true;
@ -310,35 +313,35 @@ public class RoutingHelper {
// 2. Analyze if we need to recalculate route
// >100m off current route (sideways)
if (currentRoute > 0) {
double dist = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (dist > (1.7 * posTolerance))) {
log.info("Recalculate route, because correlation : " + dist); //$NON-NLS-1$
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) {
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
isDeviatedFromRoute = true;
calculateRoute = true;
}
if(dist > 350) {
if (isFollowingMode) {
voiceRouter.announceOffRoute(dist);
}
}
}
// 3. Identify wrong movement direction
Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance))) {
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
isDeviatedFromRoute = true;
calculateRoute = true;
}
// 4. Identify if UTurn is needed
boolean uTurnIsNeeded = identifyUTurnIsNeeded(currentLocation, posTolerance);
// 5. Update Voice router
// Do not update in route planning mode
if (isFollowingMode) {
// don't update in route planing mode
boolean inRecalc = calculateRoute || isRouteBeingCalculated();
if (!inRecalc && !wrongMovementDirection) {
voiceRouter.updateStatus(currentLocation, false);
} else if(isDeviatedFromRoute){
} else if (isDeviatedFromRoute) {
voiceRouter.interruptRouteCommands();
}
if (distOrth > 350) {
voiceRouter.announceOffRoute(distOrth);
}
}
// calculate projection of current location
@ -567,7 +570,7 @@ public class RoutingHelper {
deviateFromRouteDetected = 0;
}
}
this.isDeviatedFromRoute = isOffRoute;
this.isDeviatedFromRoute = this.isDeviatedFromRoute || isOffRoute;
return isOffRoute;
}

View file

@ -60,7 +60,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
}
if (mediaPlayer != null){
mediaPlayer.stop();
//Nullifying here fixes #1351, but may be overkill. Let's see if static status variables in VoiceRouter do the job as well.
//Nullifying here fixes #1351, but there should be a better fix.
//mediaPlayer.release();
//mediaPlayer = null;
}

View file

@ -133,7 +133,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
ttsRequests = 0;
if (mTts != null){
mTts.stop();
//Nullifying here may fix #2810, but should be overkill. Let's see if static status variables in VoiceRouter do the job as well.
//Nullifying here may fix #2810, but there should be a better fix.
//mTts = null;
}
if (ctx != null) {