Added settings value for announce_favorites. Added voice calling for favorite points

This commit is contained in:
Denis_Bars 2014-08-02 18:14:04 +03:00
parent c889e99343
commit 4a2a6e81a7
7 changed files with 144 additions and 68 deletions

View file

@ -1940,4 +1940,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string> <string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string>
<string name="navigation_intent_invalid">Invalid format: %s</string> <string name="navigation_intent_invalid">Invalid format: %s</string>
<string name="hide_all_waypoints">Remove all</string> <string name="hide_all_waypoints">Remove all</string>
<string name="announce_nearby_favorites">Announce nearby favorites</string>
</resources> </resources>

View file

@ -1,16 +1,16 @@
package net.osmand.plus; package net.osmand.plus;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap;
import java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.LinkedList;
import java.util.List;
import android.widget.ListView;
import net.osmand.GeoidAltitudeCorrection; import net.osmand.GeoidAltitudeCorrection;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.NavigationInfo; import net.osmand.access.NavigationInfo;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
@ -67,8 +67,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
private float[] mGeoMags = new float[3]; private float[] mGeoMags = new float[3];
private float previousCorrectionValue = 360; private float previousCorrectionValue = 360;
private static final boolean USE_KALMAN_FILTER = true; private static final boolean USE_KALMAN_FILTER = true;
private static final float KALMAN_COEFFICIENT = 0.04f; private static final float KALMAN_COEFFICIENT = 0.04f;
@ -105,6 +103,114 @@ public class OsmAndLocationProvider implements SensorEventListener {
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS; private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS;
private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS; private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS;
private static final int NOT_ANNOUNCED = 0;
private static final int ANNOUNCED_ONCE = 1;
private static final int ANNOUNCED_TWICE = 2;
private ConcurrentHashMap<LocationPoint , Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
private List<LocationPoint> notAnnouncedPoints = new CopyOnWriteArrayList<LocationPoint>();
private List<LocationPoint> visibleLocationPoints = new CopyOnWriteArrayList<LocationPoint>();
private long locationPointsModified;
public List<LocationPoint> getVisibleLocationPoints() {
return visibleLocationPoints;
}
public void setVisibleLocationPoints(List<LocationPoint> points) {
locationPointsStates.clear();
visibleLocationPoints.clear();
notAnnouncedPoints.clear();
if (points == null){
return;
}
for(int i = 0 ;i<points.size(); i++){
locationPointsStates.put(points.get(i), NOT_ANNOUNCED);
notAnnouncedPoints.add(points.get(i));
visibleLocationPoints.add(points.get(i));
}
sortVisibleLocationPoints();
}
public void addVisibleLocationPoint(LocationPoint lp) {
this.locationPointsStates.put(lp, NOT_ANNOUNCED);
this.locationPointsModified = System.currentTimeMillis();
sortVisibleLocationPoints();
}
public void clearAllVisiblePoints() {
this.locationPointsStates.clear();
this.visibleLocationPoints.clear();
this.notAnnouncedPoints.clear();
this.locationPointsModified = System.currentTimeMillis();
}
public void sortVisibleLocationPoints() {
net.osmand.Location lastLocation = getLastKnownLocation();
if (lastLocation != null) {
Object[] loc = notAnnouncedPoints.toArray();
Arrays.sort(loc, getComparator(lastLocation));
notAnnouncedPoints.clear();
visibleLocationPoints.clear();
for (Object aLoc : loc) {
notAnnouncedPoints.add((LocationPoint) aLoc);
visibleLocationPoints.add((LocationPoint) aLoc);
}
}
}
private Comparator<Object> getComparator(final net.osmand.Location lastLocation){
return new Comparator<Object>() {
@Override
public int compare(Object locationPoint, Object locationPoint2) {
double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
((LocationPoint)locationPoint).getLatitude(), ((LocationPoint)locationPoint).getLongitude());
double d2 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
((LocationPoint)locationPoint2).getLatitude(), ((LocationPoint)locationPoint2).getLongitude());
return Double.compare(d1, d2);
}
};
}
public long getLocationPointsModified() {
return locationPointsModified;
}
public void removeVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints = removeFromList(visibleLocationPoints, lp);
this.notAnnouncedPoints = removeFromList(notAnnouncedPoints, lp);
this.locationPointsStates.remove(lp);
this.locationPointsModified = System.currentTimeMillis();
}
private void announceVisibleLocations() {
final net.osmand.Location lastLocation = getLastKnownLocation();
if (lastLocation != null) {
for (LocationPoint point : notAnnouncedPoints) {
double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
point.getLatitude(), point.getLongitude());
int state = locationPointsStates.get(point);
if (d1 <= 300 && (state == NOT_ANNOUNCED || state == ANNOUNCED_ONCE)) {
app.getRoutingHelper().getVoiceRouter().announceWaypoint(point.getName());
locationPointsStates.put(point, state + 1);
} else {
notAnnouncedPoints = removeFromList(notAnnouncedPoints, point);
}
}
}
}
public List<LocationPoint> removeFromList(List<LocationPoint> items, Object item){
List<LocationPoint> newArray = new ArrayList<LocationPoint>();
Object[] oldArray = items.toArray();
for (int i=0; i<oldArray.length; i++){
if (!item.equals(oldArray[i])){
newArray.add((LocationPoint)oldArray[i]);
}
}
items.clear();
return new CopyOnWriteArrayList<LocationPoint>(newArray);
}
public class SimulationProvider { public class SimulationProvider {
private int currentRoad; private int currentRoad;
@ -518,6 +624,10 @@ public class OsmAndLocationProvider implements SensorEventListener {
private void updateLocation(net.osmand.Location loc ) { private void updateLocation(net.osmand.Location loc ) {
if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get()){
sortVisibleLocationPoints();
announceVisibleLocations();
}
for(OsmAndLocationListener l : locationListeners){ for(OsmAndLocationListener l : locationListeners){
l.updateLocation(loc); l.updateLocation(loc);
} }

View file

@ -819,7 +819,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> GPX_SPEAK_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_SPEAK_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_FAVORITES = new BooleanPreference("announce_nearby_favorites", false).makeGlobal().cache();
public final OsmandPreference<Boolean> AVOID_TOLL_ROADS = new BooleanPreference("avoid_toll_roads", false).makeProfile().cache(); public final OsmandPreference<Boolean> AVOID_TOLL_ROADS = new BooleanPreference("avoid_toll_roads", false).makeProfile().cache();
public final OsmandPreference<Boolean> AVOID_MOTORWAY = new BooleanPreference("avoid_motorway", false).makeProfile().cache(); public final OsmandPreference<Boolean> AVOID_MOTORWAY = new BooleanPreference("avoid_motorway", false).makeProfile().cache();

View file

@ -25,8 +25,6 @@ public class TargetPointsHelper {
private RoutingHelper routingHelper; private RoutingHelper routingHelper;
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>(); private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>();
private OsmandApplication ctx; private OsmandApplication ctx;
private List<LocationPoint> visibleLocationPoints = new CopyOnWriteArrayList<LocationPoint>();
private long locationPointsModified;
public TargetPointsHelper(OsmandApplication ctx){ public TargetPointsHelper(OsmandApplication ctx){
this.ctx = ctx; this.ctx = ctx;
@ -69,47 +67,7 @@ public class TargetPointsHelper {
return intermediatePoints; return intermediatePoints;
} }
public List<LocationPoint> getVisibleLocationPoints() {
return visibleLocationPoints;
}
public void addVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints.add(lp);
this.locationPointsModified = System.currentTimeMillis();
sortVisibleLocationPoints();
}
public void removeAllVisiblePoints() {
this.locationPointsModified = System.currentTimeMillis();
visibleLocationPoints.clear();
}
public void sortVisibleLocationPoints() {
final Location lastLocation = ctx.getLocationProvider().getLastKnownLocation();
if(lastLocation != null) {
Collections.sort(this.visibleLocationPoints, new Comparator<LocationPoint>() {
@Override
public int compare(LocationPoint locationPoint, LocationPoint locationPoint2) {
double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
locationPoint.getLatitude(), locationPoint.getLongitude());
double d2 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
locationPoint2.getLatitude(), locationPoint2.getLongitude());
return Double.compare(d1, d2);
}
});
this.locationPointsModified = System.currentTimeMillis();
}
}
public long getLocationPointsModified() {
return locationPointsModified;
}
public void removeVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints.remove(lp);
this.locationPointsModified = System.currentTimeMillis();
}
public List<LatLon> getIntermediatePointsWithTarget() { public List<LatLon> getIntermediatePointsWithTarget() {

View file

@ -13,7 +13,6 @@ import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.NavigationService; import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -26,7 +25,6 @@ import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.sherpafy.WaypointDialogHelper;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.RouteCalculationProgress; import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RouteSegmentResult; import net.osmand.router.RouteSegmentResult;
@ -537,6 +535,11 @@ public class RoutingHelper {
} }
private synchronized void setNewRoute(RouteCalculationResult res, Location start){ private synchronized void setNewRoute(RouteCalculationResult res, Location start){
if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get()){
app.getLocationProvider().setVisibleLocationPoints(new ArrayList<LocationPoint>(app.getFavorites().getFavouritePoints()));
} else {
app.getLocationProvider().clearAllVisiblePoints();
}
final boolean newRoute = !this.route.isCalculated(); final boolean newRoute = !this.route.isCalculated();
route = res; route = res;
if (isFollowingMode) { if (isFollowingMode) {

View file

@ -1,7 +1,6 @@
package net.osmand.plus.sherpafy; package net.osmand.plus.sherpafy;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -17,7 +16,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.*; import android.widget.*;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.*; import net.osmand.plus.*;
import net.osmand.plus.activities.FavouritesActivity; import net.osmand.plus.activities.FavouritesActivity;
@ -35,7 +33,7 @@ public class WaypointDialogHelper {
private MapActivity mapActivity; private MapActivity mapActivity;
private OsmandApplication app; private OsmandApplication app;
private FrameLayout mainLayout; private FrameLayout mainLayout;
private TargetPointsHelper targetPointsHelper; private OsmAndLocationProvider locationProvider;
public static boolean OVERLAP_LAYOUT = true; public static boolean OVERLAP_LAYOUT = true;
private long uiModified; private long uiModified;
@ -43,14 +41,14 @@ public class WaypointDialogHelper {
public WaypointDialogHelper(MapActivity mapActivity) { public WaypointDialogHelper(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication(); this.app = mapActivity.getMyApplication();
targetPointsHelper = this.app.getTargetPointsHelper(); locationProvider = this.app.getLocationProvider();
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0); this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0);
} }
public void updateDialog() { public void updateDialog() {
List<LocationPoint> vlp = targetPointsHelper.getVisibleLocationPoints(); List<LocationPoint> vlp = locationProvider.getVisibleLocationPoints();
long locationPointsModified = targetPointsHelper.getLocationPointsModified(); long locationPointsModified = locationProvider.getLocationPointsModified();
if (locationPointsModified != uiModified) { if (locationPointsModified != uiModified) {
uiModified = locationPointsModified; uiModified = locationPointsModified;
if (vlp.isEmpty()) { if (vlp.isEmpty()) {
@ -80,7 +78,7 @@ public class WaypointDialogHelper {
btnN.setOnClickListener(new View.OnClickListener() { btnN.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
targetPointsHelper.removeVisibleLocationPoint(point); locationProvider.removeVisibleLocationPoint(point);
updateDialog(); updateDialog();
} }
}); });
@ -189,7 +187,7 @@ public class WaypointDialogHelper {
} }
public void showAllDialog(){ public void showAllDialog(){
final List<LocationPoint> visibleLocationPoints = targetPointsHelper.getVisibleLocationPoints(); final List<LocationPoint> visibleLocationPoints = locationProvider.getVisibleLocationPoints();
final ArrayAdapter<LocationPoint> listAdapter = new ArrayAdapter<LocationPoint>(mapActivity, R.layout.waypoint_reached, R.id.title, final ArrayAdapter<LocationPoint> listAdapter = new ArrayAdapter<LocationPoint>(mapActivity, R.layout.waypoint_reached, R.id.title,
visibleLocationPoints) { visibleLocationPoints) {
@Override @Override
@ -220,9 +218,9 @@ public class WaypointDialogHelper {
remove.setOnClickListener(new View.OnClickListener() { remove.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
LocationPoint point = targetPointsHelper.getVisibleLocationPoints().get(position); LocationPoint point = locationProvider.getVisibleLocationPoints().get(position);
remove(point); remove(point);
targetPointsHelper.removeVisibleLocationPoint(point); locationProvider.removeVisibleLocationPoint(point);
notifyDataSetChanged(); notifyDataSetChanged();
} }
}); });
@ -249,7 +247,7 @@ public class WaypointDialogHelper {
builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() { builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
targetPointsHelper.removeAllVisiblePoints(); locationProvider.clearAllVisiblePoints();
updateDialog(); updateDialog();
} }
}); });

View file

@ -210,11 +210,16 @@ public class MapRoutePreferencesControl extends MapControls {
if (gpxParam.id == R.string.fast_route_mode) { if (gpxParam.id == R.string.fast_route_mode) {
settings.FAST_ROUTE_MODE.set(selected); settings.FAST_ROUTE_MODE.set(selected);
} }
if (gpxParam.id == R.string.announce_nearby_favorites){
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
}
} }
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) { private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>(); List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
list.add(new OtherLocalRoutingParameter(R.string.announce_nearby_favorites,
mapActivity.getString(R.string.announce_nearby_favorites), settings.ANNOUNCE_NEARBY_FAVORITES.get()));
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute(); GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ; boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
if(!osmandRouter) { if(!osmandRouter) {
@ -255,6 +260,7 @@ public class MapRoutePreferencesControl extends MapControls {
list.add(rp); list.add(rp);
} }
} }
return list; return list;
} }
private String getString(int id) { private String getString(int id) {