Fix pause navigation and implement search poi on the path
This commit is contained in:
parent
441b547a21
commit
431fd20f76
8 changed files with 145 additions and 75 deletions
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="app_name">OsmAnd~</string>
|
||||
<string name="app_version">1.8 alpha</string>
|
||||
<string name="app_version">1.9 alpha</string>
|
||||
<!-- Not translatable -->
|
||||
<string name="ga_api_key">UA-28342846-2</string>
|
||||
<string name="ga_dispatchPeriod">10</string>
|
||||
|
|
|
@ -820,6 +820,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
} else {
|
||||
routingHelper.setRoutePlanningMode(true);
|
||||
routingHelper.setFollowingMode(false);
|
||||
routingHelper.setPauseNaviation(true);
|
||||
}
|
||||
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
|
||||
mapActivity.refreshMap();
|
||||
|
|
|
@ -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<Object> requests = new Stack<Object>();
|
||||
|
@ -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()) {
|
||||
|
|
|
@ -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<Amenity> searchAmenities(PoiFilter filter,
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||
final List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
if(filter instanceof NameFinderPoiFilter || filter instanceof SearchByNameFilter){
|
||||
List<Amenity> 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<Amenity> 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<Amenity>() {
|
||||
|
||||
@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<Amenity>() {
|
||||
|
||||
@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<Location> locations, double radius, PoiFilter filter, ResultMatcher<Amenity> matcher) {
|
||||
if (locations != null && locations.size() > 0) {
|
||||
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
|
||||
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<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) {
|
||||
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
|
||||
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<Amenity> 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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Amenity> {
|
||||
MapTextProvider<Amenity>, 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<List<Amenity>> data;
|
||||
private boolean path = false;
|
||||
private double radius = 100;
|
||||
|
||||
|
||||
public POIMapLayer(MapActivity activity) {
|
||||
routingHelper = activity.getRoutingHelper();
|
||||
routingHelper.addListener(this);
|
||||
data = new OsmandMapLayer.MapLayerData<List<Amenity>>() {
|
||||
{
|
||||
ZOOM_THRESHOLD = 0;
|
||||
|
@ -70,19 +79,24 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
@Override
|
||||
protected List<Amenity> calculateResult(RotatedTileBox tileBox) {
|
||||
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||
return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left,
|
||||
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() {
|
||||
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<Amenity>() {
|
||||
|
||||
@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,10 +106,22 @@ 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<? super Amenity> am) {
|
||||
List<Amenity> objects = data.getResults();
|
||||
if (objects != null) {
|
||||
|
@ -224,6 +250,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
routingHelper.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class MapNavigateControl extends MapControls {
|
|||
startNavigation();
|
||||
}
|
||||
});
|
||||
if(!mapActivity.getRoutingHelper().isFollowingMode()) {
|
||||
if(!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isPauseNavigation()) {
|
||||
startCounter();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue