Fix pause navigation and implement search poi on the path

This commit is contained in:
Victor Shcherb 2014-08-06 01:28:55 +02:00
parent 441b547a21
commit 431fd20f76
8 changed files with 145 additions and 75 deletions

View file

@ -1410,6 +1410,7 @@ public class BinaryMapIndexReader {
} }
request.radius = radius; request.radius = radius;
request.left = sleft; request.left = sleft;
request.zoom = -1;
request.right = sright; request.right = sright;
request.top = stop; request.top = stop;
request.bottom = sbottom; request.bottom = sbottom;

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="app_name">OsmAnd~</string> <string name="app_name">OsmAnd~</string>
<string name="app_version">1.8 alpha</string> <string name="app_version">1.9 alpha</string>
<!-- Not translatable --> <!-- Not translatable -->
<string name="ga_api_key">UA-28342846-2</string> <string name="ga_api_key">UA-28342846-2</string>
<string name="ga_dispatchPeriod">10</string> <string name="ga_dispatchPeriod">10</string>

View file

@ -820,6 +820,7 @@ public class MapActivityActions implements DialogProvider {
} else { } else {
routingHelper.setRoutePlanningMode(true); routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false); routingHelper.setFollowingMode(false);
routingHelper.setPauseNaviation(true);
} }
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap(); mapActivity.refreshMap();

View file

@ -29,7 +29,6 @@ public class AsyncLoadingThread extends Thread {
private static final Log log = PlatformUtil.getLog(AsyncLoadingThread.class); private static final Log log = PlatformUtil.getLog(AsyncLoadingThread.class);
private Handler asyncLoadingPoi;
private Handler asyncLoadingTransport; private Handler asyncLoadingTransport;
Stack<Object> requests = new Stack<Object>(); Stack<Object> requests = new Stack<Object>();
@ -43,11 +42,7 @@ public class AsyncLoadingThread extends Thread {
this.resourceManger = resourceManger; this.resourceManger = resourceManger;
} }
private void startPoiLoadingThread() {
HandlerThread h = new HandlerThread("Loading poi");
h.start();
asyncLoadingPoi = new Handler(h.getLooper());
}
private void startTransportLoadingThread() { private void startTransportLoadingThread() {
HandlerThread h = new HandlerThread("Loading transport"); HandlerThread h = new HandlerThread("Loading transport");
@ -61,6 +56,8 @@ public class AsyncLoadingThread extends Thread {
progress = BusyIndicator.STATUS_GREEN; progress = BusyIndicator.STATUS_GREEN;
} else if (resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated()) { } else if (resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated()) {
progress = BusyIndicator.STATUS_ORANGE; progress = BusyIndicator.STATUS_ORANGE;
} else if (resourceManger.isSearchAmenitiesInProgress()) {
progress = BusyIndicator.STATUS_BLACK;
} else if (!requests.isEmpty()) { } else if (!requests.isEmpty()) {
progress = BusyIndicator.STATUS_BLACK; progress = BusyIndicator.STATUS_BLACK;
} else if (transportLoadRequest != null && transportLoadRequest.isRunning()) { } else if (transportLoadRequest != null && transportLoadRequest.isRunning()) {

View file

@ -270,6 +270,7 @@ public class ResourceManager {
protected StringBuilder builder = new StringBuilder(40); protected StringBuilder builder = new StringBuilder(40);
protected char[] tileId = new char[120]; protected char[] tileId = new char[120];
private GeoidAltitudeCorrection geoidAltitudeCorrection; private GeoidAltitudeCorrection geoidAltitudeCorrection;
private boolean searchAmenitiesInProgress;
public synchronized String calculateTileId(ITileSource map, int x, int y, int zoom) { public synchronized String calculateTileId(ITileSource map, int x, int y, int zoom) {
builder.setLength(0); builder.setLength(0);
@ -718,13 +719,16 @@ public class ResourceManager {
public List<Amenity> searchAmenities(PoiFilter filter, public List<Amenity> searchAmenities(PoiFilter filter,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) { double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
final List<Amenity> amenities = new ArrayList<Amenity>(); final List<Amenity> amenities = new ArrayList<Amenity>();
if(filter instanceof NameFinderPoiFilter || filter instanceof SearchByNameFilter){ searchAmenitiesInProgress = true;
List<Amenity> tempResults = filter instanceof NameFinderPoiFilter ? try {
((NameFinderPoiFilter) filter).getSearchedAmenities() :((SearchByNameFilter) filter).getSearchedAmenities() ; if (filter instanceof NameFinderPoiFilter || filter instanceof SearchByNameFilter) {
for(Amenity a : tempResults){ List<Amenity> tempResults = filter instanceof NameFinderPoiFilter ? ((NameFinderPoiFilter) filter)
.getSearchedAmenities() : ((SearchByNameFilter) filter).getSearchedAmenities();
for (Amenity a : tempResults) {
LatLon l = a.getLocation(); LatLon l = a.getLocation();
if(l != null && l.getLatitude() <= topLatitude && l.getLatitude() >= bottomLatitude && l.getLongitude() >= leftLongitude && l.getLongitude() <= rightLongitude){ if (l != null && l.getLatitude() <= topLatitude && l.getLatitude() >= bottomLatitude
if(matcher.publish(a) ){ && l.getLongitude() >= leftLongitude && l.getLongitude() <= rightLongitude) {
if (matcher.publish(a)) {
amenities.add(a); amenities.add(a);
} }
} }
@ -754,6 +758,9 @@ public class ResourceManager {
} }
} }
} }
} finally {
searchAmenitiesInProgress = false;
}
return amenities; return amenities;
} }
@ -813,14 +820,17 @@ public class ResourceManager {
return map; return map;
} }
public void searchAmenitiesOnThePath(List<Location> locations, double radius, PoiFilter filter, ResultMatcher<Amenity> matcher) { public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, PoiFilter filter, ResultMatcher<Amenity> matcher) {
searchAmenitiesInProgress = true;
final List<Amenity> amenities = new ArrayList<Amenity>();
try {
if (locations != null && locations.size() > 0) { if (locations != null && locations.size() > 0) {
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>(); List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
double topLatitude = locations.get(0).getLatitude(); double topLatitude = locations.get(0).getLatitude();
double bottomLatitude = locations.get(0).getLatitude(); double bottomLatitude = locations.get(0).getLatitude();
double leftLongitude = locations.get(0).getLongitude(); double leftLongitude = locations.get(0).getLongitude();
double rightLongitude = locations.get(0).getLongitude(); double rightLongitude = locations.get(0).getLongitude();
for(Location l : locations) { for (Location l : locations) {
topLatitude = Math.max(topLatitude, l.getLatitude()); topLatitude = Math.max(topLatitude, l.getLatitude());
bottomLatitude = Math.min(bottomLatitude, l.getLatitude()); bottomLatitude = Math.min(bottomLatitude, l.getLatitude());
leftLongitude = Math.min(leftLongitude, l.getLongitude()); leftLongitude = Math.min(leftLongitude, l.getLongitude());
@ -832,12 +842,19 @@ public class ResourceManager {
} }
} }
if (!repos.isEmpty()) { if (!repos.isEmpty()) {
for(AmenityIndexRepository r : repos) { for (AmenityIndexRepository r : repos) {
r.searchAmenitiesOnThePath(locations, radius, filter, matcher); List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
if (res != null) {
amenities.addAll(res);
} }
} }
} }
} }
}finally {
searchAmenitiesInProgress = false;
}
return amenities;
}
////////////////////////////////////////////// Working with address /////////////////////////////////////////// ////////////////////////////////////////////// Working with address ///////////////////////////////////////////
@ -892,6 +909,10 @@ public class ResourceManager {
renderer.interruptLoadingMap(); renderer.interruptLoadingMap();
} }
public boolean isSearchAmenitiesInProgress() {
return searchAmenitiesInProgress;
}
public MapRenderRepositories getRenderer() { public MapRenderRepositories getRenderer() {
return renderer; return renderer;
} }

View file

@ -50,8 +50,8 @@ public class RoutingHelper {
private OsmandApplication app; private OsmandApplication app;
private boolean isFollowingMode = false; private boolean isFollowingMode = false;
private boolean isRoutePlanningMode = false; private boolean isRoutePlanningMode = false;
private boolean isPauseNavigation = false;
private GPXRouteParamsBuilder currentGPXRoute = null; private GPXRouteParamsBuilder currentGPXRoute = null;
@ -79,6 +79,7 @@ public class RoutingHelper {
private RouteCalculationProgressCallback progressRoute; private RouteCalculationProgressCallback progressRoute;
private SearchOnTheRouteHelper searchOnTheRouteHelper; private SearchOnTheRouteHelper searchOnTheRouteHelper;
// private ProgressBar progress; // private ProgressBar progress;
// private Handler progressHandler; // private Handler progressHandler;
@ -101,8 +102,17 @@ public class RoutingHelper {
return isFollowingMode; return isFollowingMode;
} }
public void setPauseNaviation(boolean b) {
this.isPauseNavigation = b;
}
public boolean isPauseNavigation() {
return isPauseNavigation;
}
public void setFollowingMode(boolean follow) { public void setFollowingMode(boolean follow) {
isFollowingMode = follow; isFollowingMode = follow;
isPauseNavigation = false;
if (!follow) { if (!follow) {
if (app.getNavigationService() != null) { if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION); app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION);
@ -932,4 +942,5 @@ public class RoutingHelper {
} }
} }
} }

View file

@ -21,6 +21,10 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
import net.osmand.plus.views.MapTextLayer.MapTextProvider; import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -36,7 +40,7 @@ import android.net.Uri;
import android.widget.Toast; import android.widget.Toast;
public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
MapTextProvider<Amenity> { MapTextProvider<Amenity>, IRouteInformationListener {
private static final int startZoom = 10; private static final int startZoom = 10;
public static final org.apache.commons.logging.Log log = PlatformUtil.getLog(POIMapLayer.class); public static final org.apache.commons.logging.Log log = PlatformUtil.getLog(POIMapLayer.class);
@ -48,15 +52,20 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private final static int MAXIMUM_SHOW_AMENITIES = 5; private final static int MAXIMUM_SHOW_AMENITIES = 5;
private ResourceManager resourceManager; private ResourceManager resourceManager;
private RoutingHelper routingHelper;
private PoiFilter filter; private PoiFilter filter;
private MapTextLayer mapTextLayer; private MapTextLayer mapTextLayer;
/// cache for displayed POI /// cache for displayed POI
// Work with cache (for map copied from AmenityIndexRepositoryOdb) // Work with cache (for map copied from AmenityIndexRepositoryOdb)
private MapLayerData<List<Amenity>> data; private MapLayerData<List<Amenity>> data;
private boolean path = false;
private double radius = 100;
public POIMapLayer(MapActivity activity) { public POIMapLayer(MapActivity activity) {
routingHelper = activity.getRoutingHelper();
routingHelper.addListener(this);
data = new OsmandMapLayer.MapLayerData<List<Amenity>>() { data = new OsmandMapLayer.MapLayerData<List<Amenity>>() {
{ {
ZOOM_THRESHOLD = 0; ZOOM_THRESHOLD = 0;
@ -70,6 +79,10 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override @Override
protected List<Amenity> calculateResult(RotatedTileBox tileBox) { protected List<Amenity> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds(); QuadRect latLonBounds = tileBox.getLatLonBounds();
if(path) {
RouteCalculationResult result = routingHelper.getRoute();
return resourceManager.searchAmenitiesOnThePath(result.getImmutableAllLocations(), radius, filter, null);
} else {
return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() { latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() {
@ -84,6 +97,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
} }
}); });
} }
}
}; };
} }
@ -92,10 +106,22 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
} }
public void setFilter(PoiFilter filter) { public void setFilter(PoiFilter filter) {
// TODO parameter
this.filter = filter; this.filter = filter;
// this.radius = 100;
// this.path = true;
this.path = false;
data.clearCache(); data.clearCache();
} }
public void setFilter(PoiFilter filter, double radius) {
this.filter = filter;
this.radius = radius;
this.path = true;
data.clearCache();
}
public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) { public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) {
List<Amenity> objects = data.getResults(); List<Amenity> objects = data.getResults();
if (objects != null) { if (objects != null) {
@ -224,6 +250,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override @Override
public void destroyLayer() { public void destroyLayer() {
routingHelper.removeListener(this);
} }
@Override @Override
@ -333,4 +360,16 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return o.getName(view.getSettings().usingEnglishNames()); return o.getName(view.getSettings().usingEnglishNames());
} }
@Override
public void newRouteIsCalculated(boolean newRoute) {
if(path) {
data.clearCache();
}
}
@Override
public void routeWasCancelled() {
}
} }

View file

@ -111,7 +111,7 @@ public class MapNavigateControl extends MapControls {
startNavigation(); startNavigation();
} }
}); });
if(!mapActivity.getRoutingHelper().isFollowingMode()) { if(!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isPauseNavigation()) {
startCounter(); startCounter();
} }
} }