Search in sources :

Example 6 with NextDirectionInfo

use of net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo in project Osmand by osmandapp.

the class VoiceRouter method updateStatus.

/**
 * Updates status of voice guidance
 * @param currentLocation
 */
protected void updateStatus(Location currentLocation, boolean repeat) {
    // Directly after turn: goAhead (dist), unless:
    // < PREPARE_LONG_DISTANCE (e.g. 3500m):         playPrepareTurn (-not played any more-)
    // < PREPARE_DISTANCE      (e.g. 1500m):         playPrepareTurn ("Turn after ...")
    // < TURN_IN_DISTANCE      (e.g. 390m or 30sec): playMakeTurnIn  ("Turn in ...")
    // < TURN_DISTANCE         (e.g. 50m or 7sec):   playMakeTurn    ("Turn ...")
    float speed = DEFAULT_SPEED;
    if (currentLocation != null && currentLocation.hasSpeed()) {
        speed = Math.max(currentLocation.getSpeed(), speed);
    }
    NextDirectionInfo nextInfo = router.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
    RouteSegmentResult currentSegment = router.getCurrentSegmentResult();
    if (nextInfo == null || nextInfo.directionInfo == null) {
        return;
    }
    int dist = nextInfo.distanceTo;
    RouteDirectionInfo next = nextInfo.directionInfo;
    // If routing is changed update status to unknown
    if (next != nextRouteDirection) {
        nextRouteDirection = next;
        currentStatus = STATUS_UNKNOWN;
        suppressDest = false;
        playedAndArriveAtTarget = false;
        announceBackOnRoute = false;
        if (playGoAheadDist != -1) {
            playGoAheadDist = 0;
        }
    }
    if (!repeat) {
        if (dist <= 0) {
            return;
        } else if (needsInforming()) {
            playGoAhead(dist, getSpeakableStreetName(currentSegment, next, false));
            return;
        } else if (currentStatus == STATUS_TOLD) {
            // however it should be checked manually ?
            return;
        }
    }
    if (currentStatus == STATUS_UNKNOWN) {
        // Play "Continue for ..." if (1) after route calculation no other prompt is due, or (2) after a turn if next turn is more than PREPARE_LONG_DISTANCE away
        if ((playGoAheadDist == -1) || (dist > PREPARE_LONG_DISTANCE)) {
            playGoAheadDist = dist - 3 * TURN_DISTANCE;
        }
    }
    // I think "true" is correct here, not "!repeat"
    NextDirectionInfo nextNextInfo = router.getNextRouteDirectionInfoAfter(nextInfo, new NextDirectionInfo(), true);
    // STATUS_TURN = "Turn (now)"
    if ((repeat || statusNotPassed(STATUS_TURN)) && isDistanceLess(speed, dist, TURN_DISTANCE, TURN_DEFAULT_SPEED)) {
        if (nextNextInfo.distanceTo < TURN_IN_DISTANCE_END && nextNextInfo != null) {
            playMakeTurn(currentSegment, next, nextNextInfo);
        } else {
            playMakeTurn(currentSegment, next, null);
        }
        if (!next.getTurnType().goAhead() && isTargetPoint(nextNextInfo)) {
            // !goAhead() avoids isolated "and arrive.." prompt, as goAhead() is not pronounced
            if (nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) {
                // Distance fon non-straights already announced in "Turn (now)"'s nextnext  code above
                if ((nextNextInfo != null) && (nextNextInfo.directionInfo != null) && nextNextInfo.directionInfo.getTurnType().goAhead()) {
                    playThen();
                    playGoAhead(nextNextInfo.distanceTo, empty);
                }
                playAndArriveAtDestination(nextNextInfo);
            } else if (nextNextInfo.distanceTo < 1.2f * TURN_IN_DISTANCE_END) {
                // 1.2 is safety margin should the subsequent "Turn in" prompt not fit in amy more
                playThen();
                playGoAhead(nextNextInfo.distanceTo, empty);
                playAndArriveAtDestination(nextNextInfo);
            }
        }
        nextStatusAfter(STATUS_TURN);
    // STATUS_TURN_IN = "Turn in ..."
    } else if ((repeat || statusNotPassed(STATUS_TURN_IN)) && isDistanceLess(speed, dist, TURN_IN_DISTANCE, 0f)) {
        if (repeat || dist >= TURN_IN_DISTANCE_END) {
            if ((isDistanceLess(speed, nextNextInfo.distanceTo, TURN_DISTANCE, 0f) || nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) && nextNextInfo != null) {
                playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, nextNextInfo.directionInfo);
            } else {
                playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, null);
            }
            playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
        }
        nextStatusAfter(STATUS_TURN_IN);
    // STATUS_PREPARE = "Turn after ..."
    } else if ((repeat || statusNotPassed(STATUS_PREPARE)) && (dist <= PREPARE_DISTANCE)) {
        if (repeat || dist >= PREPARE_DISTANCE_END) {
            if (!repeat && (next.getTurnType().keepLeft() || next.getTurnType().keepRight())) {
            // Do not play prepare for keep left/right
            } else {
                playPrepareTurn(currentSegment, next, dist);
                playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
            }
        }
        nextStatusAfter(STATUS_PREPARE);
    // STATUS_LONG_PREPARE =  also "Turn after ...", we skip this now, users said this is obsolete
    } else if ((repeat || statusNotPassed(STATUS_LONG_PREPARE)) && (dist <= PREPARE_LONG_DISTANCE)) {
        if (repeat || dist >= PREPARE_LONG_DISTANCE_END) {
            playPrepareTurn(currentSegment, next, dist);
            playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
        }
        nextStatusAfter(STATUS_LONG_PREPARE);
    // STATUS_UNKNOWN = "Continue for ..." if (1) after route calculation no other prompt is due, or (2) after a turn if next turn is more than PREPARE_LONG_DISTANCE away
    } else if (statusNotPassed(STATUS_UNKNOWN)) {
        // Strange how we get here but
        nextStatusAfter(STATUS_UNKNOWN);
    } else if (repeat || (statusNotPassed(STATUS_PREPARE) && dist < playGoAheadDist)) {
        playGoAheadDist = 0;
        playGoAhead(dist, getSpeakableStreetName(currentSegment, next, false));
    }
}
Also used : NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) RouteSegmentResult(net.osmand.router.RouteSegmentResult)

Example 7 with NextDirectionInfo

use of net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createNextNextInfoControl.

public NextTurnInfoWidget createNextNextInfoControl(final Activity activity, final OsmandApplication app, boolean horisontalMini) {
    final RoutingHelper routingHelper = app.getRoutingHelper();
    final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini) {

        NextDirectionInfo calc1 = new NextDirectionInfo();

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
            TurnType turnType = null;
            boolean deviatedFromRoute = false;
            int turnImminent = 0;
            int nextTurnDistance = 0;
            if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) {
                deviatedFromRoute = routingHelper.isDeviatedFromRoute();
                NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                if (!deviatedFromRoute) {
                    if (r != null) {
                        r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
                    }
                }
                if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
                    turnType = r.directionInfo.getTurnType();
                    turnImminent = r.imminent;
                    nextTurnDistance = r.distanceTo;
                }
            }
            setTurnType(turnType);
            setTurnImminent(turnImminent, deviatedFromRoute);
            setTurnDistance(nextTurnDistance);
            return true;
        }
    };
    nextTurnInfo.setOnClickListener(new View.OnClickListener() {

        // int i = 0;
        @Override
        public void onClick(View v) {
        // uncomment to test turn info rendering
        // final int l = TurnType.predefinedTypes.length;
        // final int exits = 5;
        // i++;
        // if (i % (l + exits) >= l ) {
        // nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1), true);
        // nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+"";
        // float a = 180 - (i % (l + exits) - l + 1) * 50;
        // nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a);
        // } else {
        // nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i % (TurnType.predefinedTypes.length + exits)], true);
        // nextTurnInfo.exitOut = "";
        // }
        // nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3;
        // nextTurnInfo.nextTurnDirection = 580;
        // TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nexsweepAngletTurnInfo.turnType,nextTurnInfo.pathTransform);
        // showMiniMap = true;
        }
    });
    // initial state
    return nextTurnInfo;
}
Also used : NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TurnType(net.osmand.router.TurnType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

NextDirectionInfo (net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)5 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 TurnType (net.osmand.router.TurnType)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Location (net.osmand.Location)2 DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 RouteSegmentResult (net.osmand.router.RouteSegmentResult)2 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 BigTextStyle (android.support.v4.app.NotificationCompat.BigTextStyle)1 Builder (android.support.v4.app.NotificationCompat.Builder)1 AlertDialog (android.support.v7.app.AlertDialog)1