Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-08-04 15:00:20 +02:00
commit a83603cd77
6 changed files with 121 additions and 23 deletions

View file

@ -149,8 +149,10 @@ public class OsmAndLocationProvider implements SensorEventListener {
for (Object aLoc : loc) {
visibleLocationPoints.add((LocationPoint) aLoc);
}
locationPointsModified = System.currentTimeMillis();
}
}
private Comparator<Object> getComparator(final net.osmand.Location lastLocation){
return new Comparator<Object>() {
@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<LocationPoint> approachPoints = new ArrayList<LocationPoint>();
List<LocationPoint> announcePoints = new ArrayList<LocationPoint>();
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){

View file

@ -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<LocationPoint> 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<LocationPoint> 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();
}
}

View file

@ -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

View file

@ -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) {

View file

@ -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;

View file

@ -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);
}
}