Temporary commit
This commit is contained in:
parent
403c8e750a
commit
d40fa64568
7 changed files with 358 additions and 214 deletions
|
@ -9,11 +9,15 @@ public class ToDoConstants {
|
|||
|
||||
|
||||
// == 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
|
||||
// Remove notification from OsmAndMapTileView (?)
|
||||
// Index version
|
||||
// 1. POI inside obf
|
||||
// 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. ||
|
||||
|
||||
// === 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) ||
|
||||
// || 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) ||
|
||||
// || 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) ||
|
||||
|
||||
|
||||
|
@ -43,13 +43,16 @@ public class ToDoConstants {
|
|||
|
||||
/////////////////////////// DONE //////////////////////////////
|
||||
// DONE ANDROID :
|
||||
// || 104 || Add activity to show current loaded indexes and information about them (Issue 366) ||
|
||||
// || 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) ||
|
||||
// || 120 || Show icons over poi circle (issue 414) ||
|
||||
// || 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) ||
|
||||
// || 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
|
||||
|
||||
}
|
||||
|
|
|
@ -554,7 +554,6 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
|
||||
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();
|
||||
IndexPoiCreator poiCreator = new IndexPoiCreator();
|
||||
// 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);
|
||||
|
||||
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
|
||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
|
||||
PoiFilter filter, List<Amenity> toFill) {
|
||||
cTopLatitude = topLatitude + (topLatitude - bottomLatitude);
|
||||
cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude);
|
||||
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
||||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
||||
PoiFilter filter) {
|
||||
cTopLatitude = topLatitude ;
|
||||
cBottomLatitude = bottomLatitude ;
|
||||
cLeftLongitude = leftLongitude ;
|
||||
cRightLongitude = rightLongitude ;
|
||||
cFilterId = filter == null ? null : filter.getFilterId();
|
||||
cZoom = zoom;
|
||||
// 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);
|
||||
}
|
||||
|
||||
checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, cZoom, filter.getFilterId(), toFill, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,11 +102,11 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
|||
cFilterId = null;
|
||||
}
|
||||
|
||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter, List<Amenity> toFill){
|
||||
cTopLatitude = topLatitude + (topLatitude -bottomLatitude);
|
||||
cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude);
|
||||
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
||||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter){
|
||||
cTopLatitude = topLatitude ;
|
||||
cBottomLatitude = bottomLatitude ;
|
||||
cLeftLongitude = leftLongitude ;
|
||||
cRightLongitude = rightLongitude ;
|
||||
cFilterId = filter == null? null :filter.getFilterId();
|
||||
cZoom = zoom;
|
||||
// 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.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){
|
||||
|
|
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
|
@ -30,10 +29,13 @@ import net.osmand.data.IndexConstants;
|
|||
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;
|
||||
import net.osmand.osm.LatLon;
|
||||
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.render.BaseOsmandRender;
|
||||
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 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 String MINE_POI_DB = APP_DIR + "mine"+ IndexConstants.POI_INDEX_EXT;
|
||||
|
@ -92,7 +93,7 @@ public class ResourceManager {
|
|||
|
||||
private BusyIndicator busyIndicator;
|
||||
|
||||
private final MapTileDownloader downloader = MapTileDownloader.getInstance();
|
||||
|
||||
// Indexes
|
||||
private final Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>(Collator.getInstance());
|
||||
|
||||
|
@ -107,20 +108,18 @@ public class ResourceManager {
|
|||
|
||||
protected final MapRenderRepositories renderer;
|
||||
|
||||
public final AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
|
||||
public final AsyncLoadingThread asyncLoadingTthread = new AsyncLoadingThread(this);
|
||||
|
||||
protected boolean internetIsNotAccessible = false;
|
||||
|
||||
protected AmenityIndexRepositoryOdb updatablePoiDb = null;
|
||||
|
||||
|
||||
public ResourceManager(OsmandApplication context) {
|
||||
this.context = context;
|
||||
this.renderer = new MapRenderRepositories(context);
|
||||
asyncLoadingTiles.start();
|
||||
asyncLoadingTthread.start();
|
||||
|
||||
resetStoreDirectory();
|
||||
|
||||
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
mgr.getDefaultDisplay().getMetrics(dm);
|
||||
|
@ -131,6 +130,7 @@ public class ResourceManager {
|
|||
maxImgCacheSize = (int) (tiles) ;
|
||||
}
|
||||
|
||||
|
||||
public void resetStoreDirectory() {
|
||||
dirWithTiles = context.getSettings().extendOsmandPath(TILES_PATH);
|
||||
dirWithTiles.mkdirs();
|
||||
|
@ -300,7 +300,7 @@ public class ResourceManager {
|
|||
if(sync){
|
||||
return getRequestedImageTile(req);
|
||||
} else {
|
||||
asyncLoadingTiles.requestToLoadImage(req);
|
||||
asyncLoadingTthread.requestToLoadImage(req);
|
||||
}
|
||||
}
|
||||
return cacheOfImages.get(tileId);
|
||||
|
@ -667,18 +667,22 @@ public class ResourceManager {
|
|||
toFill.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String filterId = filter == null ? null : filter.getFilterId();
|
||||
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
|
||||
for (AmenityIndexRepository index : amenityRepositories) {
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filterId, toFill,
|
||||
true)) {
|
||||
asyncLoadingTiles.requestToLoadAmenities(new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude,
|
||||
rightLongitude, zoom, filter));
|
||||
repos.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
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){
|
||||
for(TransportIndexRepository index : transportRepositories){
|
||||
if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){
|
||||
if(!index.checkCachedObjects(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, toFill, true)){
|
||||
asyncLoadingTiles.requestToLoadTransport(
|
||||
new TransportLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom));
|
||||
List<TransportIndexRepository> repos = new ArrayList<TransportIndexRepository>();
|
||||
for (TransportIndexRepository index : transportRepositories) {
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
if (!index.checkCachedObjects(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, toFill, true)) {
|
||||
repos.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!repos.isEmpty()){
|
||||
TransportLoadRequest req = new TransportLoadRequest(repos, zoom);
|
||||
req.setBoundaries(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
|
||||
asyncLoadingTthread.requestToLoadTransport(req);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////// Working with map ////////////////////////////////////////////////
|
||||
|
@ -722,7 +731,7 @@ public class ResourceManager {
|
|||
|
||||
public void updateRendererMap(RotatedTileBox rotatedTileBox){
|
||||
renderer.interruptLoadingMap();
|
||||
asyncLoadingTiles.requestToLoadMap(
|
||||
asyncLoadingTthread.requestToLoadMap(
|
||||
new MapLoadRequest(new RotatedTileBox(rotatedTileBox)));
|
||||
}
|
||||
|
||||
|
@ -828,177 +837,4 @@ public class ResourceManager {
|
|||
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