From 17e0de132c1d0d45696f4b5076a6fa3b9a3e17c3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 14 Jul 2013 02:28:56 +0200 Subject: [PATCH] Add voice warnings (preparation) --- .../src/net/osmand/plus/OsmandSettings.java | 2 +- .../SettingsNavigationActivity.java | 2 +- .../osmand/plus/routing/RoutingHelper.java | 4 +++ .../net/osmand/plus/routing/VoiceRouter.java | 35 +++++++++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 8080a6c88f..62f6e2a6a9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -684,7 +684,7 @@ public class OsmandSettings { public final OsmandPreference SHOW_LANES = new BooleanPreference("show_lanes", true).makeProfile().cache(); public final OsmandPreference SPEAK_TRAFFIC_WARNINGS = new BooleanPreference("speak_traffic_warnings", true).makeProfile().cache(); - public final OsmandPreference SPEAK_SPEAD_CAMERAS = new BooleanPreference("speak_cameras", true).makeProfile().cache(); + public final OsmandPreference SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", true).makeProfile().cache(); public final OsmandPreference SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache(); public final OsmandPreference AVOID_TOLL_ROADS = new BooleanPreference("avoid_toll_roads", false).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index a1acbb9c4d..0a35481a5a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -174,7 +174,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { } else if (preference == speakAlarms) { showBooleanSettings(new String[] { getString(R.string.speak_traffic_warnings), getString(R.string.speak_cameras), getString(R.string.speak_speed_limit) }, new OsmandPreference[] { settings.SPEAK_TRAFFIC_WARNINGS, - settings.SPEAK_SPEAD_CAMERAS , settings.SPEAK_SPEED_LIMIT}); + settings.SPEAK_SPEED_CAMERA , settings.SPEAK_SPEED_LIMIT}); return true; } return false; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 7aa94d51a7..d95403a9b7 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -509,6 +509,10 @@ public class RoutingHelper { return route.getLeftTime(lastFixedLocation); } + public OsmandSettings getSettings() { + return settings; + } + public String getGeneralRouteInformation(){ int dist = getLeftDistance(); int hours = getLeftTime() / (60 * 60); diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 32ac99ab48..9f304bb05b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -27,6 +27,9 @@ public class VoiceRouter { private int currentStatus = STATUS_UNKNOWN; private float playGoAheadDist = 0; + private long lastAnnouncedSpeedLimit = 0; + private long lastAnnouncedSpeedCamera = 0; + private long lastAnnouncedWarning = 0; // private long lastTimeRouteRecalcAnnounced = 0; @@ -180,8 +183,36 @@ public class VoiceRouter { public void announceAlarm(AlarmInfo alarm) { - // TODO Auto-generated method stub - + if(alarm == null) { + return; + } + long ms = System.currentTimeMillis(); + if (alarm.getTime() == AlarmInfo.SPEED_LIMIT) { + if (router.getSettings().SPEAK_SPEED_LIMIT.get() && ms - lastAnnouncedSpeedLimit > 120 * 60 * 1000) { + CommandBuilder p = getNewCommandPlayerToPlay(); + if (p != null) { + lastAnnouncedSpeedLimit = ms; + p.speedAlarm().play(); + } + } + } else if (alarm.getTime() == AlarmInfo.SPEED_CAMERA) { + if (router.getSettings().SPEAK_SPEED_CAMERA.get() && ms - lastAnnouncedSpeedCamera > 120 * 60 * 1000) { + CommandBuilder p = getNewCommandPlayerToPlay(); + if (p != null) { + lastAnnouncedSpeedCamera = ms; + p.speedAlarm().play(); + } + } + } else { + if (router.getSettings().SPEAK_TRAFFIC_WARNINGS.get() && ms - lastAnnouncedWarning > 120 * 60 * 1000) { + CommandBuilder p = getNewCommandPlayerToPlay(); + if (p != null) { + lastAnnouncedWarning = ms; + p.speedAlarm().play(); + } + } + } + } /**