Added settings value for announce_favorites. Added voice calling for favorite points
This commit is contained in:
parent
c889e99343
commit
4a2a6e81a7
7 changed files with 144 additions and 68 deletions
|
@ -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="navigation_intent_invalid">Invalid format: %s</string>
|
||||
<string name="hide_all_waypoints">Remove all</string>
|
||||
<string name="announce_nearby_favorites">Announce nearby favorites</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import android.widget.ListView;
|
||||
import net.osmand.GeoidAltitudeCorrection;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.NavigationInfo;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
|
@ -66,9 +66,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
private float[] mGravs = new float[3];
|
||||
private float[] mGeoMags = new float[3];
|
||||
private float previousCorrectionValue = 360;
|
||||
|
||||
|
||||
|
||||
|
||||
private static final boolean USE_KALMAN_FILTER = true;
|
||||
private static final float KALMAN_COEFFICIENT = 0.04f;
|
||||
|
||||
|
@ -104,8 +102,116 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
private float[] mRotationM = new float[9];
|
||||
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_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 {
|
||||
private int currentRoad;
|
||||
private int currentSegment;
|
||||
|
@ -518,6 +624,10 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
|
||||
|
||||
private void updateLocation(net.osmand.Location loc ) {
|
||||
if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get()){
|
||||
sortVisibleLocationPoints();
|
||||
announceVisibleLocations();
|
||||
}
|
||||
for(OsmAndLocationListener l : locationListeners){
|
||||
l.updateLocation(loc);
|
||||
}
|
||||
|
|
|
@ -818,8 +818,8 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", 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> 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_MOTORWAY = new BooleanPreference("avoid_motorway", false).makeProfile().cache();
|
||||
|
|
|
@ -25,8 +25,6 @@ public class TargetPointsHelper {
|
|||
private RoutingHelper routingHelper;
|
||||
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>();
|
||||
private OsmandApplication ctx;
|
||||
private List<LocationPoint> visibleLocationPoints = new CopyOnWriteArrayList<LocationPoint>();
|
||||
private long locationPointsModified;
|
||||
|
||||
public TargetPointsHelper(OsmandApplication ctx){
|
||||
this.ctx = ctx;
|
||||
|
@ -69,47 +67,7 @@ public class TargetPointsHelper {
|
|||
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() {
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
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.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.plus.sherpafy.WaypointDialogHelper;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.router.RouteCalculationProgress;
|
||||
import net.osmand.router.RouteSegmentResult;
|
||||
|
@ -537,6 +535,11 @@ public class RoutingHelper {
|
|||
}
|
||||
|
||||
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();
|
||||
route = res;
|
||||
if (isFollowingMode) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -17,7 +16,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.*;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.*;
|
||||
import net.osmand.plus.activities.FavouritesActivity;
|
||||
|
@ -35,7 +33,7 @@ public class WaypointDialogHelper {
|
|||
private MapActivity mapActivity;
|
||||
private OsmandApplication app;
|
||||
private FrameLayout mainLayout;
|
||||
private TargetPointsHelper targetPointsHelper;
|
||||
private OsmAndLocationProvider locationProvider;
|
||||
|
||||
public static boolean OVERLAP_LAYOUT = true;
|
||||
private long uiModified;
|
||||
|
@ -43,14 +41,14 @@ public class WaypointDialogHelper {
|
|||
|
||||
public WaypointDialogHelper(MapActivity mapActivity) {
|
||||
this.app = mapActivity.getMyApplication();
|
||||
targetPointsHelper = this.app.getTargetPointsHelper();
|
||||
locationProvider = this.app.getLocationProvider();
|
||||
this.mapActivity = mapActivity;
|
||||
this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0);
|
||||
}
|
||||
|
||||
public void updateDialog() {
|
||||
List<LocationPoint> vlp = targetPointsHelper.getVisibleLocationPoints();
|
||||
long locationPointsModified = targetPointsHelper.getLocationPointsModified();
|
||||
List<LocationPoint> vlp = locationProvider.getVisibleLocationPoints();
|
||||
long locationPointsModified = locationProvider.getLocationPointsModified();
|
||||
if (locationPointsModified != uiModified) {
|
||||
uiModified = locationPointsModified;
|
||||
if (vlp.isEmpty()) {
|
||||
|
@ -80,7 +78,7 @@ public class WaypointDialogHelper {
|
|||
btnN.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
targetPointsHelper.removeVisibleLocationPoint(point);
|
||||
locationProvider.removeVisibleLocationPoint(point);
|
||||
updateDialog();
|
||||
}
|
||||
});
|
||||
|
@ -189,7 +187,7 @@ public class WaypointDialogHelper {
|
|||
}
|
||||
|
||||
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,
|
||||
visibleLocationPoints) {
|
||||
@Override
|
||||
|
@ -220,9 +218,9 @@ public class WaypointDialogHelper {
|
|||
remove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
LocationPoint point = targetPointsHelper.getVisibleLocationPoints().get(position);
|
||||
LocationPoint point = locationProvider.getVisibleLocationPoints().get(position);
|
||||
remove(point);
|
||||
targetPointsHelper.removeVisibleLocationPoint(point);
|
||||
locationProvider.removeVisibleLocationPoint(point);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
@ -249,7 +247,7 @@ public class WaypointDialogHelper {
|
|||
builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
targetPointsHelper.removeAllVisiblePoints();
|
||||
locationProvider.clearAllVisiblePoints();
|
||||
updateDialog();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -202,7 +202,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
settings.GPX_ROUTE_CALC.set(selected);
|
||||
rp.setCalculateOsmAndRoute(selected);
|
||||
updateParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
|
||||
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
|
||||
|
@ -210,11 +210,16 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
if (gpxParam.id == R.string.fast_route_mode) {
|
||||
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) {
|
||||
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();
|
||||
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
|
||||
if(!osmandRouter) {
|
||||
|
@ -255,6 +260,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
list.add(rp);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
private String getString(int id) {
|
||||
|
|
Loading…
Reference in a new issue