fix bug : implement listeners for downloader
git-svn-id: https://osmand.googlecode.com/svn/trunk@72 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
79d2745427
commit
a91d036274
7 changed files with 53 additions and 21 deletions
|
@ -19,8 +19,6 @@ public class ToDoConstants {
|
|||
*/
|
||||
public int DESCRIBE_ABOUT_AUTHORS = 8;
|
||||
|
||||
// TODO see all calculations x, y for layers & for MapView
|
||||
|
||||
// 0. Minimize memory used for index & improve time for read index
|
||||
//// TODO for releasing version
|
||||
// 1. POI SEARCH NEAR TO YOU
|
||||
|
@ -45,8 +43,8 @@ public class ToDoConstants {
|
|||
|
||||
/// SWING version :
|
||||
// TODO :
|
||||
// 1. Predefine before file loading what should be extracted from osm (building, poi or roads) !
|
||||
// 2. Fix TODO in files (accept amenity - way)
|
||||
// 1. Accept amenity as way
|
||||
// 1. Fix TODO in files
|
||||
|
||||
// 3. download tiles without using dir tiles
|
||||
// 4. Config file log & see log from file
|
||||
|
|
|
@ -7,8 +7,10 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
@ -27,7 +29,7 @@ public class MapTileDownloader {
|
|||
|
||||
|
||||
private ThreadPoolExecutor threadPoolExecutor;
|
||||
private IMapDownloaderCallback callback;
|
||||
private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>();
|
||||
|
||||
private Set<File> currentlyDownloaded;
|
||||
|
||||
|
@ -95,12 +97,16 @@ public class MapTileDownloader {
|
|||
|
||||
}
|
||||
|
||||
public void setDownloaderCallback(IMapDownloaderCallback callback){
|
||||
this.callback = callback;
|
||||
public void addDownloaderCallback(IMapDownloaderCallback callback){
|
||||
callbacks.add(callback);
|
||||
}
|
||||
|
||||
public IMapDownloaderCallback getDownloaderCallback() {
|
||||
return callback;
|
||||
public void removeDownloaderCallback(IMapDownloaderCallback callback){
|
||||
callbacks.remove(callback);
|
||||
}
|
||||
|
||||
public List<IMapDownloaderCallback> getDownloaderCallbacks() {
|
||||
return callbacks;
|
||||
}
|
||||
|
||||
public boolean isFileCurrentlyDownloaded(File f){
|
||||
|
@ -181,8 +187,8 @@ public class MapTileDownloader {
|
|||
} finally {
|
||||
currentlyDownloaded.remove(request.fileToSave);
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.tileDownloaded(request);
|
||||
for(IMapDownloaderCallback c : callbacks){
|
||||
c.tileDownloaded(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
|
||||
addControls();
|
||||
|
||||
downloader.setDownloaderCallback(this);
|
||||
downloader.addDownloaderCallback(this);
|
||||
setFocusable(true);
|
||||
addComponentListener(new ComponentAdapter(){
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
@ -195,6 +195,17 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean flag) {
|
||||
super.setVisible(flag);
|
||||
if(!flag){
|
||||
downloader.removeDownloaderCallback(this);
|
||||
} else {
|
||||
downloader.addDownloaderCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double getXTile(){
|
||||
return MapUtils.getTileNumberX(zoom, longitude);
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.awt.event.ActionListener;
|
|||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
|
@ -196,9 +197,10 @@ public class TileBundleDownloadDialog extends JDialog {
|
|||
}
|
||||
|
||||
});
|
||||
IMapDownloaderCallback previousCallback = instance.getDownloaderCallback();
|
||||
instance.setDownloaderCallback(new IMapDownloaderCallback(){
|
||||
|
||||
ArrayList<IMapDownloaderCallback> previousCallbacks =
|
||||
new ArrayList<IMapDownloaderCallback>(instance.getDownloaderCallbacks());
|
||||
instance.getDownloaderCallbacks().clear();
|
||||
instance.addDownloaderCallback(new IMapDownloaderCallback(){
|
||||
@Override
|
||||
public void tileDownloaded(DownloadRequest request) {
|
||||
// TODO request could be null if bundle loading?
|
||||
|
@ -207,6 +209,7 @@ public class TileBundleDownloadDialog extends JDialog {
|
|||
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
progressDialog.run();
|
||||
instance.refuseAllPreviousRequests();
|
||||
|
@ -215,7 +218,8 @@ public class TileBundleDownloadDialog extends JDialog {
|
|||
} catch (InterruptedException e) {
|
||||
ExceptionHandler.handle(e);
|
||||
} finally {
|
||||
instance.setDownloaderCallback(previousCallback);
|
||||
instance.getDownloaderCallbacks().clear();
|
||||
instance.getDownloaderCallbacks().addAll(previousCallbacks);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.osmand.data.DataTileManager;
|
|||
import com.osmand.data.Region;
|
||||
import com.osmand.data.preparation.MapTileDownloader;
|
||||
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||
import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||
import com.osmand.map.ITileSource;
|
||||
import com.osmand.osm.LatLon;
|
||||
import com.osmand.osm.io.OsmIndexStorage;
|
||||
|
@ -148,7 +149,9 @@ public class ResourceManager {
|
|||
}
|
||||
if(update){
|
||||
// use downloader callback
|
||||
downloader.getDownloaderCallback().tileDownloaded(null);
|
||||
for(IMapDownloaderCallback c : downloader.getDownloaderCallbacks()){
|
||||
c.tileDownloaded(null);
|
||||
}
|
||||
}
|
||||
sleep(750);
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.osmand.IMapLocationListener;
|
|||
import com.osmand.OsmandSettings;
|
||||
import com.osmand.R;
|
||||
import com.osmand.ResourceManager;
|
||||
import com.osmand.data.preparation.MapTileDownloader;
|
||||
import com.osmand.views.OsmandMapTileView;
|
||||
import com.osmand.views.POIMapLayer;
|
||||
import com.osmand.views.PointLocationLayer;
|
||||
|
@ -67,6 +68,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
|||
|
||||
setContentView(R.layout.main);
|
||||
mapView = (OsmandMapTileView) findViewById(R.id.MapView);
|
||||
MapTileDownloader.getInstance().addDownloaderCallback(mapView);
|
||||
mapView.setMapLocationListener(this);
|
||||
poiMapLayer = new POIMapLayer();
|
||||
poiMapLayer.setNodeManager(ResourceManager.getResourceManager().getPoiIndex());
|
||||
|
@ -132,6 +134,12 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
MapTileDownloader.getInstance().removeDownloaderCallback(mapView);
|
||||
}
|
||||
|
||||
public void setLocation(Location location){
|
||||
locationLayer.setLastKnownLocation(location);
|
||||
if (location != null) {
|
||||
|
|
|
@ -53,8 +53,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
private IMapLocationListener locationListener;
|
||||
|
||||
private MapTileDownloader downloader = MapTileDownloader.getInstance();
|
||||
|
||||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
||||
|
||||
// UI Part
|
||||
|
@ -98,11 +96,15 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
setClickable(true);
|
||||
getHolder().addCallback(this);
|
||||
downloader.setDownloaderCallback(this);
|
||||
|
||||
animatedDraggingThread = new AnimateDraggingMapThread();
|
||||
animatedDraggingThread.setCallback(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
prepareImage();
|
||||
|
@ -231,7 +233,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
public void prepareImage() {
|
||||
if (OsmandSettings.isUsingInternetToDownloadTiles(getContext())) {
|
||||
downloader.refuseAllPreviousRequests();
|
||||
MapTileDownloader.getInstance().refuseAllPreviousRequests();
|
||||
}
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
|
Loading…
Reference in a new issue