Temporary commit
This commit is contained in:
parent
403c8e750a
commit
d40fa64568
7 changed files with 358 additions and 214 deletions
|
@ -10,10 +10,14 @@ public class ToDoConstants {
|
||||||
|
|
||||||
// == Osmand application (TODO 127) ==
|
// == Osmand application (TODO 127) ==
|
||||||
|
|
||||||
|
// TODO support cancelling poi search request! Do it in another thread (Check is cancelled()!!!) TODO transport progress
|
||||||
|
// TODO redesign Directions using GPX file! (One menu directions <-> switch 'Route')
|
||||||
|
// TODO test if voice properly inititialized (first command!)
|
||||||
|
// TODO prepare C++ version of routing algorithm
|
||||||
|
|
||||||
// Map Refactoring
|
// Map Refactoring
|
||||||
// Remove notification from OsmAndMapTileView (?)
|
// Remove notification from OsmAndMapTileView (?)
|
||||||
// Index version
|
// Index version
|
||||||
// 1. POI inside obf
|
|
||||||
// 2. Multiple attributes for one point (amenity=circle, type=...)
|
// 2. Multiple attributes for one point (amenity=circle, type=...)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,13 +25,9 @@ public class ToDoConstants {
|
||||||
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
||||||
|
|
||||||
// === Common issues ===
|
// === Common issues ===
|
||||||
// || 104 || Add activity to show current loaded indexes and information about them (Issue 366) ||
|
|
||||||
// || 123 || Improve gpx file showing (very slow for big files) (Issue 412) ||
|
|
||||||
// || 110 || Use android voice for pronounce command (could be used in future to pronounce street) (Issue 70) ||
|
// || 110 || Use android voice for pronounce command (could be used in future to pronounce street) (Issue 70) ||
|
||||||
// || 97 || For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m (Issue 420) ||
|
|
||||||
// || 111 || Investigate showing street name while driving (Issue 286) ||
|
// || 111 || Investigate showing street name while driving (Issue 286) ||
|
||||||
// || 86 || Allow to add/edit custom tags to POI objects (Issue 44) ||
|
// || 86 || Allow to add/edit custom tags to POI objects (Issue 44) ||
|
||||||
// || 92 || Support poi index with standard map index and unify POI categories (unify done +, works very slow) (Issue 417) ||
|
|
||||||
// || 113 || Calculate speed cameras/bumps on the road (announce about them) (Issue 418) ||
|
// || 113 || Calculate speed cameras/bumps on the road (announce about them) (Issue 418) ||
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,13 +43,16 @@ public class ToDoConstants {
|
||||||
|
|
||||||
/////////////////////////// DONE //////////////////////////////
|
/////////////////////////// DONE //////////////////////////////
|
||||||
// DONE ANDROID :
|
// DONE ANDROID :
|
||||||
|
// || 104 || Add activity to show current loaded indexes and information about them (Issue 366) ||
|
||||||
// || 112 || Investigate exiting/minimizing app (Issue 214) ||
|
// || 112 || Investigate exiting/minimizing app (Issue 214) ||
|
||||||
// || 122 || Frozen sqlite db images (bug?). When images are loaded into sqlite the whole map is frozen (issue 413) ||
|
// || 122 || Frozen sqlite db images (bug?). When images are loaded into sqlite the whole map is frozen (issue 413) ||
|
||||||
// || 120 || Show icons over poi circle (issue 414) ||
|
// || 120 || Show icons over poi circle (issue 414) ||
|
||||||
// || 119 || Dialog on main screen tips and tricks (Issue 415) ||
|
// || 119 || Dialog on main screen tips and tricks (Issue 415) ||
|
||||||
// || 118 || Config switching between maps on different zoom levels <14 (using raster), > 14 vector (Issue 419) ||
|
// || 118 || Config switching between maps on different zoom levels <14 (using raster), > 14 vector (Issue 419) ||
|
||||||
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
||||||
|
// || 92 || Support poi index with standard map index and unify POI categories (unify done +, works very slow) (Issue 417) ||
|
||||||
|
// || 97 || For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m (Issue 420) ||
|
||||||
|
// || 123 || Improve gpx file showing (very slow for big files) (Issue 412) ||
|
||||||
// DONE SWING
|
// DONE SWING
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,7 +554,6 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
|
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
|
||||||
// TODO support cancelling poi search request! Do it in another thread (Check is cancelled()!!!)
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
IndexPoiCreator poiCreator = new IndexPoiCreator();
|
IndexPoiCreator poiCreator = new IndexPoiCreator();
|
||||||
// String fileSqlte = "/home/victor/projects/OsmAnd/data/osm-gen/POI/Ru-mow.poi.odb";
|
// String fileSqlte = "/home/victor/projects/OsmAnd/data/osm-gen/POI/Ru-mow.poi.odb";
|
||||||
|
|
|
@ -26,6 +26,6 @@ public interface AmenityIndexRepository {
|
||||||
String filterId, List<Amenity> toFill, boolean fillFound);
|
String filterId, List<Amenity> toFill, boolean fillFound);
|
||||||
|
|
||||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
|
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
|
||||||
PoiFilter filter, List<Amenity> toFill);
|
PoiFilter filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,11 +141,11 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
|
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
|
||||||
PoiFilter filter, List<Amenity> toFill) {
|
PoiFilter filter) {
|
||||||
cTopLatitude = topLatitude + (topLatitude - bottomLatitude);
|
cTopLatitude = topLatitude ;
|
||||||
cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude);
|
cBottomLatitude = bottomLatitude ;
|
||||||
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
cLeftLongitude = leftLongitude ;
|
||||||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
cRightLongitude = rightLongitude ;
|
||||||
cFilterId = filter == null ? null : filter.getFilterId();
|
cFilterId = filter == null ? null : filter.getFilterId();
|
||||||
cZoom = zoom;
|
cZoom = zoom;
|
||||||
// first of all put all entities in temp list in order to not freeze other read threads
|
// first of all put all entities in temp list in order to not freeze other read threads
|
||||||
|
@ -160,8 +160,6 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
|
||||||
cachedObjects.addAll(tempList);
|
cachedObjects.addAll(tempList);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, cZoom, filter.getFilterId(), toFill, true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,11 +102,11 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
||||||
cFilterId = null;
|
cFilterId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter, List<Amenity> toFill){
|
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter){
|
||||||
cTopLatitude = topLatitude + (topLatitude -bottomLatitude);
|
cTopLatitude = topLatitude ;
|
||||||
cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude);
|
cBottomLatitude = bottomLatitude ;
|
||||||
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
cLeftLongitude = leftLongitude ;
|
||||||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
cRightLongitude = rightLongitude ;
|
||||||
cFilterId = filter == null? null :filter.getFilterId();
|
cFilterId = filter == null? null :filter.getFilterId();
|
||||||
cZoom = zoom;
|
cZoom = zoom;
|
||||||
// first of all put all entities in temp list in order to not freeze other read threads
|
// first of all put all entities in temp list in order to not freeze other read threads
|
||||||
|
@ -120,8 +120,6 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
||||||
cachedObjects.clear();
|
cachedObjects.clear();
|
||||||
cachedObjects.addAll(tempList);
|
cachedObjects.addAll(tempList);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, cZoom, filter.getFilterId(), toFill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, String filterId, List<Amenity> toFill, boolean fillFound){
|
public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, String filterId, List<Amenity> toFill, boolean fillFound){
|
||||||
|
|
310
OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java
Normal file
310
OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java
Normal file
|
@ -0,0 +1,310 @@
|
||||||
|
package net.osmand.plus;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
|
import net.osmand.Algoritms;
|
||||||
|
import net.osmand.ResultMatcher;
|
||||||
|
import net.osmand.data.Amenity;
|
||||||
|
import net.osmand.data.MapTileDownloader;
|
||||||
|
import net.osmand.data.TransportStop;
|
||||||
|
import net.osmand.data.MapTileDownloader.DownloadRequest;
|
||||||
|
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
|
||||||
|
import net.osmand.map.ITileSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread to load map objects (POI, transport stops )async
|
||||||
|
*/
|
||||||
|
public class AsyncLoadingThread extends Thread {
|
||||||
|
|
||||||
|
public static final int LIMIT_TRANSPORT = 200;
|
||||||
|
|
||||||
|
private Handler asyncLoadingPoi;
|
||||||
|
|
||||||
|
private Handler asyncLoadingTransport;
|
||||||
|
|
||||||
|
Stack<Object> requests = new Stack<Object>();
|
||||||
|
AmenityLoadRequest poiLoadRequest = null;
|
||||||
|
TransportLoadRequest transportLoadRequest = null;
|
||||||
|
|
||||||
|
private final MapTileDownloader downloader = MapTileDownloader.getInstance();
|
||||||
|
|
||||||
|
private final ResourceManager resourceManger;
|
||||||
|
|
||||||
|
public AsyncLoadingThread(ResourceManager resourceManger) {
|
||||||
|
super("Loader map objects (synchronizer)"); //$NON-NLS-1$
|
||||||
|
this.resourceManger = resourceManger;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startPoiLoadingThread() {
|
||||||
|
if (asyncLoadingPoi == null) {
|
||||||
|
Thread th = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Looper.prepare();
|
||||||
|
asyncLoadingPoi = new Handler();
|
||||||
|
Looper.loop();
|
||||||
|
}
|
||||||
|
}, "Loading poi");
|
||||||
|
th.start();
|
||||||
|
}
|
||||||
|
while(asyncLoadingPoi != null){
|
||||||
|
// wait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startTransportLoadingThread() {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Looper.prepare();
|
||||||
|
asyncLoadingTransport = new Handler();
|
||||||
|
Looper.loop();
|
||||||
|
}
|
||||||
|
}, "Loading transport").start();
|
||||||
|
while(asyncLoadingTransport != null){
|
||||||
|
// wait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
boolean update = false;
|
||||||
|
boolean amenityLoaded = false;
|
||||||
|
boolean transportLoaded = false;
|
||||||
|
boolean mapLoaded = false;
|
||||||
|
int progress = 0;
|
||||||
|
if (downloader.isSomethingBeingDownloaded()) {
|
||||||
|
progress = BusyIndicator.STATUS_GREEN;
|
||||||
|
}
|
||||||
|
synchronized (resourceManger) {
|
||||||
|
if (resourceManger.getBusyIndicator() != null) {
|
||||||
|
|
||||||
|
if (resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated()) {
|
||||||
|
progress = BusyIndicator.STATUS_BLUE;
|
||||||
|
} else if (!requests.isEmpty()) {
|
||||||
|
progress = BusyIndicator.STATUS_BLACK;
|
||||||
|
}
|
||||||
|
resourceManger.getBusyIndicator().updateStatus(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!requests.isEmpty()) {
|
||||||
|
Object req = requests.pop();
|
||||||
|
if (req instanceof TileLoadDownloadRequest) {
|
||||||
|
TileLoadDownloadRequest r = (TileLoadDownloadRequest) req;
|
||||||
|
if (cacheOfImages.get(r.tileId) == null) {
|
||||||
|
update |= getRequestedImageTile(r) != null;
|
||||||
|
}
|
||||||
|
} else if (req instanceof AmenityLoadRequest) {
|
||||||
|
if (!amenityLoaded) {
|
||||||
|
if (poiLoadRequest == null || asyncLoadingPoi == null) {
|
||||||
|
startPoiLoadingThread();
|
||||||
|
poiLoadRequest = (AmenityLoadRequest) req;
|
||||||
|
asyncLoadingPoi.post(poiLoadRequest.prepareToRun());
|
||||||
|
} else if (poiLoadRequest.recalculateRequest((AmenityLoadRequest) req)) {
|
||||||
|
asyncLoadingPoi.post(poiLoadRequest.prepareToRun());
|
||||||
|
}
|
||||||
|
amenityLoaded = true;
|
||||||
|
}
|
||||||
|
} else if (req instanceof TransportLoadRequest) {
|
||||||
|
if (!transportLoaded) {
|
||||||
|
if (transportLoadRequest == null || asyncLoadingTransport == null) {
|
||||||
|
startTransportLoadingThread();
|
||||||
|
transportLoadRequest = (TransportLoadRequest) req;
|
||||||
|
asyncLoadingTransport.post(transportLoadRequest.prepareToRun());
|
||||||
|
} else if (transportLoadRequest.recalculateRequest((TransportLoadRequest) req)) {
|
||||||
|
asyncLoadingTransport.post(transportLoadRequest.prepareToRun());
|
||||||
|
}
|
||||||
|
transportLoaded = true;
|
||||||
|
}
|
||||||
|
} else if (req instanceof MapLoadRequest) {
|
||||||
|
if (!mapLoaded) {
|
||||||
|
MapLoadRequest r = (MapLoadRequest) req;
|
||||||
|
renderer.loadMap(r.tileBox, downloader.getDownloaderCallbacks());
|
||||||
|
mapLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (update || amenityLoaded || transportLoaded || mapLoaded) {
|
||||||
|
// use downloader callback
|
||||||
|
for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) {
|
||||||
|
c.tileDownloaded(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean routeBeingCalculated = resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated();
|
||||||
|
if (progress != 0 || routeBeingCalculated || downloader.isSomethingBeingDownloaded()) {
|
||||||
|
synchronized (resourceManger) {
|
||||||
|
if (resourceManger.getBusyIndicator() != null) {
|
||||||
|
if (routeBeingCalculated) {
|
||||||
|
progress = BusyIndicator.STATUS_BLUE;
|
||||||
|
} else if (downloader.isSomethingBeingDownloaded()) {
|
||||||
|
progress = BusyIndicator.STATUS_GREEN;
|
||||||
|
} else {
|
||||||
|
progress = 0;
|
||||||
|
}
|
||||||
|
resourceManger.getBusyIndicator().updateStatus(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(750);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error(e, e);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestToLoadImage(TileLoadDownloadRequest req) {
|
||||||
|
requests.push(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestToLoadAmenities(AmenityLoadRequest req) {
|
||||||
|
requests.push(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestToLoadMap(MapLoadRequest req) {
|
||||||
|
requests.push(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestToLoadTransport(TransportLoadRequest req) {
|
||||||
|
requests.push(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class TileLoadDownloadRequest extends DownloadRequest {
|
||||||
|
|
||||||
|
public final String tileId;
|
||||||
|
public final File dirWithTiles;
|
||||||
|
public final ITileSource tileSource;
|
||||||
|
|
||||||
|
public TileLoadDownloadRequest(File dirWithTiles, String url, File fileToSave, String tileId, ITileSource source, int tileX,
|
||||||
|
int tileY, int zoom) {
|
||||||
|
super(url, fileToSave, tileX, tileY, zoom);
|
||||||
|
this.dirWithTiles = dirWithTiles;
|
||||||
|
this.tileSource = source;
|
||||||
|
this.tileId = tileId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class MapObjectLoadRequest<T> implements ResultMatcher<T> {
|
||||||
|
protected double topLatitude;
|
||||||
|
protected double bottomLatitude;
|
||||||
|
protected double leftLongitude;
|
||||||
|
protected double rightLongitude;
|
||||||
|
protected boolean cancelled = false;
|
||||||
|
|
||||||
|
public boolean isContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
|
||||||
|
boolean inside = this.topLatitude >= topLatitude && this.leftLongitude <= leftLongitude
|
||||||
|
&& this.rightLongitude >= rightLongitude && this.bottomLatitude <= bottomLatitude;
|
||||||
|
return inside;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundaries(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
|
||||||
|
this.topLatitude = topLatitude;
|
||||||
|
this.bottomLatitude = bottomLatitude;
|
||||||
|
this.leftLongitude = leftLongitude;
|
||||||
|
this.rightLongitude = rightLongitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean publish(T object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class AmenityLoadRequest extends MapObjectLoadRequest<Amenity> {
|
||||||
|
private final List<AmenityIndexRepository> res;
|
||||||
|
private final PoiFilter filter;
|
||||||
|
private final int zoom;
|
||||||
|
|
||||||
|
public AmenityLoadRequest(List<AmenityIndexRepository> repos, int zoom, PoiFilter filter) {
|
||||||
|
super();
|
||||||
|
this.res = repos;
|
||||||
|
this.zoom = zoom;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Runnable prepareToRun() {
|
||||||
|
final double ntopLatitude = topLatitude + (topLatitude - bottomLatitude);
|
||||||
|
final double nbottomLatitude = bottomLatitude - (topLatitude - bottomLatitude);
|
||||||
|
final double nleftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
||||||
|
final double nrightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
||||||
|
setBoundaries(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude);
|
||||||
|
return new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (AmenityIndexRepository repository : res) {
|
||||||
|
repository.evaluateCachedAmenities(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recalculateRequest(AmenityLoadRequest req) {
|
||||||
|
if (this.zoom != req.zoom || !Algoritms.objectEquals(this.filter, req.filter)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !isContains(req.topLatitude, req.leftLongitude, req.bottomLatitude, req.rightLongitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class TransportLoadRequest extends MapObjectLoadRequest<TransportStop> {
|
||||||
|
private final List<TransportIndexRepository> repos;
|
||||||
|
private int zoom;
|
||||||
|
|
||||||
|
public TransportLoadRequest(List<TransportIndexRepository> repos, int zoom) {
|
||||||
|
super();
|
||||||
|
this.repos = repos;
|
||||||
|
this.zoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Runnable prepareToRun() {
|
||||||
|
final double ntopLatitude = topLatitude + (topLatitude - bottomLatitude);
|
||||||
|
final double nbottomLatitude = bottomLatitude - (topLatitude - bottomLatitude);
|
||||||
|
final double nleftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
||||||
|
final double nrightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
||||||
|
setBoundaries(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude);
|
||||||
|
return new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (TransportIndexRepository repository : repos) {
|
||||||
|
repository.evaluateCachedTransportStops(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom,
|
||||||
|
LIMIT_TRANSPORT, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recalculateRequest(AmenityLoadRequest req) {
|
||||||
|
if (this.zoom != req.zoom) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !isContains(req.topLatitude, req.leftLongitude, req.bottomLatitude, req.rightLongitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class MapLoadRequest {
|
||||||
|
public final RotatedTileBox tileBox;
|
||||||
|
|
||||||
|
public MapLoadRequest(RotatedTileBox tileBox) {
|
||||||
|
super();
|
||||||
|
this.tileBox = tileBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import java.util.Date;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.osmand.Algoritms;
|
import net.osmand.Algoritms;
|
||||||
|
@ -30,10 +29,13 @@ import net.osmand.data.IndexConstants;
|
||||||
import net.osmand.data.MapTileDownloader;
|
import net.osmand.data.MapTileDownloader;
|
||||||
import net.osmand.data.TransportStop;
|
import net.osmand.data.TransportStop;
|
||||||
import net.osmand.data.MapTileDownloader.DownloadRequest;
|
import net.osmand.data.MapTileDownloader.DownloadRequest;
|
||||||
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
|
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.osm.LatLon;
|
import net.osmand.osm.LatLon;
|
||||||
import net.osmand.osm.MapUtils;
|
import net.osmand.osm.MapUtils;
|
||||||
|
import net.osmand.plus.AsyncLoadingThread.AmenityLoadRequest;
|
||||||
|
import net.osmand.plus.AsyncLoadingThread.MapLoadRequest;
|
||||||
|
import net.osmand.plus.AsyncLoadingThread.TileLoadDownloadRequest;
|
||||||
|
import net.osmand.plus.AsyncLoadingThread.TransportLoadRequest;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
import net.osmand.plus.render.BaseOsmandRender;
|
import net.osmand.plus.render.BaseOsmandRender;
|
||||||
import net.osmand.plus.render.MapRenderRepositories;
|
import net.osmand.plus.render.MapRenderRepositories;
|
||||||
|
@ -70,7 +72,6 @@ public class ResourceManager {
|
||||||
public static final String TEMP_SOURCE_TO_LOAD = "temp"; //$NON-NLS-1$
|
public static final String TEMP_SOURCE_TO_LOAD = "temp"; //$NON-NLS-1$
|
||||||
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final int LIMIT_TRANSPORT = 200;
|
|
||||||
|
|
||||||
private static final Log log = LogUtil.getLog(ResourceManager.class);
|
private static final Log log = LogUtil.getLog(ResourceManager.class);
|
||||||
private static final String MINE_POI_DB = APP_DIR + "mine"+ IndexConstants.POI_INDEX_EXT;
|
private static final String MINE_POI_DB = APP_DIR + "mine"+ IndexConstants.POI_INDEX_EXT;
|
||||||
|
@ -92,7 +93,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
private BusyIndicator busyIndicator;
|
private BusyIndicator busyIndicator;
|
||||||
|
|
||||||
private final MapTileDownloader downloader = MapTileDownloader.getInstance();
|
|
||||||
// Indexes
|
// Indexes
|
||||||
private final Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>(Collator.getInstance());
|
private final Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>(Collator.getInstance());
|
||||||
|
|
||||||
|
@ -107,20 +108,18 @@ public class ResourceManager {
|
||||||
|
|
||||||
protected final MapRenderRepositories renderer;
|
protected final MapRenderRepositories renderer;
|
||||||
|
|
||||||
public final AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
|
public final AsyncLoadingThread asyncLoadingTthread = new AsyncLoadingThread(this);
|
||||||
|
|
||||||
protected boolean internetIsNotAccessible = false;
|
protected boolean internetIsNotAccessible = false;
|
||||||
|
|
||||||
protected AmenityIndexRepositoryOdb updatablePoiDb = null;
|
protected AmenityIndexRepositoryOdb updatablePoiDb = null;
|
||||||
|
|
||||||
|
|
||||||
public ResourceManager(OsmandApplication context) {
|
public ResourceManager(OsmandApplication context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.renderer = new MapRenderRepositories(context);
|
this.renderer = new MapRenderRepositories(context);
|
||||||
asyncLoadingTiles.start();
|
asyncLoadingTthread.start();
|
||||||
|
|
||||||
resetStoreDirectory();
|
resetStoreDirectory();
|
||||||
|
|
||||||
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
||||||
DisplayMetrics dm = new DisplayMetrics();
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
mgr.getDefaultDisplay().getMetrics(dm);
|
mgr.getDefaultDisplay().getMetrics(dm);
|
||||||
|
@ -131,6 +130,7 @@ public class ResourceManager {
|
||||||
maxImgCacheSize = (int) (tiles) ;
|
maxImgCacheSize = (int) (tiles) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void resetStoreDirectory() {
|
public void resetStoreDirectory() {
|
||||||
dirWithTiles = context.getSettings().extendOsmandPath(TILES_PATH);
|
dirWithTiles = context.getSettings().extendOsmandPath(TILES_PATH);
|
||||||
dirWithTiles.mkdirs();
|
dirWithTiles.mkdirs();
|
||||||
|
@ -300,7 +300,7 @@ public class ResourceManager {
|
||||||
if(sync){
|
if(sync){
|
||||||
return getRequestedImageTile(req);
|
return getRequestedImageTile(req);
|
||||||
} else {
|
} else {
|
||||||
asyncLoadingTiles.requestToLoadImage(req);
|
asyncLoadingTthread.requestToLoadImage(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cacheOfImages.get(tileId);
|
return cacheOfImages.get(tileId);
|
||||||
|
@ -667,18 +667,22 @@ public class ResourceManager {
|
||||||
toFill.add(a);
|
toFill.add(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String filterId = filter == null ? null : filter.getFilterId();
|
String filterId = filter == null ? null : filter.getFilterId();
|
||||||
|
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
|
||||||
for (AmenityIndexRepository index : amenityRepositories) {
|
for (AmenityIndexRepository index : amenityRepositories) {
|
||||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||||
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filterId, toFill,
|
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filterId, toFill,
|
||||||
true)) {
|
true)) {
|
||||||
asyncLoadingTiles.requestToLoadAmenities(new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude,
|
repos.add(index);
|
||||||
rightLongitude, zoom, filter));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!repos.isEmpty()){
|
||||||
|
AmenityLoadRequest req = new AmenityLoadRequest(repos, zoom, filter);
|
||||||
|
req.setBoundaries(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
|
||||||
|
asyncLoadingTthread.requestToLoadAmenities(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,14 +709,19 @@ public class ResourceManager {
|
||||||
|
|
||||||
|
|
||||||
public void searchTransportAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, List<TransportStop> toFill){
|
public void searchTransportAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, List<TransportStop> toFill){
|
||||||
for(TransportIndexRepository index : transportRepositories){
|
List<TransportIndexRepository> repos = new ArrayList<TransportIndexRepository>();
|
||||||
if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){
|
for (TransportIndexRepository index : transportRepositories) {
|
||||||
if(!index.checkCachedObjects(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, toFill, true)){
|
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||||
asyncLoadingTiles.requestToLoadTransport(
|
if (!index.checkCachedObjects(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, toFill, true)) {
|
||||||
new TransportLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom));
|
repos.add(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!repos.isEmpty()){
|
||||||
|
TransportLoadRequest req = new TransportLoadRequest(repos, zoom);
|
||||||
|
req.setBoundaries(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
|
||||||
|
asyncLoadingTthread.requestToLoadTransport(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with map ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with map ////////////////////////////////////////////////
|
||||||
|
@ -722,7 +731,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
public void updateRendererMap(RotatedTileBox rotatedTileBox){
|
public void updateRendererMap(RotatedTileBox rotatedTileBox){
|
||||||
renderer.interruptLoadingMap();
|
renderer.interruptLoadingMap();
|
||||||
asyncLoadingTiles.requestToLoadMap(
|
asyncLoadingTthread.requestToLoadMap(
|
||||||
new MapLoadRequest(new RotatedTileBox(rotatedTileBox)));
|
new MapLoadRequest(new RotatedTileBox(rotatedTileBox)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -828,177 +837,4 @@ public class ResourceManager {
|
||||||
cacheOfImages.remove(list.get(i));
|
cacheOfImages.remove(list.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TileLoadDownloadRequest extends DownloadRequest {
|
|
||||||
|
|
||||||
public final String tileId;
|
|
||||||
public final File dirWithTiles;
|
|
||||||
public final ITileSource tileSource;
|
|
||||||
|
|
||||||
public TileLoadDownloadRequest(File dirWithTiles, String url, File fileToSave,
|
|
||||||
String tileId, ITileSource source, int tileX, int tileY, int zoom) {
|
|
||||||
super(url, fileToSave, tileX, tileY, zoom);
|
|
||||||
this.dirWithTiles = dirWithTiles;
|
|
||||||
this.tileSource = source;
|
|
||||||
this.tileId = tileId;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static class AmenityLoadRequest {
|
|
||||||
public final AmenityIndexRepository repository;
|
|
||||||
public final double topLatitude;
|
|
||||||
public final double bottomLatitude;
|
|
||||||
public final double leftLongitude;
|
|
||||||
public final double rightLongitude;
|
|
||||||
public final PoiFilter filter;
|
|
||||||
public final int zoom;
|
|
||||||
|
|
||||||
public AmenityLoadRequest(AmenityIndexRepository repository, double topLatitude, double leftLongitude,
|
|
||||||
double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter) {
|
|
||||||
super();
|
|
||||||
this.bottomLatitude = bottomLatitude;
|
|
||||||
this.leftLongitude = leftLongitude;
|
|
||||||
this.repository = repository;
|
|
||||||
this.rightLongitude = rightLongitude;
|
|
||||||
this.topLatitude = topLatitude;
|
|
||||||
this.zoom = zoom;
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static class TransportLoadRequest {
|
|
||||||
public final TransportIndexRepository repository;
|
|
||||||
public final double topLatitude;
|
|
||||||
public final double bottomLatitude;
|
|
||||||
public final double leftLongitude;
|
|
||||||
public final double rightLongitude;
|
|
||||||
public final int zoom;
|
|
||||||
|
|
||||||
public TransportLoadRequest(TransportIndexRepository repository, double topLatitude, double leftLongitude,
|
|
||||||
double bottomLatitude, double rightLongitude, int zoom) {
|
|
||||||
super();
|
|
||||||
this.bottomLatitude = bottomLatitude;
|
|
||||||
this.leftLongitude = leftLongitude;
|
|
||||||
this.repository = repository;
|
|
||||||
this.rightLongitude = rightLongitude;
|
|
||||||
this.topLatitude = topLatitude;
|
|
||||||
this.zoom = zoom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MapLoadRequest {
|
|
||||||
public final RotatedTileBox tileBox;
|
|
||||||
|
|
||||||
public MapLoadRequest(RotatedTileBox tileBox) {
|
|
||||||
super();
|
|
||||||
this.tileBox = tileBox;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AsyncLoadingThread extends Thread {
|
|
||||||
Stack<Object> requests = new Stack<Object>();
|
|
||||||
|
|
||||||
public AsyncLoadingThread(){
|
|
||||||
super("Loader map objects (tiles, poi)"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while(true){
|
|
||||||
try {
|
|
||||||
boolean update = false;
|
|
||||||
boolean amenityLoaded = false;
|
|
||||||
boolean transportLoaded = false;
|
|
||||||
boolean mapLoaded = false;
|
|
||||||
int progress = 0;
|
|
||||||
if(downloader.isSomethingBeingDownloaded()){
|
|
||||||
progress = BusyIndicator.STATUS_GREEN;
|
|
||||||
}
|
|
||||||
synchronized(ResourceManager.this){
|
|
||||||
if(busyIndicator != null){
|
|
||||||
if(context.getRoutingHelper().isRouteBeingCalculated()){
|
|
||||||
progress = BusyIndicator.STATUS_BLUE;
|
|
||||||
} else if(!requests.isEmpty()){
|
|
||||||
progress = BusyIndicator.STATUS_BLACK;;
|
|
||||||
}
|
|
||||||
busyIndicator.updateStatus(progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(!requests.isEmpty()){
|
|
||||||
Object req = requests.pop();
|
|
||||||
if (req instanceof TileLoadDownloadRequest) {
|
|
||||||
TileLoadDownloadRequest r = (TileLoadDownloadRequest) req;
|
|
||||||
if (cacheOfImages.get(r.tileId) == null) {
|
|
||||||
update |= getRequestedImageTile(r) != null;
|
|
||||||
}
|
|
||||||
} else if(req instanceof AmenityLoadRequest){
|
|
||||||
if(!amenityLoaded){
|
|
||||||
AmenityLoadRequest r = (AmenityLoadRequest) req;
|
|
||||||
r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude,
|
|
||||||
r.bottomLatitude, r.rightLongitude, r.zoom, r.filter, null);
|
|
||||||
amenityLoaded = true;
|
|
||||||
}
|
|
||||||
} else if(req instanceof TransportLoadRequest){
|
|
||||||
if(!transportLoaded){
|
|
||||||
TransportLoadRequest r = (TransportLoadRequest) req;
|
|
||||||
r.repository.evaluateCachedTransportStops(r.topLatitude, r.leftLongitude,
|
|
||||||
r.bottomLatitude, r.rightLongitude, r.zoom, LIMIT_TRANSPORT, null);
|
|
||||||
transportLoaded = true;
|
|
||||||
}
|
|
||||||
} else if(req instanceof MapLoadRequest){
|
|
||||||
if(!mapLoaded){
|
|
||||||
MapLoadRequest r = (MapLoadRequest) req;
|
|
||||||
renderer.loadMap(r.tileBox, downloader.getDownloaderCallbacks());
|
|
||||||
mapLoaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(update || amenityLoaded || transportLoaded || mapLoaded){
|
|
||||||
// use downloader callback
|
|
||||||
for(IMapDownloaderCallback c : downloader.getDownloaderCallbacks()){
|
|
||||||
c.tileDownloaded(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean routeBeingCalculated = context.getRoutingHelper().isRouteBeingCalculated();
|
|
||||||
if (progress != 0 || routeBeingCalculated || downloader.isSomethingBeingDownloaded()) {
|
|
||||||
synchronized (ResourceManager.this) {
|
|
||||||
if (busyIndicator != null) {
|
|
||||||
if(routeBeingCalculated){
|
|
||||||
progress = BusyIndicator.STATUS_BLUE;
|
|
||||||
} else if(downloader.isSomethingBeingDownloaded()){
|
|
||||||
progress = BusyIndicator.STATUS_GREEN;
|
|
||||||
} else {
|
|
||||||
progress = 0;
|
|
||||||
}
|
|
||||||
busyIndicator.updateStatus(progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep(750);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.error(e, e);
|
|
||||||
} catch (RuntimeException e){
|
|
||||||
log.error(e, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void requestToLoadImage(TileLoadDownloadRequest req){
|
|
||||||
requests.push(req);
|
|
||||||
}
|
|
||||||
public void requestToLoadAmenities(AmenityLoadRequest req){
|
|
||||||
requests.push(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void requestToLoadMap(MapLoadRequest req){
|
|
||||||
requests.push(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void requestToLoadTransport(TransportLoadRequest req){
|
|
||||||
requests.push(req);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in a new issue