Update waypoint helper

This commit is contained in:
Victor Shcherb 2014-08-17 15:42:09 +02:00
parent 099959b7fe
commit 4f51bb9237
11 changed files with 396 additions and 280 deletions

View file

@ -1923,7 +1923,7 @@ public class BinaryMapIndexReader {
for (Amenity a : results) {
final float dds = dist(a.getLocation(), locations);
if (dds <= radius) {
println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float)a.getDeviateDistance() + ") " + a.getName() + " " + a.getLocation());
println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float)a.getRoutePoint().deviateDistance + ") " + a.getName() + " " + a.getLocation());
k++;
} else {
println(a.getType() + " " + a.getSubType() + " Dist " + dds + " " + a.getName() + " " + a.getLocation());

View file

@ -20,6 +20,7 @@ import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.OsmandOdb.OsmAndPoiNameIndex.OsmAndPoiNameIndexData;
import net.osmand.data.Amenity;
import net.osmand.data.Amenity.AmenityRoutePoint;
import net.osmand.data.AmenityType;
import net.osmand.data.LatLon;
import net.osmand.util.Algorithms;
@ -590,16 +591,23 @@ public class BinaryMapPoiReaderAdapter {
}
}
private float dist(LatLon l, List<Location> locations) {
float dist = Float.POSITIVE_INFINITY;
private AmenityRoutePoint dist(LatLon l, List<Location> locations, double radius) {
float dist = (float) (radius + 0.1);
AmenityRoutePoint arp = null;
// Special iterations because points stored by pairs!
for (int i = 1; i < locations.size(); i += 2) {
dist = Math.min(dist, (float) MapUtils.getOrthogonalDistance(
l.getLatitude(), l.getLongitude(),
locations.get(i - 1).getLatitude(), locations.get(i - 1).getLongitude(),
locations.get(i).getLatitude(), locations.get(i).getLongitude()));
float d = (float) MapUtils.getOrthogonalDistance(l.getLatitude(), l.getLongitude(), locations.get(i - 1)
.getLatitude(), locations.get(i - 1).getLongitude(), locations.get(i).getLatitude(),
locations.get(i).getLongitude());
if (d < dist) {
arp = new Amenity.AmenityRoutePoint();
dist = d;
arp.deviateDistance = dist;
arp.pointA = locations.get(i - 1);
arp.pointB = locations.get(i);
}
}
return dist;
return arp;
}
private Amenity readPoiPoint(int left31, int right31, int top31, int bottom31,
int px, int py, int zoom, SearchRequest<Amenity> req, PoiRegion region, boolean checkBounds) throws IOException {
@ -628,11 +636,11 @@ public class BinaryMapPoiReaderAdapter {
if (locs == null) {
return null;
}
float d = dist(am.getLocation(), locs);
if (d > req.radius) {
AmenityRoutePoint arp = dist(am.getLocation(), locs, req.radius);
if (arp == null){
return null;
} else {
am.setDeviateDistance(d);
am.setRoutePoint(arp);
}
}
return am;

View file

@ -4,8 +4,10 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import net.osmand.Location;
public class Amenity extends MapObject {
public class Amenity extends MapObject {
public static final String WEBSITE = "website";
public static final String PHONE = "phone";
@ -18,11 +20,17 @@ public class Amenity extends MapObject {
// duplicate for fast access
private String openingHours;
private Map<String, String> additionalInfo;
private double deviateDistance; // for search on path
private AmenityRoutePoint routePoint; // for search on path
public Amenity(){
}
public static class AmenityRoutePoint {
public double deviateDistance;
public Location pointA;
public Location pointB;
}
public AmenityType getType(){
return type;
}
@ -63,12 +71,12 @@ public class Amenity extends MapObject {
openingHours = additionalInfo.get(OPENING_HOURS);
}
public double getDeviateDistance() {
return deviateDistance;
public void setRoutePoint(AmenityRoutePoint routePoint) {
this.routePoint = routePoint;
}
public void setDeviateDistance(double deviateDistance) {
this.deviateDistance = deviateDistance;
public AmenityRoutePoint getRoutePoint() {
return routePoint;
}
public void setAdditionalInfo(String tag, String value) {

View file

@ -1,4 +1,5 @@
package net.osmand.data;
import net.osmand.plus.voice.CommandBuilder;
/**
*/
@ -14,4 +15,8 @@ public interface LocationPoint {
public boolean isVisible();
// public String getSpeakableName();
//public void prepareCommandPlayer(CommandBuilder cmd, String names);
}

View file

@ -820,6 +820,7 @@ public class OsmandSettings {
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> ANNOUNCE_NEARBY_POI = new BooleanPreference("announce_nearby_poi", 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();

View file

@ -21,13 +21,13 @@ import net.osmand.plus.*;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.util.MapUtils;
import java.util.List;
/**
* Created by Denis on 25.07.2014.
*/
public class WaypointDialogHelper {
private MapActivity mapActivity;
@ -35,13 +35,9 @@ public class WaypointDialogHelper {
private FrameLayout mainLayout;
private WaypointHelper waypointHelper;
public static boolean OVERLAP_LAYOUT = true;
public final static boolean OVERLAP_LAYOUT = true; // only true is supported
private View closePointDialog;
private static final String GPX_WAYPOINTS = "GPX waypoints";
private static final String FAVORITES = "Favorites";
private static final String POI = "POI";
private static final String TARGETS = "Targets";
public WaypointDialogHelper(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication();
@ -51,18 +47,17 @@ public class WaypointDialogHelper {
}
public void updateDialog() {
List<LocationPoint> vlp = waypointHelper.getAllVisibleLocationPoints();
List<LocationPointWrapper> vlp = waypointHelper.getWaypoints(WaypointHelper.FAVORITES);
if (vlp.isEmpty()) {
removeDialog();
} else {
final LocationPoint point = vlp.get(0);
final LocationPointWrapper point = vlp.get(0);
boolean created = false;
if (closePointDialog == null) {
created = true;
final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
closePointDialog = vi.inflate(R.layout.waypoint_reached, null);
}
updatePointInfoView(closePointDialog, point);
View all = closePointDialog.findViewById(R.id.all_points);
all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE);
@ -72,7 +67,7 @@ public class WaypointDialogHelper {
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAllDialog(waypointHelper.getAllVisibleLocationPoints());
// showAllDialog(waypointHelper.getAllVisibleLocationPoints());
}
});
@ -91,12 +86,14 @@ public class WaypointDialogHelper {
}
}
private void updatePointInfoView(View localView, final LocationPoint point) {
private void updatePointInfoView(View localView, final LocationPointWrapper ps) {
LocationPoint point = ps.getPoint();
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemClick(point);
// TODO
//itemClick(point);
}
});
@ -118,14 +115,6 @@ public class WaypointDialogHelper {
}
}
private void itemClick(LocationPoint point) {
final Intent favorites = new Intent(mapActivity, app.getAppCustomization().getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
favorites.putExtra(FavouritesActivity.TAB_PARAM,
point instanceof GPXUtilities.WptPt ? FavouritesActivity.GPX_TAB : FavouritesActivity.FAVORITES_TAB);
mapActivity.startActivity(favorites);
}
public void removeDialog() {
if (closePointDialog != null) {
mainLayout.removeView(closePointDialog);
@ -140,17 +129,6 @@ public class WaypointDialogHelper {
return params;
}
private boolean checkIfDialogExists() {
if (mainLayout == null) {
return true;
}
if (mainLayout.findViewById(R.id.package_delivered_layout) != null) {
return false;
}
return true;
}
private void shiftButtons(int height) {
MapControlsLayer mapControls = mapActivity.getMapLayers().getMapControlsLayer();
if (mapControls != null) {
@ -185,94 +163,9 @@ public class WaypointDialogHelper {
}.execute(reachedView);
}
public void showWaypointsSettingsDialog(){
final List<Object> points = getItemsList(waypointHelper.getAllVisibleLocationPoints());
final ArrayAdapter<Object> listAdapter = new ArrayAdapter<Object>(mapActivity, R.layout.waypoint_reached, R.id.title,
points) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
if (points.get(position) instanceof LocationPoint){
v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, mapActivity.getResources()
.getDisplayMetrics());
final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl);
ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4);
v.findViewById(R.id.waypoint_icon).setLayoutParams(ll);
} else if (points.get(position) instanceof String){
String header = (String)points.get(position);
v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_header, null);
TextView headerText = (TextView) v.findViewById(R.id.header_text);
headerText.setText(header);
ImageButton allpoints = (ImageButton) v.findViewById(R.id.all_points);
if (header.equals(FAVORITES)){
allpoints.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAllDialog(waypointHelper.getVisibleFavorites());
}
});
} else if (header.equals(TARGETS)){
allpoints.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
} else if (header.equals(GPX_WAYPOINTS)){
allpoints.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAllDialog(waypointHelper.getVisibleGpxPoints());
}
});
} else if (header.equals(POI)){
allpoints.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
}
}
updatePointInfoView(v, (LocationPoint)getItem(position));
TextView text = (TextView) v.findViewById(R.id.waypoint_text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap((LocationPoint)points.get(position));
}
});
View remove = v.findViewById(R.id.info_close);
((ImageButton) remove).setImageDrawable(mapActivity.getResources().getDrawable(
app.getSettings().isLightContent()? R.drawable.ic_action_gremove_light:
R.drawable.ic_action_gremove_dark));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocationPoint point = waypointHelper.getAllVisibleLocationPoints().get(position);
remove(point);
waypointHelper.removeVisibleLocationPoint(point);
notifyDataSetChanged();
}
});
return v;
}
};
}
private List<Object> getItemsList(List<LocationPoint> visibleLocationPoints) {
return null;
}
public void showAllDialog(final List<LocationPoint> visibleLocationPoints){
final ArrayAdapter<LocationPoint> listAdapter = new ArrayAdapter<LocationPoint>(mapActivity, R.layout.waypoint_reached, R.id.title,
public void showAllDialog(final List<LocationPointWrapper> visibleLocationPoints){
final ArrayAdapter<LocationPointWrapper> listAdapter = new ArrayAdapter<LocationPointWrapper>(mapActivity, R.layout.waypoint_reached, R.id.title,
visibleLocationPoints) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
@ -302,7 +195,7 @@ public class WaypointDialogHelper {
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocationPoint point = waypointHelper.getAllVisibleLocationPoints().get(position);
LocationPointWrapper point = visibleLocationPoints.get(position);
remove(point);
waypointHelper.removeVisibleLocationPoint(point);
notifyDataSetChanged();
@ -321,10 +214,6 @@ public class WaypointDialogHelper {
showOnMap(visibleLocationPoints.get(i));
}
});
// Dialog dlg = new Dialog(mapActivity);
// dlg.setContentView(listView);
// dlg.show();
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setView(listView);
builder.setPositiveButton(R.string.default_buttons_ok, null);
@ -338,11 +227,12 @@ public class WaypointDialogHelper {
builder.show();
}
private void showOnMap(LocationPoint locationPoint) {
private void showOnMap(LocationPointWrapper locationPoint) {
LocationPoint point = locationPoint.getPoint();
// AnimateDraggingMapThread thread = mapActivity.getMapView().getAnimatedDraggingThread();
int fZoom = mapActivity.getMapView().getZoom() < 15 ? 15 : mapActivity.getMapView().getZoom();
// thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
mapActivity.getMapView().setIntZoom(fZoom);
mapActivity.getMapView().setLatLon(locationPoint.getLatitude(), locationPoint.getLongitude());
mapActivity.getMapView().setLatLon(point.getLatitude(), point.getLongitude());
}
}

View file

@ -1,91 +1,75 @@
package net.osmand.plus.helpers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.ResultMatcher;
import net.osmand.data.Amenity;
import net.osmand.data.Amenity.AmenityRoutePoint;
import net.osmand.data.LocationPoint;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.routing.AlarmInfo;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.util.MapUtils;
/**
*/
public class WaypointHelper {
OsmandApplication app;
// every time we modify this collection, we change the reference (copy on write list)
private List<LocationPoint> visibleLocationPoints = new ArrayList<LocationPoint>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
private Location lastKnownLocation;
private static final int NOT_ANNOUNCED = 0;
private static final int ANNOUNCED_ONCE = 1;
private int searchDeviationRadius = 500;
private static final int LONG_ANNOUNCE_RADIUS = 500;
private static final int SHORT_ANNOUNCE_RADIUS = 150;
public static final int SEARCH_WAYPOINTS_RADIUS = 400;
OsmandApplication app;
// every time we modify this collection, we change the reference (copy on write list)
public static final int TARGETS = 0;
public static final int ALARMS = 1;
public static final int WAYPOINTS = 2;
public static final int POI = 3;
public static final int FAVORITES = 4;
private List<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
private Location lastKnownLocation;
private RouteCalculationResult route;
public WaypointHelper(OsmandApplication application) {
app = application;
}
public List<LocationPoint> getAllVisibleLocationPoints() {
return visibleLocationPoints;
}
public List<LocationPoint> getVisibleFavorites() {
List<LocationPoint> points = new ArrayList<LocationPoint>();
for (LocationPoint point : visibleLocationPoints){
if (point instanceof FavouritePoint){
points.add(point);
}
public List<LocationPointWrapper> getWaypoints(int type) {
if(type >= locationPoints.size()) {
return Collections.emptyList();
}
return points;
}
public List<LocationPoint> getVisibleGpxPoints() {
List<LocationPoint> points = new ArrayList<LocationPoint>();
for (LocationPoint point : visibleLocationPoints){
if (point instanceof GPXUtilities.WptPt){
points.add(point);
}
}
return points;
return locationPoints.get(type);
}
public void locationChanged(Location location) {
app.getAppCustomization();
lastKnownLocation = location;
sortVisibleWaypoints();
announceVisibleLocations();
}
private void sortVisibleWaypoints() {
// TODO mark as passed
if (lastKnownLocation != null) {
Object[] loc = visibleLocationPoints.toArray();
Arrays.sort(loc, getComparator(lastKnownLocation));
visibleLocationPoints.clear();
for (Object aLoc : loc) {
visibleLocationPoints.add((LocationPoint) aLoc);
}
}
}
public void removeVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints = removeFromList(visibleLocationPoints, lp);
this.locationPointsStates.remove(lp);
public void removeVisibleLocationPoint(LocationPointWrapper lp) {
// TODO FIXME
}
public void announceVisibleLocations() {
// TODO FIXME
if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
String nameToAnnounce = null;
List<LocationPoint> approachPoints = new ArrayList<LocationPoint>();
@ -115,46 +99,142 @@ public class WaypointHelper {
}
}
public void addVisibleLocationPoint(LocationPoint lp) {
this.locationPointsStates.put(lp, NOT_ANNOUNCED);
sortVisibleWaypoints();
}
public void clearAllVisiblePoints() {
this.locationPointsStates.clear();
this.visibleLocationPoints = new ArrayList<LocationPoint>();
this.locationPoints = new ArrayList<List<LocationPointWrapper>>();
}
public void setVisibleLocationPoints(List<LocationPoint> points) {
locationPointsStates.clear();
visibleLocationPoints.clear();
if (points == null) {
return;
}
for (LocationPoint p : points) {
locationPointsStates.put(p, NOT_ANNOUNCED);
visibleLocationPoints.add(p);
}
sortVisibleWaypoints();
}
public void setNewRoute(RouteCalculationResult res) {
// TODO compare reset all !!
ArrayList<LocationPoint> locationPoints = new ArrayList<LocationPoint>();
if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get()){
locationPoints.addAll(app.getFavorites().getFavouritePoints());
locationPoints.addAll(app.getAppCustomization().getWaypoints());
}
locationPoints.addAll(res.getLocationPoints());
setVisibleLocationPoints(locationPoints);
this.route = res;
recalculateAllPoints();
}
public List<LocationPoint> removeFromList(List<LocationPoint> items, Object item) {
List<LocationPoint> newArray = new ArrayList<LocationPoint>(items);
newArray.remove(item);
return newArray;
private float dist(LocationPoint l, List<Location> locations, int[] ind) {
float dist = Float.POSITIVE_INFINITY;
// Special iterations because points stored by pairs!
for (int i = 1; i < locations.size(); i ++) {
final double ld = MapUtils.getOrthogonalDistance(
l.getLatitude(), l.getLongitude(),
locations.get(i - 1).getLatitude(), locations.get(i - 1).getLongitude(),
locations.get(i).getLatitude(), locations.get(i).getLongitude());
if(ld < dist){
if(ind != null) {
ind[0] = i;
}
dist = (float) ld;
}
}
return dist;
}
private void recalculateAllPoints() {
ArrayList<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
if (route != null && !route.isEmpty()) {
if (showFavorites()) {
findLocationPoints(route, FAVORITES, getArray(locationPoints, FAVORITES), app.getFavorites()
.getFavouritePoints(), announceFavorites());
}
calculateAlarms(getArray(locationPoints, ALARMS));
if (showGPXWaypoints()) {
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), app.getAppCustomization()
.getWaypoints(), announceGPXWaypoints());
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), route.getLocationPoints(),
announceGPXWaypoints());
}
if(showPOI()) {
calculatePoi(locationPoints);
}
}
for (List<LocationPointWrapper> list : locationPoints) {
Collections.sort(list, new Comparator<LocationPointWrapper>() {
@Override
public int compare(LocationPointWrapper olhs, LocationPointWrapper orhs) {
int lhs = olhs.routeIndex;
int rhs = orhs.routeIndex;
return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
}
});
}
this.locationPoints = locationPoints;
}
protected void calculatePoi(ArrayList<List<LocationPointWrapper>> locationPoints) {
final List<Location> locs = route.getImmutableAllLocations();
List<Amenity> amenities = app.getResourceManager().searchAmenitiesOnThePath(locs, searchDeviationRadius, getPoiFilter(), new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity object) {
return true;
}
@Override
public boolean isCancelled() {
return false;
}
});
List<LocationPointWrapper> array = getArray(locationPoints, POI);
for (Amenity a : amenities) {
AmenityRoutePoint rp = a.getRoutePoint();
int i = locs.indexOf(rp.pointA);
if (i >= 0) {
LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a), (float) rp.deviateDistance, i);
lwp.setAnnounce(announcePOI());
array.add(lwp);
}
}
}
private void calculateAlarms(List<LocationPointWrapper> array) {
for(AlarmInfo i : route.getAlarmInfo()) {
if(i.getType() == AlarmInfoType.SPEED_CAMERA) {
if(app.getSettings().SHOW_CAMERAS.get()){
LocationPointWrapper lw = new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
lw.setAnnounce(app.getSettings().SPEAK_SPEED_CAMERA.get());
array.add(lw);
}
} else {
if(app.getSettings().SHOW_TRAFFIC_WARNINGS.get()){
LocationPointWrapper lw = new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
lw.setAnnounce(app.getSettings().SPEAK_TRAFFIC_WARNINGS.get());
array.add(lw);
}
}
}
}
private List<LocationPointWrapper> getArray(ArrayList<List<LocationPointWrapper>> array,
int ind) {
while(array.size() <= ind) {
array.add(new ArrayList<WaypointHelper.LocationPointWrapper>());
}
return array.get(ind);
}
private void findLocationPoints(RouteCalculationResult rt, int type, List<LocationPointWrapper> locationPoints,
List<? extends LocationPoint> points, boolean announce) {
List<Location> immutableAllLocations = rt.getImmutableAllLocations();
int[] ind = new int[1];
for(LocationPoint p : points) {
float dist = dist(p, immutableAllLocations, ind);
if(dist <= searchDeviationRadius) {
LocationPointWrapper lpw = new LocationPointWrapper(rt, type, p, dist, ind[0]);
lpw.setAnnounce(announce);
locationPoints.add(lpw);
}
}
}
private Comparator<Object> getComparator(final net.osmand.Location lastLocation) {
return new Comparator<Object>() {
@Override
@ -169,4 +249,126 @@ public class WaypointHelper {
};
}
///
public PoiFilter getPoiFilter() {
return app.getPoiFilters().getFilterById(app.getSettings().getPoiFilterForMap());
}
public boolean showPOI() {
return app.getSettings().ANNOUNCE_NEARBY_POI.get();
}
public boolean announcePOI() {
return app.getSettings().ANNOUNCE_NEARBY_POI.get();
}
public boolean showGPXWaypoints() {
return app.getSettings().GPX_SPEAK_WPT.get();
}
public boolean announceGPXWaypoints() {
return app.getSettings().GPX_SPEAK_WPT.get();
}
public boolean showFavorites() {
return app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get();
}
public boolean showAlarms() {
return app.getSettings().SPEAK_SPEED_CAMERA.get() ||
app.getSettings().SPEAK_TRAFFIC_WARNINGS.get();
}
public boolean announceFavorites() {
return app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get();
}
public class LocationPointWrapper {
LocationPoint point;
float deviationDistance;
int routeIndex;
boolean announce = true;
RouteCalculationResult route;
int type;
public LocationPointWrapper(RouteCalculationResult rt, int type, LocationPoint point, float deviationDistance, int routeIndex) {
this.route = rt;
this.type = type;
this.point = point;
this.deviationDistance = deviationDistance;
this.routeIndex = routeIndex;
}
public void setAnnounce(boolean announce) {
this.announce = announce;
}
public float getDeviationDistance() {
return deviationDistance;
}
public LocationPoint getPoint() {
return point;
}
@Override
public int hashCode() {
return ((point == null) ? 0 : point.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LocationPointWrapper other = (LocationPointWrapper) obj;
if (point == null) {
if (other.point != null)
return false;
} else if (!point.equals(other.point))
return false;
return true;
}
}
private class AmenityLocationPoint implements LocationPoint {
Amenity a;
public AmenityLocationPoint(Amenity a) {
this.a = a;
}
@Override
public double getLatitude() {
return a.getLocation().getLatitude();
}
@Override
public double getLongitude() {
return a.getLocation().getLongitude();
}
@Override
public String getName() {
return OsmAndFormatter.getPoiSimpleFormat(a, app, app.getSettings().usingEnglishNames());
}
@Override
public int getColor() {
return 0;
}
@Override
public boolean isVisible() {
return true;
}
}
}

View file

@ -1,9 +1,10 @@
package net.osmand.plus.routing;
import net.osmand.Location;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.LocationPoint;
public class AlarmInfo {
public class AlarmInfo implements LocationPoint {
public enum AlarmInfoType {
SPEED_CAMERA(1),
SPEED_LIMIT(2),
@ -25,12 +26,13 @@ public class AlarmInfo {
}
private AlarmInfoType type;
private float distance;
private float time;
protected final int locationIndex;
private int intValue;
private double latitude;
private double longitude;
public AlarmInfo(AlarmInfoType type, int locationIndex){
this.type = type;
@ -58,37 +60,59 @@ public class AlarmInfo {
return type;
}
@Override
public double getLatitude() {
return latitude;
}
@Override
public double getLongitude() {
return longitude;
}
public int getIntValue() {
return intValue;
}
public int getLocationIndex() {
return locationIndex;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
public static AlarmInfo createSpeedLimit(int speed){
public static AlarmInfo createSpeedLimit(int speed, Location loc){
AlarmInfo info = new AlarmInfo(AlarmInfoType.SPEED_LIMIT, 0);
info.setLatLon(loc.getLatitude(), loc.getLongitude());
info.setIntValue(speed);
return info;
}
public static AlarmInfo createAlarmInfo(RouteTypeRule ruleType, int locInd) {
public void setLatLon(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public static AlarmInfo createAlarmInfo(RouteTypeRule ruleType, int locInd, Location loc) {
AlarmInfo alarmInfo = null;
if("highway".equals(ruleType.getTag())) {
if("speed_camera".equals(ruleType.getValue())) {
return new AlarmInfo(AlarmInfoType.SPEED_CAMERA, locInd);
alarmInfo = new AlarmInfo(AlarmInfoType.SPEED_CAMERA, locInd);
} else if("stop".equals(ruleType.getValue())) {
return new AlarmInfo(AlarmInfoType.STOP, locInd);
alarmInfo = new AlarmInfo(AlarmInfoType.STOP, locInd);
}
} else if("barrier".equals(ruleType.getTag())) {
if("toll_booth".equals(ruleType.getValue())) {
return new AlarmInfo(AlarmInfoType.TOLL_BOOTH, locInd);
alarmInfo = new AlarmInfo(AlarmInfoType.TOLL_BOOTH, locInd);
} else if("border_control".equals(ruleType.getValue())) {
return new AlarmInfo(AlarmInfoType.BORDER_CONTROL, locInd);
alarmInfo = new AlarmInfo(AlarmInfoType.BORDER_CONTROL, locInd);
}
} else if("traffic_calming".equals(ruleType.getTag())) {
return new AlarmInfo(AlarmInfoType.TRAFFIC_CALMING, locInd);
alarmInfo = new AlarmInfo(AlarmInfoType.TRAFFIC_CALMING, locInd);
}
if(alarmInfo != null) {
alarmInfo.setLatLon(loc.getLatitude(), loc.getLongitude());
}
return null;
}
@ -113,4 +137,20 @@ public class AlarmInfo {
return 0;
}
@Override
public String getName() {
return type.name();
}
@Override
public int getColor() {
return 0;
}
@Override
public boolean isVisible() {
return false;
}
}

View file

@ -1,22 +1,15 @@
package net.osmand.plus.routing;
import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.osmand.Location;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.router.RouteSegmentResult;
@ -118,6 +111,10 @@ public class RouteCalculationResult {
return locationPoints;
}
public List<AlarmInfo> getAlarmInfo() {
return alarmInfo;
}
private static void calculateIntermediateIndexes(Context ctx, List<Location> locations,
List<LatLon> intermediates, List<RouteDirectionInfo> localDirections, int[] intermediatePoints) {
if(intermediates != null && localDirections != null) {
@ -177,7 +174,12 @@ public class RouteCalculationResult {
if (pointTypes != null) {
for (int r = 0; r < pointTypes.length; r++) {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, locInd);
int x31 = res.getObject().getPoint31XTile(intId);
int y31 = res.getObject().getPoint31YTile(intId);
Location loc = new Location("");
loc.setLatitude(MapUtils.get31LatitudeY(y31));
loc.setLongitude(MapUtils.get31LongitudeX(x31));
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, locInd, loc);
if(info != null) {
alarms.add(info);
}
@ -491,46 +493,6 @@ public class RouteCalculationResult {
}
}
/**
* PREPARATION
*
*/
private int[] calculateWaypointIndexes(List<Location> list, DataTileManager<? extends LocationPoint> waypointsTm, List<LocationPoint> waypoints) {
if(waypointsTm == null || waypointsTm.isEmpty() || list.size() == 0) {
return new int[0];
}
TIntArrayList ls = new TIntArrayList();
Location loc = list.get(0);
Location ploc = list.get(0);
Set<LocationPoint> added = new HashSet<LocationPoint>();
int prev31x = MapUtils.get31TileNumberX(loc.getLatitude());
int prev31y = MapUtils.get31TileNumberY(loc.getLongitude());
for(int j = 1; j < list.size(); j++) {
loc = list.get(j);
int t31x = MapUtils.get31TileNumberX(loc.getLatitude());
int t31y = MapUtils.get31TileNumberY(loc.getLongitude());
List<? extends LocationPoint> ws = waypointsTm.getObjects(Math.min(prev31x, t31x) - Math.abs(t31x - prev31x) / 4,
Math.min(prev31y, t31y) - Math.abs(t31y - prev31y) / 4,
Math.max(prev31x, t31x) + Math.abs(t31x - prev31x) / 4,
Math.max(prev31y, t31y) + Math.abs(t31y - prev31y) / 4);
for(LocationPoint w : ws) {
if (added.contains(w)) {
double ds = MapUtils.getOrthogonalDistance(w.getLatitude(), w.getLongitude(), ploc.getLatitude(), ploc.getLongitude(), loc.getLatitude(),
loc.getLongitude());
if (ds < 160) {
ls.add(j);
waypoints.add(w);
added.add(w);
}
}
}
prev31x = t31x;
prev31y = t31y;
ploc = loc;
}
return ls.toArray();
}
/**
* PREPARATION

View file

@ -636,7 +636,7 @@ public class RoutingHelper {
if (pointTypes != null) {
for (int r = 0; r < pointTypes.length; r++) {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0, loc);
if (info != null) {
if (info.getType() != AlarmInfoType.SPEED_CAMERA || showCameras) {
voiceRouter.announceAlarm(info);
@ -661,7 +661,7 @@ public class RoutingHelper {
} else {
speed = Math.round(mxspeed * 3.6f / 1.6f);
}
speedAlarm = AlarmInfo.createSpeedLimit(speed);
speedAlarm = AlarmInfo.createSpeedLimit(speed, loc);
}
}
return speedAlarm;