diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 7bf257a9e6..f14de55997 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -46,6 +46,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener { private WaypointHelper waypointHelper; private final static String POI_RADIUS = "poi_radius"; + private final static String SEARCH_RADIUS = "favorite_radius"; public final static boolean OVERLAP_LAYOUT = true; // only true is supported private View closePointDialog; @@ -386,6 +387,41 @@ public class WaypointDialogHelper implements OsmAndLocationListener { v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null); } if (getItem(position) instanceof String && getItem(position).equals(POI_RADIUS)){ + v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null); + v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE); + final TextView radius = (TextView) v.findViewById(R.id.radius); + radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app)); + radius.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int length = WaypointHelper.SEARCH_RADIUS_VALUES.length; + String[] names = new String[length]; + int selected = 0; + for (int i = 0; i < length; i++) { + names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app); + if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getPoiSearchDeviationRadius()){ + selected = i; + } + } + new AlertDialog.Builder(getActivity()) + .setSingleChoiceItems(names, selected, new OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + int value = WaypointHelper.SEARCH_RADIUS_VALUES[i]; + if (waypointHelper.getPoiSearchDeviationRadius() != value){ + running[0] = position; + waypointHelper.setPoiSearchDeviationRadius(value); + radius.setText(OsmAndFormatter.getFormattedDistance(value, app)); + recalculatePoints(running, thisAdapter, WaypointHelper.POI); + dialogInterface.dismiss(); + } + } + }).setTitle(app.getString(R.string.search_radius)+ " " + app.getString(R.string.poi)) + .setNegativeButton(R.string.default_buttons_cancel, null) + .show(); + } + }); + } else if (getItem(position) instanceof String && getItem(position).equals(SEARCH_RADIUS)){ v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null); v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE); final TextView radius = (TextView) v.findViewById(R.id.radius); @@ -411,11 +447,11 @@ public class WaypointDialogHelper implements OsmAndLocationListener { running[0] = position; waypointHelper.setSearchDeviationRadius(value); radius.setText(OsmAndFormatter.getFormattedDistance(value, app)); - recalculatePoints(running, thisAdapter, WaypointHelper.POI); + recalculatePoints(running, thisAdapter, -1); dialogInterface.dismiss(); } } - }).setTitle(app.getString(R.string.search_radius)+ " " + app.getString(R.string.poi)) + }).setTitle(app.getString(R.string.search_radius)) .setNegativeButton(R.string.default_buttons_cancel, null) .show(); } @@ -522,6 +558,8 @@ public class WaypointDialogHelper implements OsmAndLocationListener { points.add(new Integer(i)); if (i == WaypointHelper.POI && waypointHelper.isTypeEnabled(WaypointHelper.POI)){ points.add(POI_RADIUS); + } else if (i == WaypointHelper.FAVORITES && waypointHelper.isTypeEnabled(WaypointHelper.FAVORITES)){ + points.add(SEARCH_RADIUS); } if (tp != null && tp.size() > 0) { points.addAll(tp); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index f5b0193a41..ef6bdd8d43 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -44,6 +44,7 @@ public class WaypointHelper { private static final int ANNOUNCED_DONE = 2; private int searchDeviationRadius = 500; + private int poiSearchDeviationRadius = 150; private static final int LONG_ANNOUNCE_RADIUS = 700; private static final int SHORT_ANNOUNCE_RADIUS = 150; private static final int ALARMS_ANNOUNCE_RADIUS = 150; @@ -509,7 +510,7 @@ public class WaypointHelper { PoiFilter pf = getPoiFilter(); if (pf != null) { final List locs = route.getImmutableAllLocations(); - List amenities = app.getResourceManager().searchAmenitiesOnThePath(locs, getSearchRadius(POI), + List amenities = app.getResourceManager().searchAmenitiesOnThePath(locs, getPoiSearchDeviationRadius(), pf, new ResultMatcher() { @Override @@ -536,12 +537,6 @@ public class WaypointHelper { } - protected int getSearchRadius(int type) { - // app.getAppCustomization().getWaypointSearchRadius(searchDeviationRadius, type); - return searchDeviationRadius; - } - - private void calculateAlarms(RouteCalculationResult route, List array) { for(AlarmInfo i : route.getAlarmInfo()) { @@ -580,7 +575,7 @@ public class WaypointHelper { int[] ind = new int[1]; for(LocationPoint p : points) { float dist = dist(p, immutableAllLocations, ind); - if(dist <= getSearchRadius(type)) { + if(dist <= getSearchDeviationRadius() && type != POI) { LocationPointWrapper lpw = new LocationPointWrapper(rt, type, p, dist, ind[0]); lpw.setAnnounce(announce); locationPoints.add(lpw); @@ -716,6 +711,14 @@ public class WaypointHelper { public void setSearchDeviationRadius(int radius){ this.searchDeviationRadius = radius; } + + public int getPoiSearchDeviationRadius() { + return poiSearchDeviationRadius; + } + + public void setPoiSearchDeviationRadius(int radius) { + this.poiSearchDeviationRadius = radius; + } private class AmenityLocationPoint implements LocationPoint {