Search in sources :

Example 1 with TurnType

use of net.osmand.router.TurnType in project Osmand by osmandapp.

the class VoiceRouter method playMakeTurnIn.

private void playMakeTurnIn(RouteSegmentResult currentSegment, RouteDirectionInfo next, int dist, RouteDirectionInfo pronounceNextNext) {
    CommandBuilder play = getNewCommandPlayerToPlay();
    if (play != null) {
        String tParam = getTurnType(next.getTurnType());
        boolean isPlay = true;
        if (tParam != null) {
            play.turn(tParam, dist, getSpeakableStreetName(currentSegment, next, true));
            suppressDest = true;
        } else if (next.getTurnType().isRoundAbout()) {
            play.roundAbout(dist, next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next, true));
            // Other than in prepareTurn, in prepareRoundabout we do not announce destination, so we can repeat it one more time
            suppressDest = false;
        } else if (next.getTurnType().getValue() == TurnType.TU || next.getTurnType().getValue() == TurnType.TRU) {
            play.makeUT(dist, getSpeakableStreetName(currentSegment, next, true));
            suppressDest = true;
        } else {
            isPlay = false;
        }
        // 'then keep' preparation for next after next. (Also announces an interim straight segment, which is not pronounced above.)
        if (pronounceNextNext != null) {
            TurnType t = pronounceNextNext.getTurnType();
            isPlay = true;
            if (t.getValue() != TurnType.C && next.getTurnType().getValue() == TurnType.C) {
                play.goAhead(dist, getSpeakableStreetName(currentSegment, next, true));
            }
            if (t.getValue() == TurnType.TL || t.getValue() == TurnType.TSHL || t.getValue() == TurnType.TSLL || t.getValue() == TurnType.TU || t.getValue() == TurnType.KL) {
                play.then().bearLeft(getSpeakableStreetName(currentSegment, next, false));
            } else if (t.getValue() == TurnType.TR || t.getValue() == TurnType.TSHR || t.getValue() == TurnType.TSLR || t.getValue() == TurnType.TRU || t.getValue() == TurnType.KR) {
                play.then().bearRight(getSpeakableStreetName(currentSegment, next, false));
            }
        }
        if (isPlay) {
            notifyOnVoiceMessage();
            play.play();
        }
    }
}
Also used : CommandBuilder(net.osmand.plus.voice.CommandBuilder) TurnType(net.osmand.router.TurnType)

Example 2 with TurnType

use of net.osmand.router.TurnType in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createNextInfoControl.

public NextTurnInfoWidget createNextInfoControl(final Activity activity, final OsmandApplication app, boolean horisontalMini) {
    final OsmandSettings settings = app.getSettings();
    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();
                if (deviatedFromRoute) {
                    turnImminent = 0;
                    turnType = TurnType.valueOf(TurnType.OFFR, settings.DRIVING_REGION.get().leftHandDriving);
                    setDeviatePath((int) routingHelper.getRouteDeviation());
                } else {
                    NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                    if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
                        turnType = r.directionInfo.getTurnType();
                        nextTurnDistance = r.distanceTo;
                        turnImminent = r.imminent;
                    }
                }
            }
            setTurnType(turnType);
            setTurnImminent(turnImminent, deviatedFromRoute);
            setTurnDistance(nextTurnDistance);
            return true;
        }
    };
    nextTurnInfo.setOnClickListener(new View.OnClickListener() {

        // int i = 0;
        // boolean leftSide = false;
        @Override
        public void onClick(View v) {
            // TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nextTurnInfo.turnType,nextTurnInfo.pathTransform);
            if (routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
                routingHelper.getVoiceRouter().announceCurrentDirection(null);
            }
        }
    });
    // 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) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 3 with TurnType

use of net.osmand.router.TurnType in project Osmand by osmandapp.

the class NavigationNotification method buildNotification.

@Override
public Builder buildNotification(boolean wearable) {
    if (!isEnabled()) {
        return null;
    }
    NavigationService service = app.getNavigationService();
    String notificationTitle;
    StringBuilder notificationText = new StringBuilder();
    color = 0;
    icon = R.drawable.ic_action_start_navigation;
    turnBitmap = null;
    ongoing = true;
    RoutingHelper routingHelper = app.getRoutingHelper();
    boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
    if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
        color = app.getResources().getColor(R.color.osmand_orange);
        String distanceStr = OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app);
        String timeStr = OsmAndFormatter.getFormattedDuration(app.getRoutingHelper().getLeftTime(), app);
        String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(System.currentTimeMillis() + app.getRoutingHelper().getLeftTime() * 1000));
        TurnType turnType = null;
        boolean deviatedFromRoute;
        int turnImminent = 0;
        int nextTurnDistance = 0;
        int nextNextTurnDistance = 0;
        RouteDirectionInfo ri = null;
        if (routingHelper.isRouteCalculated() && followingMode) {
            deviatedFromRoute = routingHelper.isDeviatedFromRoute();
            if (deviatedFromRoute) {
                turnImminent = 0;
                turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
                nextTurnDistance = (int) routingHelper.getRouteDeviation();
            } else {
                NextDirectionInfo calc1 = new NextDirectionInfo();
                NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
                    ri = r.directionInfo;
                    turnType = r.directionInfo.getTurnType();
                    nextTurnDistance = r.distanceTo;
                    turnImminent = r.imminent;
                    NextDirectionInfo next = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
                    nextNextTurnDistance = next.distanceTo;
                }
            }
            if (turnType != null) {
                TurnDrawable drawable = new TurnDrawable(app, false);
                int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
                int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
                drawable.setBounds(0, 0, width, height);
                drawable.setTurnType(turnType);
                drawable.setTurnImminent(turnImminent, deviatedFromRoute);
                turnBitmap = drawableToBitmap(drawable);
            }
            notificationTitle = OsmAndFormatter.getFormattedDistance(nextTurnDistance, app) + (turnType != null ? " • " + RouteCalculationResult.toString(turnType, app, true) : "");
            if (ri != null && !Algorithms.isEmpty(ri.getDescriptionRoutePart())) {
                notificationText.append(ri.getDescriptionRoutePart());
                if (nextNextTurnDistance > 0) {
                    notificationText.append(" ").append(OsmAndFormatter.getFormattedDistance(nextNextTurnDistance, app));
                }
                notificationText.append("\n");
            }
            int distanceToNextIntermediate = routingHelper.getLeftDistanceNextIntermediate();
            if (distanceToNextIntermediate > 0) {
                int nextIntermediateIndex = routingHelper.getRoute().getNextIntermediate();
                List<TargetPoint> intermediatePoints = app.getTargetPointsHelper().getIntermediatePoints();
                if (nextIntermediateIndex < intermediatePoints.size()) {
                    TargetPoint nextIntermediate = intermediatePoints.get(nextIntermediateIndex);
                    notificationText.append(OsmAndFormatter.getFormattedDistance(distanceToNextIntermediate, app)).append(" • ").append(nextIntermediate.getOnlyName());
                    notificationText.append("\n");
                }
            }
            notificationText.append(distanceStr).append(" • ").append(timeStr).append(" • ").append(etaStr);
        } else {
            notificationTitle = app.getString(R.string.shared_string_navigation);
            String error = routingHelper.getLastRouteCalcErrorShort();
            if (Algorithms.isEmpty(error)) {
                notificationText.append(app.getString(R.string.route_calculation)).append("...");
            } else {
                notificationText.append(error);
            }
        }
    } else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) {
        ongoing = false;
        notificationTitle = app.getString(R.string.shared_string_navigation);
        notificationText.append(app.getString(R.string.shared_string_paused));
    } else {
        return null;
    }
    final Builder notificationBuilder = createBuilder(wearable).setContentTitle(notificationTitle).setStyle(new BigTextStyle().bigText(notificationText)).setLargeIcon(turnBitmap);
    Intent stopIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(R.drawable.ic_action_remove_dark, app.getString(R.string.shared_string_control_stop), stopPendingIntent);
    if (routingHelper.isRouteCalculated() && followingMode) {
        Intent pauseIntent = new Intent(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION);
        PendingIntent pausePendingIntent = PendingIntent.getBroadcast(app, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.addAction(R.drawable.ic_pause, app.getString(R.string.shared_string_pause), pausePendingIntent);
    } else if (routingHelper.isRouteCalculated() && routingHelper.isPauseNavigation()) {
        Intent resumeIntent = new Intent(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION);
        PendingIntent resumePendingIntent = PendingIntent.getBroadcast(app, 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.addAction(R.drawable.ic_play_dark, app.getString(R.string.shared_string_continue), resumePendingIntent);
    }
    return notificationBuilder;
}
Also used : Builder(android.support.v4.app.NotificationCompat.Builder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TurnType(net.osmand.router.TurnType) Date(java.util.Date) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) NavigationService(net.osmand.plus.NavigationService) BigTextStyle(android.support.v4.app.NotificationCompat.BigTextStyle) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) TurnDrawable(net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable) PendingIntent(android.app.PendingIntent)

Example 4 with TurnType

use of net.osmand.router.TurnType in project Osmand by osmandapp.

the class ExternalApiHelper method updateTurnInfo.

private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) {
    result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
    result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
    if (ni.directionInfo != null && ni.directionInfo.getTurnType() != null) {
        TurnType tt = ni.directionInfo.getTurnType();
        RouteDirectionInfo a = ni.directionInfo;
        result.putExtra(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), ""));
        result.putExtra(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString());
        if (tt.getLanes() != null) {
            result.putExtra(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes()));
        }
    }
}
Also used : RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) TurnType(net.osmand.router.TurnType)

Example 5 with TurnType

use of net.osmand.router.TurnType in project Osmand by osmandapp.

the class RouteCalculationResult method convertVectorResult.

/**
 * PREPARATION
 */
private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list, List<AlarmInfo> alarms, OsmandApplication ctx) {
    float prevDirectionTime = 0;
    float prevDirectionDistance = 0;
    double lastHeight = HEIGHT_UNDEFINED;
    List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
    AlarmInfo tunnelAlarm = null;
    for (int routeInd = 0; routeInd < list.size(); routeInd++) {
        RouteSegmentResult s = list.get(routeInd);
        float[] vls = s.getObject().calculateHeightArray();
        boolean plus = s.getStartPointIndex() < s.getEndPointIndex();
        int i = s.getStartPointIndex();
        int prevLocationSize = locations.size();
        if (s.getObject().tunnel()) {
            if (tunnelAlarm == null) {
                LatLon latLon = s.getPoint(i);
                tunnelAlarm = new AlarmInfo(AlarmInfoType.TUNNEL, prevLocationSize);
                tunnelAlarm.setLatLon(latLon.getLatitude(), latLon.getLongitude());
                tunnelAlarm.setFloatValue(s.getDistance());
                alarms.add(tunnelAlarm);
            } else {
                tunnelAlarm.setFloatValue(tunnelAlarm.getFloatValue() + s.getDistance());
            }
        } else {
            if (tunnelAlarm != null) {
                tunnelAlarm.setLastLocationIndex(locations.size());
            }
            tunnelAlarm = null;
        }
        while (true) {
            // $NON-NLS-1$
            Location n = new Location("");
            LatLon point = s.getPoint(i);
            n.setLatitude(point.getLatitude());
            n.setLongitude(point.getLongitude());
            if (i == s.getEndPointIndex() && routeInd != list.size() - 1) {
                break;
            }
            if (vls != null && i * 2 + 1 < vls.length) {
                float h = vls[2 * i + 1];
                n.setAltitude(h);
                if (lastHeight == HEIGHT_UNDEFINED && locations.size() > 0) {
                    for (Location l : locations) {
                        if (!l.hasAltitude()) {
                            l.setAltitude(h);
                        }
                    }
                }
                lastHeight = h;
            }
            locations.add(n);
            attachAlarmInfo(alarms, s, i, locations.size());
            segmentsToPopulate.add(s);
            if (i == s.getEndPointIndex()) {
                break;
            }
            if (plus) {
                i++;
            } else {
                i--;
            }
        }
        TurnType turn = s.getTurnType();
        if (turn != null) {
            RouteDirectionInfo info = new RouteDirectionInfo(s.getSegmentSpeed(), turn);
            if (routeInd < list.size()) {
                int lind = routeInd;
                if (turn.isRoundAbout()) {
                    int roundAboutEnd = prevLocationSize;
                    // take next name for roundabout (not roundabout name)
                    while (lind < list.size() - 1 && list.get(lind).getObject().roundabout()) {
                        roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex() - list.get(lind).getStartPointIndex());
                        lind++;
                    }
                    // Consider roundabout end.
                    info.routeEndPointOffset = roundAboutEnd;
                }
                RouteSegmentResult next = list.get(lind);
                info.setRef(next.getObject().getRef(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
                info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()));
                info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
            }
            String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), info.getRef(), info.getDestinationName(), ctx.getString(R.string.towards));
            description = description.trim();
            String[] pointNames = s.getObject().getPointNames(s.getStartPointIndex());
            if (pointNames != null) {
                for (int t = 0; t < pointNames.length; t++) {
                    description = description.trim();
                    description += " " + pointNames[t];
                }
            }
            info.setDescriptionRoute(description);
            info.routePointOffset = prevLocationSize;
            if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
                RouteDirectionInfo prev = directions.get(directions.size() - 1);
                prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
                prevDirectionDistance = 0;
                prevDirectionTime = 0;
            }
            directions.add(info);
        }
        prevDirectionDistance += s.getDistance();
        prevDirectionTime += s.getSegmentTime();
    }
    if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
        RouteDirectionInfo prev = directions.get(directions.size() - 1);
        prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
    }
    return segmentsToPopulate;
}
Also used : ArrayList(java.util.ArrayList) TurnType(net.osmand.router.TurnType) LocationPoint(net.osmand.data.LocationPoint) LatLon(net.osmand.data.LatLon) RouteSegmentResult(net.osmand.router.RouteSegmentResult) Location(net.osmand.Location)

Aggregations

TurnType (net.osmand.router.TurnType)9 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)4 Paint (android.graphics.Paint)3 LocationPoint (net.osmand.data.LocationPoint)3 NextDirectionInfo (net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 Location (net.osmand.Location)2 RouteDirectionInfo (net.osmand.plus.routing.RouteDirectionInfo)2 DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 BigTextStyle (android.support.v4.app.NotificationCompat.BigTextStyle)1 Builder (android.support.v4.app.NotificationCompat.Builder)1 TextPaint (android.text.TextPaint)1 Date (java.util.Date)1