Introduce enum alarm info type. And let define specific voice rules in prolog like # attention('SPEED_CAMERA') -- ['attention_speed_camera.ogg'].

This commit is contained in:
vshcherb 2014-02-12 01:21:11 +01:00
parent 07db561e06
commit 6e5b377fe2
5 changed files with 60 additions and 36 deletions

View file

@ -3,21 +3,36 @@ package net.osmand.plus.routing;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
public class AlarmInfo {
public static int SPEED_CAMERA = 1;
public static int SPEED_LIMIT = SPEED_CAMERA + 1;
public static int BORDER_CONTROL = SPEED_LIMIT + 1;
public static int TRAFFIC_CALMING = BORDER_CONTROL + 1;
public static int TOLL_BOOTH = TRAFFIC_CALMING + 1;
public static int STOP = TOLL_BOOTH + 1;
public static int MAXIMUM = STOP + 1;
private int type;
public enum AlarmInfoType {
SPEED_CAMERA(1),
SPEED_LIMIT(2),
BORDER_CONTROL(3),
TRAFFIC_CALMING(4),
TOLL_BOOTH(5),
STOP(6),
MAXIMUM(7);
private int priority;
private AlarmInfoType(int p) {
this.priority = p;
}
public int getPriority(){
return priority;
}
}
private AlarmInfoType type;
private float distance;
private float time;
protected final int locationIndex;
private int intValue;
public AlarmInfo(int type, int locationIndex){
public AlarmInfo(AlarmInfoType type, int locationIndex){
this.type = type;
this.locationIndex = locationIndex;
}
@ -39,7 +54,7 @@ public class AlarmInfo {
this.distance = distance;
}
public int getType() {
public AlarmInfoType getType() {
return type;
}
@ -54,7 +69,7 @@ public class AlarmInfo {
public static AlarmInfo createSpeedLimit(int speed){
AlarmInfo info = new AlarmInfo(SPEED_LIMIT, 0);
AlarmInfo info = new AlarmInfo(AlarmInfoType.SPEED_LIMIT, 0);
info.setIntValue(speed);
return info;
}
@ -62,18 +77,18 @@ public class AlarmInfo {
public static AlarmInfo createAlarmInfo(RouteTypeRule ruleType, int locInd) {
if("highway".equals(ruleType.getTag())) {
if("speed_camera".equals(ruleType.getValue())) {
return new AlarmInfo(SPEED_CAMERA, locInd);
return new AlarmInfo(AlarmInfoType.SPEED_CAMERA, locInd);
} else if("stop".equals(ruleType.getValue())) {
return new AlarmInfo(STOP, locInd);
return new AlarmInfo(AlarmInfoType.STOP, locInd);
}
} else if("barrier".equals(ruleType.getTag())) {
if("toll_booth".equals(ruleType.getValue())) {
return new AlarmInfo(TOLL_BOOTH, locInd);
return new AlarmInfo(AlarmInfoType.TOLL_BOOTH, locInd);
} else if("border_control".equals(ruleType.getValue())) {
return new AlarmInfo(BORDER_CONTROL, locInd);
return new AlarmInfo(AlarmInfoType.BORDER_CONTROL, locInd);
}
} else if("traffic_calming".equals(ruleType.getTag())) {
return new AlarmInfo(TRAFFIC_CALMING, locInd);
return new AlarmInfo(AlarmInfoType.TRAFFIC_CALMING, locInd);
}
return null;
}
@ -85,15 +100,15 @@ public class AlarmInfo {
return 0;
}
// 1 level of priorities
if (time < 8 || distance < 100 || type == SPEED_LIMIT) {
return type;
if (time < 8 || distance < 100 || type == AlarmInfoType.SPEED_LIMIT) {
return type.getPriority();
}
if (type == SPEED_CAMERA && (time < 15 || distance < 150)) {
return type;
if (type == AlarmInfoType.SPEED_CAMERA && (time < 15 || distance < 150)) {
return type.getPriority();
}
// 2nd level
if (time < 10 || distance < 150) {
return type + MAXIMUM;
return type.getPriority() + AlarmInfoType.MAXIMUM.getPriority();
}
return 0;
}

View file

@ -18,6 +18,7 @@ import net.osmand.plus.ClientContext;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
import net.osmand.util.MapUtils;
@ -888,7 +889,7 @@ public class RouteCalculationResult {
}
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
int vl = inf.updateDistanceAndGetPriority(time, d);
if(vl < value && (showCameras || inf.getType() != AlarmInfo.SPEED_CAMERA)){
if(vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)){
mostImportant = inf;
value = vl;
}

View file

@ -7,14 +7,20 @@ import java.util.List;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.binary.RouteDataObject;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.plus.*;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.RouteService;
@ -587,7 +593,7 @@ public class RoutingHelper {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0);
if (info != null) {
if (info.getType() != AlarmInfo.SPEED_CAMERA || showCameras) {
if (info.getType() != AlarmInfoType.SPEED_CAMERA || showCameras) {
voiceRouter.announceAlarm(info);
return info;
}

View file

@ -1,12 +1,11 @@
package net.osmand.plus.routing;
import alice.tuprolog.Struct;
import alice.tuprolog.Term;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.voice.AbstractPrologCommandPlayer;
import net.osmand.plus.voice.CommandBuilder;
@ -14,6 +13,8 @@ import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import alice.tuprolog.Struct;
import alice.tuprolog.Term;
public class VoiceRouter {
@ -232,7 +233,7 @@ public class VoiceRouter {
return;
}
long ms = System.currentTimeMillis();
if (alarm.getType() == AlarmInfo.SPEED_LIMIT) {
if (alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
if (waitAnnouncedSpeedLimit == 0) {
// wait 10 seconds before announcement
@ -253,7 +254,7 @@ public class VoiceRouter {
}
}
} else if (alarm.getType() == AlarmInfo.SPEED_CAMERA) {
} else if (alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
if (router.getSettings().SPEAK_SPEED_CAMERA.get() && ms - lastAnnouncedSpeedCamera > 100 * 1000) {
CommandBuilder p = getNewCommandPlayerToPlay();
if (p != null) {

View file

@ -16,6 +16,7 @@ import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.routing.AlarmInfo;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
@ -638,29 +639,29 @@ public class RouteInfoWidgetsFactory {
int locimgId = 0;
int textDy = 0;
String text = null;
if(alarm.getType() == AlarmInfo.SPEED_LIMIT) {
if(alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
text = alarm.getIntValue() +"";
if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_speed_limit_us;
textDy = (int) (-12 * scaleCoefficient);
}
} else if(alarm.getType() == AlarmInfo.SPEED_CAMERA) {
} else if(alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
locimgId = R.drawable.warnings_speed_camera;
text = "";
} else if(alarm.getType() == AlarmInfo.BORDER_CONTROL) {
} else if(alarm.getType() == AlarmInfoType.BORDER_CONTROL) {
text = "CLO";
} else if(alarm.getType() == AlarmInfo.TOLL_BOOTH) {
} else if(alarm.getType() == AlarmInfoType.TOLL_BOOTH) {
text = "$";
} else if(alarm.getType() == AlarmInfo.TRAFFIC_CALMING) {
} else if(alarm.getType() == AlarmInfoType.TRAFFIC_CALMING) {
locimgId = R.drawable.warnings_speed_bump;
text = "";
} else if(alarm.getType() == AlarmInfo.STOP) {
} else if(alarm.getType() == AlarmInfoType.STOP) {
// text = "STOP";
text = "";
}
visible = (text != null && text.length() > 0) || locimgId != 0;
if (visible) {
if (alarm.getType() == AlarmInfo.SPEED_CAMERA) {
if (alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
visible = cams;
} else {
visible = trafficWarnings;