diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index b0e529f228..67c1983ae2 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1410,6 +1410,7 @@ public class BinaryMapIndexReader { } request.radius = radius; request.left = sleft; + request.zoom = -1; request.right = sright; request.top = stop; request.bottom = sbottom; diff --git a/OsmAnd/res/values/no_translate.xml b/OsmAnd/res/values/no_translate.xml index 25e804ab19..929963a4da 100644 --- a/OsmAnd/res/values/no_translate.xml +++ b/OsmAnd/res/values/no_translate.xml @@ -1,7 +1,7 @@ OsmAnd~ - 1.8 alpha + 1.9 alpha UA-28342846-2 10 diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 99acc6552b..30fd5c7b3e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -820,6 +820,7 @@ public class MapActivityActions implements DialogProvider { } else { routingHelper.setRoutePlanningMode(true); routingHelper.setFollowingMode(false); + routingHelper.setPauseNaviation(true); } mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); mapActivity.refreshMap(); diff --git a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java index 5a7192b0c3..a9a3320dda 100644 --- a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java @@ -29,7 +29,6 @@ public class AsyncLoadingThread extends Thread { private static final Log log = PlatformUtil.getLog(AsyncLoadingThread.class); - private Handler asyncLoadingPoi; private Handler asyncLoadingTransport; Stack requests = new Stack(); @@ -43,11 +42,7 @@ public class AsyncLoadingThread extends Thread { this.resourceManger = resourceManger; } - private void startPoiLoadingThread() { - HandlerThread h = new HandlerThread("Loading poi"); - h.start(); - asyncLoadingPoi = new Handler(h.getLooper()); - } + private void startTransportLoadingThread() { HandlerThread h = new HandlerThread("Loading transport"); @@ -61,6 +56,8 @@ public class AsyncLoadingThread extends Thread { progress = BusyIndicator.STATUS_GREEN; } else if (resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated()) { progress = BusyIndicator.STATUS_ORANGE; + } else if (resourceManger.isSearchAmenitiesInProgress()) { + progress = BusyIndicator.STATUS_BLACK; } else if (!requests.isEmpty()) { progress = BusyIndicator.STATUS_BLACK; } else if (transportLoadRequest != null && transportLoadRequest.isRunning()) { diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index e4d530384f..f751d70d9f 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -270,6 +270,7 @@ public class ResourceManager { protected StringBuilder builder = new StringBuilder(40); protected char[] tileId = new char[120]; private GeoidAltitudeCorrection geoidAltitudeCorrection; + private boolean searchAmenitiesInProgress; public synchronized String calculateTileId(ITileSource map, int x, int y, int zoom) { builder.setLength(0); @@ -718,41 +719,47 @@ public class ResourceManager { public List searchAmenities(PoiFilter filter, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher matcher) { final List amenities = new ArrayList(); - if(filter instanceof NameFinderPoiFilter || filter instanceof SearchByNameFilter){ - List tempResults = filter instanceof NameFinderPoiFilter ? - ((NameFinderPoiFilter) filter).getSearchedAmenities() :((SearchByNameFilter) filter).getSearchedAmenities() ; - for(Amenity a : tempResults){ - LatLon l = a.getLocation(); - if(l != null && l.getLatitude() <= topLatitude && l.getLatitude() >= bottomLatitude && l.getLongitude() >= leftLongitude && l.getLongitude() <= rightLongitude){ - if(matcher.publish(a) ){ - amenities.add(a); + searchAmenitiesInProgress = true; + try { + if (filter instanceof NameFinderPoiFilter || filter instanceof SearchByNameFilter) { + List tempResults = filter instanceof NameFinderPoiFilter ? ((NameFinderPoiFilter) filter) + .getSearchedAmenities() : ((SearchByNameFilter) filter).getSearchedAmenities(); + for (Amenity a : tempResults) { + LatLon l = a.getLocation(); + if (l != null && l.getLatitude() <= topLatitude && l.getLatitude() >= bottomLatitude + && l.getLongitude() >= leftLongitude && l.getLongitude() <= rightLongitude) { + if (matcher.publish(a)) { + amenities.add(a); + } + } + } + } else { + final String filterByName = filter.getFilterByName(); + for (AmenityIndexRepository index : amenityRepositories) { + if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { + index.searchAmenities(MapUtils.get31TileNumberY(topLatitude), + MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberY(bottomLatitude), + MapUtils.get31TileNumberX(rightLongitude), zoom, filter, amenities, + new ResultMatcher() { + + @Override + public boolean publish(Amenity object) { + if (checkNameFilter(object, filterByName)) { + return matcher.publish(object); + } + return false; + } + + @Override + public boolean isCancelled() { + return matcher.isCancelled(); + } + }); } } } - } else { - final String filterByName = filter.getFilterByName(); - for (AmenityIndexRepository index : amenityRepositories) { - if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { - index.searchAmenities(MapUtils.get31TileNumberY(topLatitude), - MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberY(bottomLatitude), - MapUtils.get31TileNumberX(rightLongitude), zoom, filter, amenities, - new ResultMatcher() { - - @Override - public boolean publish(Amenity object) { - if (checkNameFilter(object, filterByName)) { - return matcher.publish(object); - } - return false; - } - - @Override - public boolean isCancelled() { - return matcher.isCancelled(); - } - }); - } - } + } finally { + searchAmenitiesInProgress = false; } return amenities; } @@ -813,30 +820,40 @@ public class ResourceManager { return map; } - public void searchAmenitiesOnThePath(List locations, double radius, PoiFilter filter, ResultMatcher matcher) { - if (locations != null && locations.size() > 0) { - List repos = new ArrayList(); - double topLatitude = locations.get(0).getLatitude(); - double bottomLatitude = locations.get(0).getLatitude(); - double leftLongitude = locations.get(0).getLongitude(); - double rightLongitude = locations.get(0).getLongitude(); - for(Location l : locations) { - topLatitude = Math.max(topLatitude, l.getLatitude()); - bottomLatitude = Math.min(bottomLatitude, l.getLatitude()); - leftLongitude = Math.min(leftLongitude, l.getLongitude()); - rightLongitude = Math.max(rightLongitude, l.getLongitude()); - } - for (AmenityIndexRepository index : amenityRepositories) { - if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { - repos.add(index); - } - } - if (!repos.isEmpty()) { - for(AmenityIndexRepository r : repos) { - r.searchAmenitiesOnThePath(locations, radius, filter, matcher); + public List searchAmenitiesOnThePath(List locations, double radius, PoiFilter filter, ResultMatcher matcher) { + searchAmenitiesInProgress = true; + final List amenities = new ArrayList(); + try { + if (locations != null && locations.size() > 0) { + List repos = new ArrayList(); + double topLatitude = locations.get(0).getLatitude(); + double bottomLatitude = locations.get(0).getLatitude(); + double leftLongitude = locations.get(0).getLongitude(); + double rightLongitude = locations.get(0).getLongitude(); + for (Location l : locations) { + topLatitude = Math.max(topLatitude, l.getLatitude()); + bottomLatitude = Math.min(bottomLatitude, l.getLatitude()); + leftLongitude = Math.min(leftLongitude, l.getLongitude()); + rightLongitude = Math.max(rightLongitude, l.getLongitude()); + } + for (AmenityIndexRepository index : amenityRepositories) { + if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { + repos.add(index); + } + } + if (!repos.isEmpty()) { + for (AmenityIndexRepository r : repos) { + List res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher); + if (res != null) { + amenities.addAll(res); + } + } } } + }finally { + searchAmenitiesInProgress = false; } + return amenities; } ////////////////////////////////////////////// Working with address /////////////////////////////////////////// @@ -892,6 +909,10 @@ public class ResourceManager { renderer.interruptLoadingMap(); } + public boolean isSearchAmenitiesInProgress() { + return searchAmenitiesInProgress; + } + public MapRenderRepositories getRenderer() { return renderer; } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index fd56ad6b3a..6d4236c57b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -50,8 +50,8 @@ public class RoutingHelper { private OsmandApplication app; private boolean isFollowingMode = false; - private boolean isRoutePlanningMode = false; + private boolean isPauseNavigation = false; private GPXRouteParamsBuilder currentGPXRoute = null; @@ -79,6 +79,7 @@ public class RoutingHelper { private RouteCalculationProgressCallback progressRoute; private SearchOnTheRouteHelper searchOnTheRouteHelper; + // private ProgressBar progress; // private Handler progressHandler; @@ -101,8 +102,17 @@ public class RoutingHelper { return isFollowingMode; } + public void setPauseNaviation(boolean b) { + this.isPauseNavigation = b; + } + + public boolean isPauseNavigation() { + return isPauseNavigation; + } + public void setFollowingMode(boolean follow) { isFollowingMode = follow; + isPauseNavigation = false; if (!follow) { if (app.getNavigationService() != null) { app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION); @@ -932,4 +942,5 @@ public class RoutingHelper { } } + } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 451917d8a1..090b2aaf64 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -21,6 +21,10 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.render.RenderingIcons; 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 android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -36,7 +40,7 @@ import android.net.Uri; import android.widget.Toast; public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, - MapTextProvider { + MapTextProvider, IRouteInformationListener { private static final int startZoom = 10; 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 ResourceManager resourceManager; + private RoutingHelper routingHelper; private PoiFilter filter; private MapTextLayer mapTextLayer; /// cache for displayed POI // Work with cache (for map copied from AmenityIndexRepositoryOdb) private MapLayerData> data; + private boolean path = false; + private double radius = 100; public POIMapLayer(MapActivity activity) { + routingHelper = activity.getRoutingHelper(); + routingHelper.addListener(this); data = new OsmandMapLayer.MapLayerData>() { { ZOOM_THRESHOLD = 0; @@ -70,19 +79,24 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override protected List calculateResult(RotatedTileBox tileBox) { QuadRect latLonBounds = tileBox.getLatLonBounds(); - return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, - latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher() { + if(path) { + RouteCalculationResult result = routingHelper.getRoute(); + return resourceManager.searchAmenitiesOnThePath(result.getImmutableAllLocations(), radius, filter, null); + } else { + return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, + latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher() { - @Override - public boolean publish(Amenity object) { - return true; - } + @Override + public boolean publish(Amenity object) { + return true; + } - @Override - public boolean isCancelled() { - return isInterrupted(); - } - }); + @Override + public boolean isCancelled() { + return isInterrupted(); + } + }); + } } }; } @@ -92,9 +106,21 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } public void setFilter(PoiFilter filter) { + // TODO parameter this.filter = filter; +// this.radius = 100; +// this.path = true; + this.path = false; 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 am) { List objects = data.getResults(); @@ -224,6 +250,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override public void destroyLayer() { + routingHelper.removeListener(this); } @Override @@ -317,7 +344,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } return null; } - + @Override public LatLon getTextLocation(Amenity o) { return o.getLocation(); @@ -333,4 +360,16 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon return o.getName(view.getSettings().usingEnglishNames()); } + @Override + public void newRouteIsCalculated(boolean newRoute) { + if(path) { + data.clearCache(); + } + } + + @Override + public void routeWasCancelled() { + } + + } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java index 1e2c292136..6c96984c95 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java @@ -111,7 +111,7 @@ public class MapNavigateControl extends MapControls { startNavigation(); } }); - if(!mapActivity.getRoutingHelper().isFollowingMode()) { + if(!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isPauseNavigation()) { startCounter(); } }