From 6e5b377fe224858a6d7a2ebaef767eb644ed376a Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 12 Feb 2014 01:21:11 +0100 Subject: [PATCH] Introduce enum alarm info type. And let define specific voice rules in prolog like # attention('SPEED_CAMERA') -- ['attention_speed_camera.ogg']. --- .../net/osmand/plus/routing/AlarmInfo.java | 57 ++++++++++++------- .../plus/routing/RouteCalculationResult.java | 3 +- .../osmand/plus/routing/RoutingHelper.java | 12 +++- .../net/osmand/plus/routing/VoiceRouter.java | 9 +-- .../mapwidgets/RouteInfoWidgetsFactory.java | 15 ++--- 5 files changed, 60 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java b/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java index 99418ffba8..1bcd74c822 100644 --- a/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/AlarmInfo.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 25953b5952..2b72a7531c 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 4ba92b4af3..7eaa336022 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index fa5a917579..d94ebb2f46 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 59f4276c27..db6ce04a84 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -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;