diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index b6ee68c83d..6cfaa1c3ad 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -149,8 +149,10 @@ public class OsmAndLocationProvider implements SensorEventListener { for (Object aLoc : loc) { visibleLocationPoints.add((LocationPoint) aLoc); } + locationPointsModified = System.currentTimeMillis(); } } + private Comparator getComparator(final net.osmand.Location lastLocation){ return new Comparator() { @Override @@ -179,21 +181,32 @@ public class OsmAndLocationProvider implements SensorEventListener { final net.osmand.Location lastLocation = getLastKnownLocation(); if (lastLocation != null && app.getRoutingHelper().isFollowingMode()) { String nameToAnnounce = null; + List approachPoints = new ArrayList(); + List announcePoints = new ArrayList(); for (LocationPoint point : locationPointsStates.keySet()) { double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(), point.getLatitude(), point.getLongitude()); int state = locationPointsStates.get(point); - if(state <= ANNOUNCED_ONCE && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastLocation.getSpeed(), d1, 150)) { + if (state <= ANNOUNCED_ONCE && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastLocation.getSpeed(), d1, 150)) { nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName(); locationPointsStates.remove(point); - } else if (state == NOT_ANNOUNCED && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastLocation.getSpeed(), d1, 500)){ - nameToAnnounce = (nameToAnnounce == null? "":", ")+point.getName(); + this.locationPointsModified = System.currentTimeMillis(); + app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); + announcePoints.add(point); + } else if (state == NOT_ANNOUNCED && app.getRoutingHelper().getVoiceRouter().isDistanceLess(lastLocation.getSpeed(), d1, 500)) { locationPointsStates.put(point, state + 1); + this.locationPointsModified = System.currentTimeMillis(); + app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); + approachPoints.add(point); } } - if(nameToAnnounce!= null) { - app.getRoutingHelper().getVoiceRouter().announceWaypoint(nameToAnnounce); + if (!announcePoints.isEmpty()) { + app.getRoutingHelper().getVoiceRouter().announceWaypoint(announcePoints); } + if (!approachPoints.isEmpty()) { + app.getRoutingHelper().getVoiceRouter().approachWaypoint(lastLocation, approachPoints); + } + } } @@ -621,8 +634,9 @@ public class OsmAndLocationProvider implements SensorEventListener { private void updateLocation(net.osmand.Location loc ) { - if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get()){ + if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get() && app.getRoutingHelper().isFollowingMode()){ sortVisibleLocationPoints(); + app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog(); announceVisibleLocations(); } for(OsmAndLocationListener l : locationListeners){ diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 7bc46bcea1..692eb11dd2 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -3,7 +3,10 @@ package net.osmand.plus.routing; import net.osmand.Location; import net.osmand.binary.RouteDataObject; +import net.osmand.data.FavouritePoint; +import net.osmand.data.LocationPoint; import net.osmand.plus.ApplicationMode; +import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmandSettings; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; @@ -16,6 +19,9 @@ import net.osmand.util.Algorithms; import alice.tuprolog.Struct; import alice.tuprolog.Term; import android.content.Context; +import net.osmand.util.MapUtils; + +import java.util.List; public class VoiceRouter { @@ -216,11 +222,76 @@ public class VoiceRouter { lastAnnouncedOffRoute = ms; } } - - public void announceWaypoint(String w) { + + public void announceWaypoint(List points) { CommandBuilder p = getNewCommandPlayerToPlay(); - if(p != null) { - p.arrivedAtWayPoint(getSpeakablePointName(w)).play(); + if (p == null){ + return; + } + String favoritesWaypoints = null; + String gpxWaypoints = null; + String poiWaypoints = null; + for (LocationPoint point : points) { + if (point instanceof GPXUtilities.WptPt) { + gpxWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + } else if (point instanceof FavouritePoint) { + favoritesWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + } else { + poiWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + } + } + if (gpxWaypoints != null){ + p.arrivedAtWayPoint(gpxWaypoints).play(); + } + if (favoritesWaypoints != null){ + p.arrivedAtFavorite(favoritesWaypoints).play(); + } + if (poiWaypoints != null){ + p.arrivedAtPoi(poiWaypoints).play(); + } + } + + public void approachWaypoint(Location location, List points){ + CommandBuilder p = getNewCommandPlayerToPlay(); + if (p == null){ + return; + } + String favoritesWaypoints = null; + String gpxWaypoints = null; + String poiWaypoints = null; + double favDistance = -1; + double gpxDistance = -1; + double poiDistance = -1; + for (LocationPoint point : points) { + if (point instanceof GPXUtilities.WptPt) { + gpxWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + //need to calculate distance to nearest point + if (favDistance == -1){ + favDistance = MapUtils.getDistance(location.getLatitude(), location.getLongitude(), + point.getLatitude(), point.getLongitude()); + } + } else if (point instanceof FavouritePoint) { + favoritesWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + if (gpxDistance == -1){ + gpxDistance = MapUtils.getDistance(location.getLatitude(), location.getLongitude(), + point.getLatitude(), point.getLongitude()); + } + } else { + poiWaypoints = (favoritesWaypoints == null ? "" : ", ") + point.getName(); + if (poiDistance == -1){ + poiDistance = MapUtils.getDistance(location.getLatitude(), location.getLongitude(), + point.getLatitude(), point.getLongitude()); + } + } + } + if (gpxWaypoints != null){ + p.goAhead(gpxDistance, null).andArriveAtWayPoint(gpxWaypoints).play(); + } + if (favoritesWaypoints != null) { + p.goAhead(favDistance, null).andArriveAtFavorite(favoritesWaypoints).play(); + } + if (poiWaypoints != null){ + p.goAhead(poiDistance, null).andArriveAtPoiWaypoint(poiWaypoints).play(); } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java index 15f15b19c3..eb8ead13fa 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java @@ -62,7 +62,7 @@ public class WaypointDialogHelper { closePointDialog = vi.inflate(R.layout.waypoint_reached, null); } - createView(closePointDialog, point); + updatePointInfoView(closePointDialog, point); closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black)); ((TextView)closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE); View all = closePointDialog.findViewById(R.id.all_points); @@ -91,7 +91,7 @@ public class WaypointDialogHelper { } } - private void createView(View localView, final LocationPoint point) { + private void updatePointInfoView(View localView, final LocationPoint point) { TextView text = (TextView) localView.findViewById(R.id.waypoint_text); text.setOnClickListener(new View.OnClickListener() { @Override @@ -102,7 +102,6 @@ public class WaypointDialogHelper { ((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(mapActivity, point.getColor())); Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation(); -// LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation(); String distance; if (lastKnownMapLocation != null) { int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), @@ -202,7 +201,7 @@ public class WaypointDialogHelper { ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4); v.findViewById(R.id.waypoint_icon).setLayoutParams(ll); } - createView(v, getItem(position)); + updatePointInfoView(v, getItem(position)); TextView text = (TextView) v.findViewById(R.id.waypoint_text); text.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 9108ee9c5e..226838829d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -184,7 +184,6 @@ public class MapControlsLayer extends OsmandMapLayer { (zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()): 0; rulerControl.setVerticalMargin(vmargin); checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode); - waypointDialogHelper.updateDialog(); } private void updatextColor(int textColor, int shadowColor, MapControls... mc) { diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index f565ce6f2f..2c3e74aaa5 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -87,7 +87,9 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio public void showControls(FrameLayout parent) { infoButton = addButton(parent, R.string.route_info, R.drawable.map_btn_signpost); if (showDialog){ - showDialog(); + if (getTargets().getPointToNavigate() == null){ + showDialog(); + } showDialog = false; } controlVisible = true; diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index 7da15d5ef6..11e2656626 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -28,7 +28,11 @@ public class CommandBuilder { protected static final String C_AND_ARRIVE_INTERMEDIATE = "and_arrive_intermediate"; //$NON-NLS-1$ protected static final String C_REACHED_INTERMEDIATE = "reached_intermediate"; //$NON-NLS-1$ protected static final String C_AND_ARRIVE_WAYPOINT = "and_arrive_waypoint"; //$NON-NLS-1$ + protected static final String C_AND_ARRIVE_FAVORITE = "and_arrive_favorite"; //$NON-NLS-1$ + protected static final String C_AND_ARRIVE_POI_WAYPOINT = "and_arrive_poi"; //$NON-NLS-1$ protected static final String C_REACHED_WAYPOINT = "reached_waypoint"; //$NON-NLS-1$ + protected static final String C_REACHED_FAVORITE = "reached_favorite"; //$NON-NLS-1$ + protected static final String C_REACHED_POI = "reached_poi"; //$NON-NLS-1$ protected static final String C_THEN = "then"; //$NON-NLS-1$ protected static final String C_SPEAD_ALARM = "speed_alarm"; //$NON-NLS-1$ protected static final String C_ATTENTION = "attention"; //$NON-NLS-1$ @@ -190,9 +194,13 @@ public class CommandBuilder { public CommandBuilder arrivedAtWayPoint(String name) { return addCommand(C_REACHED_WAYPOINT, name); } - - public CommandBuilder andArriveAtWayPoint(String name){ - return addCommand(C_AND_ARRIVE_WAYPOINT, name); + + public CommandBuilder arrivedAtFavorite(String name) { + return addCommand(C_REACHED_FAVORITE, name); + } + + public CommandBuilder arrivedAtPoi(String name) { + return addCommand(C_REACHED_POI, name); } public CommandBuilder bearLeft(Term streetName){ @@ -223,8 +231,6 @@ public class CommandBuilder { return alt(prepareStruct(C_ROUTE_RECALC, dist, time), prepareStruct(C_ROUTE_RECALC, dist)); } - - public void play(){ this.commandPlayer.playCommands(this); } @@ -234,8 +240,15 @@ public class CommandBuilder { return this.commandPlayer.execute(listStruct); } - + public CommandBuilder andArriveAtWayPoint(String name){ + return addCommand(C_AND_ARRIVE_WAYPOINT, name); + } + public CommandBuilder andArriveAtPoiWaypoint(String name) { + return addCommand(C_AND_ARRIVE_POI_WAYPOINT, name); + } - + public CommandBuilder andArriveAtFavorite(String name) { + return addCommand(C_AND_ARRIVE_FAVORITE, name); + } } \ No newline at end of file