This commit is contained in:
Alexey Kulish 2018-05-25 12:59:14 +03:00
parent 3c73aaa5dc
commit ddb377bea8

View file

@ -13,12 +13,12 @@ import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.activities.IntermediatePointsDialog;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
@ -33,7 +33,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -54,6 +53,7 @@ public class WaypointHelper {
private static final int LONG_ANNOUNCE_RADIUS = 700; private static final int LONG_ANNOUNCE_RADIUS = 700;
private static final int SHORT_ANNOUNCE_RADIUS = 150; private static final int SHORT_ANNOUNCE_RADIUS = 150;
private static final int ALARMS_ANNOUNCE_RADIUS = 150; private static final int ALARMS_ANNOUNCE_RADIUS = 150;
private static final int ALARMS_SHORT_ANNOUNCE_RADIUS = 100;
// don't annoy users by lots of announcements // don't annoy users by lots of announcements
private static final int APPROACH_POI_LIMIT = 1; private static final int APPROACH_POI_LIMIT = 1;
@ -70,8 +70,9 @@ public class WaypointHelper {
public static final int[] SEARCH_RADIUS_VALUES = {50, 100, 200, 500, 1000, 2000, 5000}; public static final int[] SEARCH_RADIUS_VALUES = {50, 100, 200, 500, 1000, 2000, 5000};
private static final double DISTANCE_IGNORE_DOUBLE_SPEEDCAMS = 150; private static final double DISTANCE_IGNORE_DOUBLE_SPEEDCAMS = 150;
private List<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>(); private List<List<LocationPointWrapper>> locationPoints = new ArrayList<>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>(); private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<>();
private ConcurrentHashMap<AlarmInfo.AlarmInfoType, AlarmInfo> lastAnnouncedAlarms = new ConcurrentHashMap<>();
private TIntArrayList pointsProgress = new TIntArrayList(); private TIntArrayList pointsProgress = new TIntArrayList();
private RouteCalculationResult route; private RouteCalculationResult route;
@ -342,6 +343,8 @@ public class WaypointHelper {
kIterator++; kIterator++;
} }
pointsProgress.set(type, kIterator); pointsProgress.set(type, kIterator);
VoiceRouter voiceRouter = getVoiceRouter();
while (kIterator < lp.size()) { while (kIterator < lp.size()) {
LocationPointWrapper lwp = lp.get(kIterator); LocationPointWrapper lwp = lp.get(kIterator);
if (type == ALARMS && lwp.routeIndex < currentRoute) { if (type == ALARMS && lwp.routeIndex < currentRoute) {
@ -356,20 +359,45 @@ public class WaypointHelper {
double d1 = Math.max(0.0, MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), double d1 = Math.max(0.0, MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(),
point.getLatitude(), point.getLongitude()) - lwp.getDeviationDistance()); point.getLatitude(), point.getLongitude()) - lwp.getDeviationDistance());
Integer state = locationPointsStates.get(point); Integer state = locationPointsStates.get(point);
if (state != null && state.intValue() == ANNOUNCED_ONCE if (state != null && state == ANNOUNCED_ONCE
&& getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) { && voiceRouter.isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) {
locationPointsStates.put(point, ANNOUNCED_DONE); locationPointsStates.put(point, ANNOUNCED_DONE);
announcePoints.add(lwp); announcePoints.add(lwp);
} else if (type != ALARMS && (state == null || state == NOT_ANNOUNCED) } else if (type != ALARMS && (state == null || state == NOT_ANNOUNCED)
&& getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) { && voiceRouter.isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) {
locationPointsStates.put(point, ANNOUNCED_ONCE); locationPointsStates.put(point, ANNOUNCED_ONCE);
approachPoints.add(lwp); approachPoints.add(lwp);
} else if (type == ALARMS && (state == null || state == NOT_ANNOUNCED) } else if (type == ALARMS && (state == null || state == NOT_ANNOUNCED)) {
&& getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, ALARMS_ANNOUNCE_RADIUS, 0f)) { AlarmInfo alarm = (AlarmInfo) point;
AlarmInfoType t = alarm.getType();
int announceRadius;
boolean filter = false;
switch (t) {
case TRAFFIC_CALMING:
announceRadius = ALARMS_SHORT_ANNOUNCE_RADIUS;
filter = true;
break;
default:
announceRadius = ALARMS_ANNOUNCE_RADIUS;
break;
}
boolean proceed = voiceRouter.isDistanceLess(lastKnownLocation.getSpeed(), d1, announceRadius, 0f);
if (proceed && filter) {
AlarmInfo lastAlarm = lastAnnouncedAlarms.get(t);
if (lastAlarm != null) {
double dist = MapUtils.getDistance(lastAlarm.getLatitude(), lastAlarm.getLongitude(), alarm.getLatitude(), alarm.getLongitude());
if (dist < ALARMS_SHORT_ANNOUNCE_RADIUS) {
locationPointsStates.put(point, ANNOUNCED_DONE);
proceed = false;
}
}
}
if (proceed) {
locationPointsStates.put(point, ANNOUNCED_ONCE); locationPointsStates.put(point, ANNOUNCED_ONCE);
approachPoints.add(lwp); approachPoints.add(lwp);
} }
} }
}
kIterator++; kIterator++;
} }
if (!announcePoints.isEmpty()) { if (!announcePoints.isEmpty()) {
@ -377,13 +405,13 @@ public class WaypointHelper {
announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT); announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT);
} }
if (type == WAYPOINTS) { if (type == WAYPOINTS) {
getVoiceRouter().announceWaypoint(announcePoints); voiceRouter.announceWaypoint(announcePoints);
} else if (type == POI) { } else if (type == POI) {
getVoiceRouter().announcePoi(announcePoints); voiceRouter.announcePoi(announcePoints);
} else if (type == ALARMS) { } else if (type == ALARMS) {
// nothing to announce // nothing to announce
} else if (type == FAVORITES) { } else if (type == FAVORITES) {
getVoiceRouter().announceFavorite(announcePoints); voiceRouter.announceFavorite(announcePoints);
} }
} }
if (!approachPoints.isEmpty()) { if (!approachPoints.isEmpty()) {
@ -391,19 +419,17 @@ public class WaypointHelper {
approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT); approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT);
} }
if (type == WAYPOINTS) { if (type == WAYPOINTS) {
getVoiceRouter().approachWaypoint(lastKnownLocation, approachPoints); voiceRouter.approachWaypoint(lastKnownLocation, approachPoints);
} else if (type == POI) { } else if (type == POI) {
getVoiceRouter().approachPoi(lastKnownLocation, approachPoints); voiceRouter.approachPoi(lastKnownLocation, approachPoints);
} else if (type == ALARMS) { } else if (type == ALARMS) {
EnumSet<AlarmInfoType> ait = EnumSet.noneOf(AlarmInfoType.class);
for (LocationPointWrapper pw : approachPoints) { for (LocationPointWrapper pw : approachPoints) {
ait.add(((AlarmInfo) pw.point).getType()); AlarmInfo alarm = (AlarmInfo) pw.point;
} voiceRouter.announceAlarm(new AlarmInfo(alarm.getType(), -1), lastKnownLocation.getSpeed());
for (AlarmInfoType t : ait) { lastAnnouncedAlarms.put(alarm.getType(), alarm);
app.getRoutingHelper().getVoiceRouter().announceAlarm(new AlarmInfo(t, -1), lastKnownLocation.getSpeed());
} }
} else if (type == FAVORITES) { } else if (type == FAVORITES) {
getVoiceRouter().approachFavorite(lastKnownLocation, approachPoints); voiceRouter.approachFavorite(lastKnownLocation, approachPoints);
} }
} }
} }
@ -455,6 +481,7 @@ public class WaypointHelper {
public void clearAllVisiblePoints() { public void clearAllVisiblePoints() {
this.locationPointsStates.clear(); this.locationPointsStates.clear();
this.lastAnnouncedAlarms.clear();
this.locationPoints = new ArrayList<List<LocationPointWrapper>>(); this.locationPoints = new ArrayList<List<LocationPointWrapper>>();
} }
@ -544,6 +571,7 @@ public class WaypointHelper {
protected synchronized void setLocationPoints(List<List<LocationPointWrapper>> locationPoints, RouteCalculationResult route) { protected synchronized void setLocationPoints(List<List<LocationPointWrapper>> locationPoints, RouteCalculationResult route) {
this.locationPoints = locationPoints; this.locationPoints = locationPoints;
this.locationPointsStates.clear(); this.locationPointsStates.clear();
this.lastAnnouncedAlarms.clear();
TIntArrayList list = new TIntArrayList(locationPoints.size()); TIntArrayList list = new TIntArrayList(locationPoints.size());
list.fill(0, locationPoints.size(), 0); list.fill(0, locationPoints.size(), 0);
this.pointsProgress = list; this.pointsProgress = list;