mirror of
https://github.com/mollyim/osmdroid.git
synced 2025-05-13 07:10:36 +01:00
#850 should fix resource leaks related to gemf files, offline archives and the demo app. adds some test files sources from US national aviation charts at zoom 4
This commit is contained in:
parent
cb151289f0
commit
b41a8d42ac
7 changed files with 48 additions and 15 deletions
|
@ -104,6 +104,9 @@ before_script:
|
|||
- adb shell chmod 777 /mnt/sdcard
|
||||
- adb shell mkdir /sdcard/osmdroid/
|
||||
- adb push world.map /sdcard/osmdroid/world.map
|
||||
- adb push testzoom4.sqlite /sdcard/osmdroid/testzoom4.sqlite
|
||||
- adb push testzoom4.zip /sdcard/osmdroid/testzoom4.zip
|
||||
- adb push testzoom4.gemf /sdcard/osmdroid/testzoom4.gemf
|
||||
#maybe one day it will be added to the repo- adb push ERDC_Whitehorse_GeoPackage.gpkg /sdcard/osmdroid/ERDC_Whitehorse_GeoPackage.gpkg
|
||||
#- adb push resources/usgsbase.gemf /sdcard/osmdroid/usgsbase.gemf
|
||||
#- adb push resources/usgstopo.sqlite /sdcard/osmdroid/usgstopo.sqlite
|
||||
|
|
|
@ -91,6 +91,13 @@ public class OfflinePickerSample extends BaseSampleFragment implements View.OnCl
|
|||
this.mMapView.setUseDataConnection(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
if (tileWriter!=null)
|
||||
tileWriter.onDetach();
|
||||
}
|
||||
|
||||
/**
|
||||
* step 1, users selects files
|
||||
*/
|
||||
|
@ -128,7 +135,7 @@ public class OfflinePickerSample extends BaseSampleFragment implements View.OnCl
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
IFilesystemCache tileWriter=null;
|
||||
/**
|
||||
* step two, configure our offline tile provider
|
||||
* @param files
|
||||
|
@ -137,8 +144,9 @@ public class OfflinePickerSample extends BaseSampleFragment implements View.OnCl
|
|||
if (files == null || files.length == 0)
|
||||
return;
|
||||
SimpleRegisterReceiver simpleRegisterReceiver = new SimpleRegisterReceiver(getContext());
|
||||
if (tileWriter!=null)
|
||||
tileWriter.onDetach();
|
||||
|
||||
IFilesystemCache tileWriter;
|
||||
|
||||
if (Build.VERSION.SDK_INT < 10) {
|
||||
tileWriter = new TileWriter();
|
||||
|
|
|
@ -140,13 +140,17 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
|||
|
||||
@Override
|
||||
public void detach() {
|
||||
clearArcives();
|
||||
super.detach();
|
||||
}
|
||||
|
||||
private void clearArcives(){
|
||||
while(!mArchiveFiles.isEmpty()) {
|
||||
IArchiveFile t = mArchiveFiles.get(0);
|
||||
if (t!=null)
|
||||
mArchiveFiles.get(0).close();
|
||||
t.close();
|
||||
mArchiveFiles.remove(0);
|
||||
}
|
||||
super.detach();
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
|
@ -154,8 +158,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
|||
// ===========================================================
|
||||
|
||||
private void findArchiveFiles() {
|
||||
|
||||
mArchiveFiles.clear();
|
||||
clearArcives();
|
||||
|
||||
if (!isSdCardAvailable()) {
|
||||
return;
|
||||
|
@ -200,6 +203,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
|||
@Override
|
||||
public Drawable loadTile(final MapTile pTile) {
|
||||
|
||||
Drawable returnValue=null;
|
||||
ITileSource tileSource = mTileSource.get();
|
||||
if (tileSource == null) {
|
||||
return null;
|
||||
|
@ -225,7 +229,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
|||
Log.d(IMapView.LOGTAG,"Use tile from archive: " + pTile);
|
||||
}
|
||||
final Drawable drawable = tileSource.getDrawable(inputStream);
|
||||
return drawable;
|
||||
returnValue = drawable;
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
Log.e(IMapView.LOGTAG,"Error loading tile", e);
|
||||
|
@ -235,7 +239,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
|||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ import java.util.TreeSet;
|
|||
*
|
||||
* Reference: https://sites.google.com/site/abudden/android-map-store
|
||||
*
|
||||
* Do not reference any android specific code in this class, it is reused in the JRE
|
||||
* Tile Packager
|
||||
*
|
||||
* @author A. S. Budden
|
||||
* @author Erik Burrows
|
||||
*
|
||||
|
@ -575,7 +578,9 @@ public class GEMFFile {
|
|||
|
||||
long dataOffset;
|
||||
int dataLength;
|
||||
|
||||
InputStream returnValue=null;
|
||||
GEMFInputStream stream=null;
|
||||
ByteArrayOutputStream byteBuffer=null;
|
||||
try {
|
||||
|
||||
// Determine offset to requested tile record in the header
|
||||
|
@ -612,11 +617,9 @@ public class GEMFFile {
|
|||
// Read data block into a byte array
|
||||
pDataFile.seek(dataOffset);
|
||||
|
||||
|
||||
|
||||
GEMFInputStream stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
|
||||
stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
|
||||
// this dynamically extends to take the bytes you read
|
||||
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
|
||||
byteBuffer = new ByteArrayOutputStream();
|
||||
|
||||
// this is storage overwritten on each iteration with bytes
|
||||
int bufferSize = 1024;
|
||||
|
@ -633,11 +636,26 @@ public class GEMFFile {
|
|||
|
||||
// and then we can return your byte array.
|
||||
byte[] bits = byteBuffer.toByteArray();
|
||||
return new ByteArrayInputStream(bits);
|
||||
returnValue= new ByteArrayInputStream(bits);
|
||||
|
||||
} catch (final java.io.IOException e) {
|
||||
return null;
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (byteBuffer!=null)
|
||||
try {
|
||||
byteBuffer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (stream!=null)
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
|
|
BIN
testzoom4.gemf
Normal file
BIN
testzoom4.gemf
Normal file
Binary file not shown.
BIN
testzoom4.sqlite
Normal file
BIN
testzoom4.sqlite
Normal file
Binary file not shown.
BIN
testzoom4.zip
Normal file
BIN
testzoom4.zip
Normal file
Binary file not shown.
Loading…
Reference in a new issue