Underlay/Overlay threading
This commit is contained in:
parent
d25a5a9ba2
commit
1b9455e864
2 changed files with 68 additions and 7 deletions
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.core.jni.AlphaChannelPresence;
|
import net.osmand.core.jni.AlphaChannelPresence;
|
||||||
|
import net.osmand.core.jni.IMapDataProvider;
|
||||||
import net.osmand.core.jni.MapStubStyle;
|
import net.osmand.core.jni.MapStubStyle;
|
||||||
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
|
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
|
||||||
import net.osmand.core.jni.SwigUtilities;
|
import net.osmand.core.jni.SwigUtilities;
|
||||||
|
@ -13,7 +14,9 @@ import net.osmand.core.jni.TileId;
|
||||||
import net.osmand.core.jni.ZoomLevel;
|
import net.osmand.core.jni.ZoomLevel;
|
||||||
import net.osmand.core.jni.interface_ImageMapLayerProvider;
|
import net.osmand.core.jni.interface_ImageMapLayerProvider;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
import net.osmand.map.MapTileDownloader;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.resources.AsyncLoadingThread;
|
||||||
import net.osmand.plus.resources.ResourceManager;
|
import net.osmand.plus.resources.ResourceManager;
|
||||||
|
|
||||||
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||||
|
@ -49,14 +52,22 @@ public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||||
String tileFilename = rm.calculateTileId(tileSource, tileId.getX(), tileId.getY(),
|
String tileFilename = rm.calculateTileId(tileSource, tileId.getX(), tileId.getY(),
|
||||||
zoom.swigValue());
|
zoom.swigValue());
|
||||||
|
|
||||||
if (!rm.tileExistOnFileSystem(tileFilename, tileSource, tileId.getX(), tileId.getY(),
|
final TileReadyCallback tileReadyCallback = new TileReadyCallback(tileSource,
|
||||||
zoom.swigValue())) {
|
tileId.getX(), tileId.getY(), zoom.swigValue());
|
||||||
Bitmap loadedBitmap = null;
|
rm.getMapTileDownloader().addDownloaderCallback(tileReadyCallback);
|
||||||
while (loadedBitmap == null) {
|
while (rm.getTileImageForMapAsync(tileFilename, tileSource, tileId.getX(), tileId.getY(),
|
||||||
loadedBitmap = rm.getTileImageForMapSync(tileFilename, tileSource,
|
zoom.swigValue(), true) == null) {
|
||||||
tileId.getX(), tileId.getY(), zoom.swigValue(), true);
|
synchronized (tileReadyCallback.getSync()) {
|
||||||
|
if (tileReadyCallback.isReady()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
tileReadyCallback.getSync().wait(250);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rm.getMapTileDownloader().removeDownloaderCallback(tileReadyCallback);
|
||||||
|
|
||||||
image = tileSource.getBytes(tileId.getX(), tileId.getY(), zoom.swigValue(),
|
image = tileSource.getBytes(tileId.getX(), tileId.getY(), zoom.swigValue(),
|
||||||
app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath());
|
app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath());
|
||||||
|
@ -83,4 +94,54 @@ public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||||
public AlphaChannelPresence getAlphaChannelPresence() {
|
public AlphaChannelPresence getAlphaChannelPresence() {
|
||||||
return AlphaChannelPresence.Unknown;
|
return AlphaChannelPresence.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMapDataProvider.SourceType getSourceType() {
|
||||||
|
return IMapDataProvider.SourceType.NetworkDirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TileReadyCallback implements MapTileDownloader.IMapDownloaderCallback {
|
||||||
|
private final ITileSource tileSource;
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int zoom;
|
||||||
|
private boolean ready = false;
|
||||||
|
private final Object sync = new Object();
|
||||||
|
|
||||||
|
public TileReadyCallback(ITileSource tileSource, int x, int y, int zoom) {
|
||||||
|
this.tileSource = tileSource;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.zoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReady() {
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getSync() {
|
||||||
|
return sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tileDownloaded(MapTileDownloader.DownloadRequest request) {
|
||||||
|
if (!(request instanceof AsyncLoadingThread.TileLoadDownloadRequest)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AsyncLoadingThread.TileLoadDownloadRequest tileLoadRequest =
|
||||||
|
(AsyncLoadingThread.TileLoadDownloadRequest)request;
|
||||||
|
|
||||||
|
if (tileSource != tileLoadRequest.tileSource ||
|
||||||
|
x != tileLoadRequest.xTile ||
|
||||||
|
y != tileLoadRequest.yTile ||
|
||||||
|
zoom != tileLoadRequest.zoom) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (sync) {
|
||||||
|
ready = true;
|
||||||
|
sync.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class AsyncLoadingThread extends Thread {
|
||||||
resourceManger.getMapTileDownloader().requestToDownload(req);
|
resourceManger.getMapTileDownloader().requestToDownload(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class TileLoadDownloadRequest extends DownloadRequest {
|
public static class TileLoadDownloadRequest extends DownloadRequest {
|
||||||
|
|
||||||
public final String tileId;
|
public final String tileId;
|
||||||
public final File dirWithTiles;
|
public final File dirWithTiles;
|
||||||
|
|
Loading…
Reference in a new issue