diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 121b9e367c..af5ffabee8 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -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 diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java index 69735d763e..181b2de568 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java @@ -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 callbacks = new ArrayList(); private Set 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 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); } } diff --git a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java index a9d30021d8..128115af91 100644 --- a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java +++ b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java @@ -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) { @@ -194,6 +194,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(){ diff --git a/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java b/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java index 9ba4f3c61b..2fa9d9ca50 100644 --- a/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java +++ b/DataExtractionOSM/src/com/osmand/swing/TileBundleDownloadDialog.java @@ -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 previousCallbacks = + new ArrayList(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); } } diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 092c77910a..6e2f35b187 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -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) { diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 54e6ec2a9f..da6a394793 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -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) { diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 4c235037ed..98055ac748 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -53,8 +53,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private IMapLocationListener locationListener; - private MapTileDownloader downloader = MapTileDownloader.getInstance(); - private List layers = new ArrayList(); // 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();