Search in sources :

Example 1 with AlarmInfo

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

the class WaypointHelper method getMostImportantAlarm.

public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) {
    Location lastProjection = app.getRoutingHelper().getLastProjection();
    float mxspeed = route.getCurrentMaxSpeed();
    float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
    AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta);
    if (speedAlarm != null) {
        getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed());
    }
    AlarmInfo mostImportant = speedAlarm;
    int value = speedAlarm != null ? speedAlarm.updateDistanceAndGetPriority(0, 0) : Integer.MAX_VALUE;
    float speed = lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0;
    if (ALARMS < pointsProgress.size()) {
        int kIterator = pointsProgress.get(ALARMS);
        List<LocationPointWrapper> lp = locationPoints.get(ALARMS);
        while (kIterator < lp.size()) {
            AlarmInfo inf = (AlarmInfo) lp.get(kIterator).point;
            int currentRoute = route.getCurrentRoute();
            if (inf.getLocationIndex() < currentRoute && inf.getLastLocationIndex() != -1 && inf.getLastLocationIndex() < currentRoute) {
            // skip
            } else {
                if (inf.getType() == AlarmInfoType.TUNNEL && inf.getLastLocationIndex() != -1 && currentRoute > inf.getLocationIndex() && currentRoute < inf.getLastLocationIndex()) {
                    inf.setFloatValue(route.getDistanceToPoint(inf.getLastLocationIndex()));
                }
                int d = route.getDistanceToPoint(inf.getLocationIndex());
                if (d > LONG_ANNOUNCE_RADIUS) {
                    break;
                }
                float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
                int vl = inf.updateDistanceAndGetPriority(time, d);
                if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
                    mostImportant = inf;
                    value = vl;
                }
            }
            kIterator++;
        }
    }
    return mostImportant;
}
Also used : AlarmInfo(net.osmand.plus.routing.AlarmInfo) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 2 with AlarmInfo

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

the class WaypointHelper method calculateMostImportantAlarm.

public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) {
    float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc));
    float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
    AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta);
    if (speedAlarm != null) {
        getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed());
        return speedAlarm;
    }
    for (int i = 0; i < ro.getPointsLength(); i++) {
        int[] pointTypes = ro.getPointTypes(i);
        RouteRegion reg = ro.region;
        if (pointTypes != null) {
            for (int r = 0; r < pointTypes.length; r++) {
                RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
                AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0, loc);
                if (info != null) {
                    if (info.getType() != AlarmInfoType.SPEED_CAMERA || showCameras) {
                        long ms = System.currentTimeMillis();
                        if (ms - announcedAlarmTime > 50 * 1000) {
                            announcedAlarmTime = ms;
                            getVoiceRouter().announceAlarm(info, loc.getSpeed());
                        }
                        return info;
                    }
                }
            }
        }
    }
    return null;
}
Also used : RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) AlarmInfo(net.osmand.plus.routing.AlarmInfo) RouteTypeRule(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint)

Example 3 with AlarmInfo

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

the class WaypointHelper method createSpeedAlarm.

private static AlarmInfo createSpeedAlarm(MetricsConstants mc, float mxspeed, Location loc, float delta) {
    AlarmInfo speedAlarm = null;
    if (mxspeed != 0 && loc != null && loc.hasSpeed() && mxspeed != RouteDataObject.NONE_MAX_SPEED) {
        if (loc.getSpeed() > mxspeed + delta) {
            int speed;
            if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
                speed = Math.round(mxspeed * 3.6f);
            } else {
                speed = Math.round(mxspeed * 3.6f / 1.6f);
            }
            speedAlarm = AlarmInfo.createSpeedLimit(speed, loc);
        }
    }
    return speedAlarm;
}
Also used : AlarmInfo(net.osmand.plus.routing.AlarmInfo) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint)

Example 4 with AlarmInfo

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

the class WaypointHelper method calculateAlarms.

private void calculateAlarms(RouteCalculationResult route, List<LocationPointWrapper> array, ApplicationMode mode) {
    AlarmInfo prevSpeedCam = null;
    for (AlarmInfo i : route.getAlarmInfo()) {
        if (i.getType() == AlarmInfoType.SPEED_CAMERA) {
            if (app.getSettings().SHOW_CAMERAS.getModeValue(mode) || app.getSettings().SPEAK_SPEED_CAMERA.getModeValue(mode)) {
                LocationPointWrapper lw = new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
                if (prevSpeedCam != null && MapUtils.getDistance(prevSpeedCam.getLatitude(), prevSpeedCam.getLongitude(), i.getLatitude(), i.getLongitude()) < DISTANCE_IGNORE_DOUBLE_SPEEDCAMS) {
                // ignore double speed cams
                } else {
                    lw.setAnnounce(app.getSettings().SPEAK_SPEED_CAMERA.get());
                    array.add(lw);
                    prevSpeedCam = i;
                }
            }
        } else {
            if (app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(mode) || app.getSettings().SPEAK_TRAFFIC_WARNINGS.getModeValue(mode)) {
                LocationPointWrapper lw = new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
                lw.setAnnounce(app.getSettings().SPEAK_TRAFFIC_WARNINGS.get());
                array.add(lw);
            }
        }
    }
}
Also used : AlarmInfo(net.osmand.plus.routing.AlarmInfo)

Example 5 with AlarmInfo

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

the class WaypointHelper method announceVisibleLocations.

public void announceVisibleLocations() {
    Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
    if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
        for (int type = 0; type < locationPoints.size(); type++) {
            int currentRoute = route.getCurrentRoute();
            List<LocationPointWrapper> approachPoints = new ArrayList<LocationPointWrapper>();
            List<LocationPointWrapper> announcePoints = new ArrayList<LocationPointWrapper>();
            List<LocationPointWrapper> lp = locationPoints.get(type);
            if (lp != null) {
                int kIterator = pointsProgress.get(type);
                while (kIterator < lp.size() && lp.get(kIterator).routeIndex < currentRoute) {
                    if (type == ALARMS) {
                        AlarmInfo alarm = (AlarmInfo) lp.get(kIterator).getPoint();
                        if (alarm.getLastLocationIndex() >= currentRoute) {
                            break;
                        }
                    }
                    kIterator++;
                }
                pointsProgress.set(type, kIterator);
                while (kIterator < lp.size()) {
                    LocationPointWrapper lwp = lp.get(kIterator);
                    if (type == ALARMS && lwp.routeIndex < currentRoute) {
                        kIterator++;
                        continue;
                    }
                    if (lwp.announce) {
                        if (route.getDistanceToPoint(lwp.routeIndex) > LONG_ANNOUNCE_RADIUS * 2) {
                            break;
                        }
                        LocationPoint point = lwp.point;
                        double d1 = Math.max(0.0, MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), point.getLatitude(), point.getLongitude()) - lwp.getDeviationDistance());
                        Integer state = locationPointsStates.get(point);
                        if (state != null && state.intValue() == ANNOUNCED_ONCE && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_DONE);
                            announcePoints.add(lwp);
                        } else if (type != ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_ONCE);
                            approachPoints.add(lwp);
                        } else if (type == ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, ALARMS_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_ONCE);
                            approachPoints.add(lwp);
                        }
                    }
                    kIterator++;
                }
                if (!announcePoints.isEmpty()) {
                    if (announcePoints.size() > ANNOUNCE_POI_LIMIT) {
                        announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT);
                    }
                    if (type == WAYPOINTS) {
                        getVoiceRouter().announceWaypoint(announcePoints);
                    } else if (type == POI) {
                        getVoiceRouter().announcePoi(announcePoints);
                    } else if (type == ALARMS) {
                    // nothing to announce
                    } else if (type == FAVORITES) {
                        getVoiceRouter().announceFavorite(announcePoints);
                    }
                }
                if (!approachPoints.isEmpty()) {
                    if (approachPoints.size() > APPROACH_POI_LIMIT) {
                        approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT);
                    }
                    if (type == WAYPOINTS) {
                        getVoiceRouter().approachWaypoint(lastKnownLocation, approachPoints);
                    } else if (type == POI) {
                        getVoiceRouter().approachPoi(lastKnownLocation, approachPoints);
                    } else if (type == ALARMS) {
                        EnumSet<AlarmInfoType> ait = EnumSet.noneOf(AlarmInfoType.class);
                        for (LocationPointWrapper pw : approachPoints) {
                            ait.add(((AlarmInfo) pw.point).getType());
                        }
                        for (AlarmInfoType t : ait) {
                            app.getRoutingHelper().getVoiceRouter().announceAlarm(new AlarmInfo(t, -1), lastKnownLocation.getSpeed());
                        }
                    } else if (type == FAVORITES) {
                        getVoiceRouter().approachFavorite(lastKnownLocation, approachPoints);
                    }
                }
            }
        }
    }
}
Also used : AlarmInfoType(net.osmand.plus.routing.AlarmInfo.AlarmInfoType) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) LocationPoint(net.osmand.data.LocationPoint) AlarmInfo(net.osmand.plus.routing.AlarmInfo) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Aggregations

AlarmInfo (net.osmand.plus.routing.AlarmInfo)5 AmenityRoutePoint (net.osmand.data.Amenity.AmenityRoutePoint)4 LocationPoint (net.osmand.data.LocationPoint)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 Location (net.osmand.Location)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)1 RouteTypeRule (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule)1 AlarmInfoType (net.osmand.plus.routing.AlarmInfo.AlarmInfoType)1