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