Skip to content

Commit 2a5c946

Browse files
committed
osmandapp#3721 and osmandapp#8108 initial implementation.
- RouteCalculationResult attachAlarmInfo method extended to add max speed to speed camera AlarmInfo taken either from speed camera point (preferred) or from RouteSegmentResult. - WaypointHelper getMostImportantAlarm and announceVisibleLocations updated to attach actual distance to speed camera AlarmInfo. - AlarmWidget extended with ability to show max speed for speed camera when available. - VoiceRouter.announceAlarm extended with special handling for speed camera announcement to announce distance and max speed when available. - CommandBuilder / JsCommandBuilder extended with new speedCameraAlarm method, which allows announce speed camera with distance and max speed. - TestVoiceActivity extended to test speed camera with distance and max speed announcement.
1 parent e78c8eb commit 2a5c946

File tree

8 files changed

+120
-16
lines changed

8 files changed

+120
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="92dp"
3+
android:height="92dp"
4+
android:viewportWidth="92"
5+
android:viewportHeight="92">
6+
<path
7+
android:pathData="M86,46C86,68.0914 68.0914,86 46,86C23.9086,86 6,68.0914 6,46C6,23.9086 23.9086,6 46,6C68.0914,6 86,23.9086 86,46Z"
8+
android:fillColor="#FFFFFF"/>
9+
<path
10+
android:pathData="M46,80C64.7777,80 80,64.7777 80,46C80,27.2223 64.7777,12 46,12C27.2223,12 12,27.2223 12,46C12,64.7777 27.2223,80 46,80ZM46,86C68.0914,86 86,68.0914 86,46C86,23.9086 68.0914,6 46,6C23.9086,6 6,23.9086 6,46C6,68.0914 23.9086,86 46,86Z"
11+
android:fillColor="#F03434"
12+
android:fillType="evenOdd"/>
13+
<path
14+
android:pathData="M2,60C0.895,60 0,60.895 0,62V90C0,91.105 0.895,92 2,92H43C44.105,92 45,91.105 45,90V62C45,60.895 44.105,60 43,60H2Z"
15+
android:fillColor="#000000"/>
16+
<path
17+
android:pathData="M2,62V90H43V62H2Z"
18+
android:fillColor="#FFFFFF"/>
19+
<path
20+
android:pathData="M6,64C4.895,64 4,64.895 4,66V86C4,87.105 4.895,88 6,88H24.5C25.605,88 26.5,87.105 26.5,86V66C26.5,64.895 25.605,64 24.5,64H6ZM12.5,74C15.538,74 18,76.462 18,79.5C18,82.538 15.538,85 12.5,85C9.462,85 7,82.538 7,79.5C7,76.462 9.462,74 12.5,74ZM20,66.5C21.933,66.5 23.5,68.067 23.5,70C23.5,71.933 21.933,73.5 20,73.5C18.067,73.5 16.5,71.933 16.5,70C16.5,68.067 18.067,66.5 20,66.5Z"
21+
android:fillColor="#000000"
22+
android:fillType="evenOdd"/>
23+
<path
24+
android:pathData="M12.5,76C14.433,76 16,77.567 16,79.5C16,81.433 14.433,83 12.5,83C10.567,83 9,81.433, 9,79.5C9,77.567 10.567,76 12.5,76ZM20,68C21.105,68 22,68.895 22,70C22,71.105 21.105,72 20,72C18.895,72 18,71.105 18,70C18,68.895 18.895,68 20,68Z"
25+
android:fillColor="#000000" />
26+
<path
27+
android:pathData="M28,67H33V80H28V67Z"
28+
android:fillColor="#000000"/>
29+
<path
30+
android:pathData="M36,70H34.5V81.5H28V83H36V80H41V72.5H36V70Z"
31+
android:fillColor="#000000" />
32+
</vector>

OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ private void addButtons(final LinearLayout ll, CommandPlayer p) {
214214

215215
addButton(ll, "Attention prompts:", builder(p));
216216
addButton(ll, "\u25BA (9.1) You are exceeding the speed limit '50' (18 m/s)", builder(p).speedAlarm(50, 18f));
217-
addButton(ll, "\u25BA (9.2) Attention, speed camera", builder(p).attention("SPEED_CAMERA"));
218-
addButton(ll, "\u25BA (9.3) Attention, border control", builder(p).attention("BORDER_CONTROL"));
219-
addButton(ll, "\u25BA (9.4) Attention, railroad crossing", builder(p).attention("RAILWAY"));
220-
addButton(ll, "\u25BA (9.5) Attention, traffic calming", builder(p).attention("TRAFFIC_CALMING"));
221-
addButton(ll, "\u25BA (9.6) Attention, toll booth", builder(p).attention("TOLL_BOOTH"));
222-
addButton(ll, "\u25BA (9.7) Attention, stop sign", builder(p).attention("STOP"));
223-
addButton(ll, "\u25BA (9.8) Attention, pedestrian crosswalk", builder(p).attention("PEDESTRIAN"));
224-
addButton(ll, "\u25BA (9.9) Attention, tunnel", builder(p).attention("TUNNEL"));
217+
addButton(ll, "\u25BA (9.2) Attention, speed camera, distance 650m, speed limit '50' (18 m/s)", builder(p).speedCameraAlarm(650f, 50));
218+
addButton(ll, "\u25BA (9.3) Attention, speed camera", builder(p).attention("SPEED_CAMERA"));
219+
addButton(ll, "\u25BA (9.4) Attention, border control", builder(p).attention("BORDER_CONTROL"));
220+
addButton(ll, "\u25BA (9.5) Attention, railroad crossing", builder(p).attention("RAILWAY"));
221+
addButton(ll, "\u25BA (9.6) Attention, traffic calming", builder(p).attention("TRAFFIC_CALMING"));
222+
addButton(ll, "\u25BA (9.7) Attention, toll booth", builder(p).attention("TOLL_BOOTH"));
223+
addButton(ll, "\u25BA (9.8) Attention, stop sign", builder(p).attention("STOP"));
224+
addButton(ll, "\u25BA (9.9) Attention, pedestrian crosswalk", builder(p).attention("PEDESTRIAN"));
225+
addButton(ll, "\u25BA (9.10) Attention, tunnel", builder(p).attention("TUNNEL"));
225226

226227
addButton(ll, "Other prompts:", builder(p));
227228
addButton(ll, "\u25BA (10.1) GPS signal lost", builder(p).gpsLocationLost());

OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ public AlarmInfo getMostImportantAlarm(SpeedConstants sc, boolean showCameras) {
230230
if (!atd.isTurnStateActive(0, d, STATE_LONG_PNT_APPROACH)) {
231231
break;
232232
}
233+
234+
// Set actual distance to speed camera
235+
if (inf.getType() == AlarmInfoType.SPEED_CAMERA) {
236+
inf.setFloatValue(d);
237+
}
238+
233239
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
234240
int vl = inf.updateDistanceAndGetPriority(time, d);
235241
if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
@@ -460,7 +466,15 @@ public void announceVisibleLocations() {
460466
} else if (type == ALARMS) {
461467
for (LocationPointWrapper pw : approachPoints) {
462468
AlarmInfo alarm = (AlarmInfo) pw.point;
463-
voiceRouter.announceAlarm(new AlarmInfo(alarm.getType(), -1), lastKnownLocation.getSpeed());
469+
AlarmInfo alarmCopy = new AlarmInfo(alarm.getType(), -1);
470+
471+
// Set actual distance and copy max speed to speed camera
472+
if (alarmCopy.getType() == AlarmInfoType.SPEED_CAMERA){
473+
alarmCopy.setFloatValue(route.getDistanceToPoint(alarm.getLocationIndex()));
474+
alarmCopy.setIntValue(alarm.getIntValue());
475+
}
476+
477+
voiceRouter.announceAlarm(alarmCopy, lastKnownLocation.getSpeed());
464478
lastAnnouncedAlarms.put(alarm.getType(), alarm);
465479
}
466480
} else if (type == FAVORITES) {

OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.osmand.map.WorldRegion;
1616
import net.osmand.plus.OsmandApplication;
1717
import net.osmand.plus.R;
18+
import net.osmand.plus.helpers.enums.SpeedConstants;
1819
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
1920
import net.osmand.plus.settings.backend.ApplicationMode;
2021
import net.osmand.router.ExitInfo;
@@ -260,10 +261,12 @@ private static double getDistanceToLocation(List<Location> locations, LatLon p,
260261
locations.get(currentLocation).getLatitude(), locations.get(currentLocation).getLongitude());
261262
}
262263

263-
private static void attachAlarmInfo(List<AlarmInfo> alarms, RouteSegmentResult res, int intId, int locInd) {
264+
private static void attachAlarmInfo(List<AlarmInfo> alarms, RouteSegmentResult res, int intId, int locInd, SpeedConstants sc) {
264265
int[] pointTypes = res.getObject().getPointTypes(intId);
265266
if (pointTypes != null) {
266267
RouteRegion reg = res.getObject().region;
268+
float maxSpeed = -1;
269+
AlarmInfo speedCameraAlarmInfo = null;
267270
for (int r = 0; r < pointTypes.length; r++) {
268271
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
269272
int x31 = res.getObject().getPoint31XTile(intId);
@@ -272,9 +275,32 @@ private static void attachAlarmInfo(List<AlarmInfo> alarms, RouteSegmentResult r
272275
loc.setLatitude(MapUtils.get31LatitudeY(y31));
273276
loc.setLongitude(MapUtils.get31LongitudeX(x31));
274277
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, locInd, loc);
278+
275279
// For STOP first check if it has directional info
276280
if ((info != null) && !((info.getType() == AlarmInfoType.STOP) && !res.getObject().isStopApplicable(res.isForwardDirection(), intId, res.getStartPointIndex(), res.getEndPointIndex()))) {
277281
alarms.add(info);
282+
283+
if (info.getType() == AlarmInfoType.SPEED_CAMERA) {
284+
speedCameraAlarmInfo = info;
285+
}
286+
}
287+
288+
if (maxSpeed <= 0 || maxSpeed == RouteDataObject.NONE_MAX_SPEED) {
289+
maxSpeed = typeRule.maxSpeed();
290+
}
291+
}
292+
293+
if (speedCameraAlarmInfo != null) {
294+
if (maxSpeed <= 0 || maxSpeed == RouteDataObject.NONE_MAX_SPEED) {
295+
maxSpeed = res.getObject().getMaximumSpeed(res.isForwardDirection());
296+
}
297+
298+
if (maxSpeed > 0 && maxSpeed != RouteDataObject.NONE_MAX_SPEED) {
299+
if (sc.imperial) {
300+
speedCameraAlarmInfo.setIntValue(Math.round(maxSpeed * 3.6f / 1.6f));
301+
} else {
302+
speedCameraAlarmInfo.setIntValue(Math.round(maxSpeed * 3.6f));
303+
}
278304
}
279305
}
280306
}
@@ -378,7 +404,7 @@ private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionI
378404
lastHeight = h;
379405
}
380406
locations.add(n);
381-
attachAlarmInfo(alarms, s, i, locations.size());
407+
attachAlarmInfo(alarms, s, i, locations.size(), ctx.getSettings().SPEED_SYSTEM.get());
382408
segmentsToPopulate.add(s);
383409
if (i == s.getEndPointIndex()) {
384410
break;

OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,19 @@ public void announceAlarm(AlarmInfo info, float speed) {
321321
AlarmInfoType type = info.getType();
322322
if (type == AlarmInfoType.SPEED_LIMIT) {
323323
announceSpeedAlarm(info.getIntValue(), speed);
324+
} else if (type == AlarmInfoType.SPEED_CAMERA) {
325+
OsmandSettings settings = router.getSettings();
326+
if (settings.SPEAK_SPEED_CAMERA.get()) {
327+
announceSpeedCameraAlarm(info.getFloatValue(), info.getIntValue());
328+
}
324329
} else {
325330
OsmandSettings settings = router.getSettings();
326331
boolean speakTrafficWarnings = settings.SPEAK_TRAFFIC_WARNINGS.get();
327332
boolean speakTunnels = type == AlarmInfoType.TUNNEL && settings.SPEAK_TUNNELS.get();
328333
boolean speakPedestrian = type == AlarmInfoType.PEDESTRIAN && settings.SPEAK_PEDESTRIAN.get();
329-
boolean speakSpeedCamera = type == AlarmInfoType.SPEED_CAMERA && settings.SPEAK_SPEED_CAMERA.get();
330-
boolean speakPrefType = type == AlarmInfoType.TUNNEL || type == AlarmInfoType.PEDESTRIAN || type == AlarmInfoType.SPEED_CAMERA;
334+
boolean speakPrefType = type == AlarmInfoType.TUNNEL || type == AlarmInfoType.PEDESTRIAN;
331335

332-
if (speakSpeedCamera || speakPedestrian || speakTunnels || speakTrafficWarnings && !speakPrefType) {
336+
if (speakPedestrian || speakTunnels || speakTrafficWarnings && !speakPrefType) {
333337
CommandBuilder p = getNewCommandPlayerToPlay();
334338
if (p != null) {
335339
p.attention(String.valueOf(type));
@@ -365,7 +369,19 @@ public void announceSpeedAlarm(int maxSpeed, float speed) {
365369
}
366370
}
367371
}
368-
372+
373+
private void announceSpeedCameraAlarm(double dist, int maxSpeed) {
374+
CommandBuilder p = getNewCommandPlayerToPlay();
375+
if (p != null) {
376+
if (dist > 0 && maxSpeed > 0) {
377+
p.speedCameraAlarm(dist, maxSpeed);
378+
} else {
379+
p.attention(String.valueOf(AlarmInfoType.SPEED_CAMERA));
380+
}
381+
}
382+
play(p);
383+
}
384+
369385
private boolean isTargetPoint(NextDirectionInfo info) {
370386
boolean in = info != null && info.intermediatePoint;
371387
boolean target = info == null || info.directionInfo == null

OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/AlarmWidget.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ public AlarmWidgetInfo createWidgetInfo(@NonNull AlarmInfo alarm) {
265265
}
266266
text = alarm.getIntValue() + "";
267267
} else if (alarm.getType() == AlarmInfo.AlarmInfoType.SPEED_CAMERA) {
268-
locImgId = R.drawable.warnings_speed_camera;
268+
int maxSpeed = alarm.getIntValue();
269+
if (maxSpeed > 0) {
270+
locImgId = R.drawable.warnings_speed_camera_w_limit;
271+
text = maxSpeed + "";
272+
}
273+
else {
274+
locImgId = R.drawable.warnings_speed_camera;
275+
}
269276
} else if (alarm.getType() == AlarmInfo.AlarmInfoType.BORDER_CONTROL) {
270277
locImgId = R.drawable.warnings_border_control;
271278
} else if (alarm.getType() == AlarmInfo.AlarmInfoType.HAZARD) {

OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract class CommandBuilder {
3030
protected static final String C_REACHED_POI = "reached_poi";
3131
protected static final String C_THEN = "then";
3232
protected static final String C_SPEAD_ALARM = "speed_alarm";
33+
protected static final String C_SPEED_CAMERA_ALARM = "speed_camera_alarm";
3334
protected static final String C_ATTENTION = "attention";
3435
protected static final String C_OFF_ROUTE = "off_route";
3536
protected static final String C_BACK_ON_ROUTE = "back_on_route";
@@ -69,6 +70,8 @@ public List<String> getCommandsList() {
6970

7071
public abstract CommandBuilder speedAlarm(int maxSpeed, float speed);
7172

73+
public abstract CommandBuilder speedCameraAlarm(double dist, int maxSpeed);
74+
7275
public abstract CommandBuilder attention(String type);
7376

7477
public abstract CommandBuilder offRoute(double dist);

OsmAnd/src/net/osmand/plus/voice/JsCommandBuilder.java

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public CommandBuilder speedAlarm(int maxSpeed, float speed) {
7979
return addCommand(C_SPEAD_ALARM, maxSpeed, speed);
8080
}
8181

82+
@Override
83+
public CommandBuilder speedCameraAlarm(double dist, int maxSpeed) {
84+
return addCommand(C_SPEED_CAMERA_ALARM, dist, maxSpeed);
85+
}
86+
8287
@Override
8388
public CommandBuilder attention(String type) {
8489
return addCommand(C_ATTENTION, type);

0 commit comments

Comments
 (0)