mirror of
https://github.com/mollyim/osmdroid.git
synced 2025-05-16 08:40: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 chmod 777 /mnt/sdcard
|
||||||
- adb shell mkdir /sdcard/osmdroid/
|
- adb shell mkdir /sdcard/osmdroid/
|
||||||
- adb push world.map /sdcard/osmdroid/world.map
|
- 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
|
#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/usgsbase.gemf /sdcard/osmdroid/usgsbase.gemf
|
||||||
#- adb push resources/usgstopo.sqlite /sdcard/osmdroid/usgstopo.sqlite
|
#- 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);
|
this.mMapView.setUseDataConnection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy(){
|
||||||
|
super.onDestroy();
|
||||||
|
if (tileWriter!=null)
|
||||||
|
tileWriter.onDetach();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* step 1, users selects files
|
* step 1, users selects files
|
||||||
*/
|
*/
|
||||||
|
@ -128,7 +135,7 @@ public class OfflinePickerSample extends BaseSampleFragment implements View.OnCl
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IFilesystemCache tileWriter=null;
|
||||||
/**
|
/**
|
||||||
* step two, configure our offline tile provider
|
* step two, configure our offline tile provider
|
||||||
* @param files
|
* @param files
|
||||||
|
@ -137,8 +144,9 @@ public class OfflinePickerSample extends BaseSampleFragment implements View.OnCl
|
||||||
if (files == null || files.length == 0)
|
if (files == null || files.length == 0)
|
||||||
return;
|
return;
|
||||||
SimpleRegisterReceiver simpleRegisterReceiver = new SimpleRegisterReceiver(getContext());
|
SimpleRegisterReceiver simpleRegisterReceiver = new SimpleRegisterReceiver(getContext());
|
||||||
|
if (tileWriter!=null)
|
||||||
|
tileWriter.onDetach();
|
||||||
|
|
||||||
IFilesystemCache tileWriter;
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < 10) {
|
if (Build.VERSION.SDK_INT < 10) {
|
||||||
tileWriter = new TileWriter();
|
tileWriter = new TileWriter();
|
||||||
|
|
|
@ -140,13 +140,17 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detach() {
|
public void detach() {
|
||||||
|
clearArcives();
|
||||||
|
super.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearArcives(){
|
||||||
while(!mArchiveFiles.isEmpty()) {
|
while(!mArchiveFiles.isEmpty()) {
|
||||||
IArchiveFile t = mArchiveFiles.get(0);
|
IArchiveFile t = mArchiveFiles.get(0);
|
||||||
if (t!=null)
|
if (t!=null)
|
||||||
mArchiveFiles.get(0).close();
|
t.close();
|
||||||
mArchiveFiles.remove(0);
|
mArchiveFiles.remove(0);
|
||||||
}
|
}
|
||||||
super.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
@ -154,8 +158,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
private void findArchiveFiles() {
|
private void findArchiveFiles() {
|
||||||
|
clearArcives();
|
||||||
mArchiveFiles.clear();
|
|
||||||
|
|
||||||
if (!isSdCardAvailable()) {
|
if (!isSdCardAvailable()) {
|
||||||
return;
|
return;
|
||||||
|
@ -200,6 +203,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
||||||
@Override
|
@Override
|
||||||
public Drawable loadTile(final MapTile pTile) {
|
public Drawable loadTile(final MapTile pTile) {
|
||||||
|
|
||||||
|
Drawable returnValue=null;
|
||||||
ITileSource tileSource = mTileSource.get();
|
ITileSource tileSource = mTileSource.get();
|
||||||
if (tileSource == null) {
|
if (tileSource == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -225,7 +229,7 @@ public class MapTileFileArchiveProvider extends MapTileFileStorageProviderBase {
|
||||||
Log.d(IMapView.LOGTAG,"Use tile from archive: " + pTile);
|
Log.d(IMapView.LOGTAG,"Use tile from archive: " + pTile);
|
||||||
}
|
}
|
||||||
final Drawable drawable = tileSource.getDrawable(inputStream);
|
final Drawable drawable = tileSource.getDrawable(inputStream);
|
||||||
return drawable;
|
returnValue = drawable;
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
Log.e(IMapView.LOGTAG,"Error loading tile", 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
|
* 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 A. S. Budden
|
||||||
* @author Erik Burrows
|
* @author Erik Burrows
|
||||||
*
|
*
|
||||||
|
@ -575,7 +578,9 @@ public class GEMFFile {
|
||||||
|
|
||||||
long dataOffset;
|
long dataOffset;
|
||||||
int dataLength;
|
int dataLength;
|
||||||
|
InputStream returnValue=null;
|
||||||
|
GEMFInputStream stream=null;
|
||||||
|
ByteArrayOutputStream byteBuffer=null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Determine offset to requested tile record in the header
|
// Determine offset to requested tile record in the header
|
||||||
|
@ -612,11 +617,9 @@ public class GEMFFile {
|
||||||
// Read data block into a byte array
|
// Read data block into a byte array
|
||||||
pDataFile.seek(dataOffset);
|
pDataFile.seek(dataOffset);
|
||||||
|
|
||||||
|
stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
|
||||||
|
|
||||||
GEMFInputStream stream= new GEMFInputStream(mFileNames.get(index), dataOffset, dataLength);
|
|
||||||
// this dynamically extends to take the bytes you read
|
// 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
|
// this is storage overwritten on each iteration with bytes
|
||||||
int bufferSize = 1024;
|
int bufferSize = 1024;
|
||||||
|
@ -633,11 +636,26 @@ public class GEMFFile {
|
||||||
|
|
||||||
// and then we can return your byte array.
|
// and then we can return your byte array.
|
||||||
byte[] bits = byteBuffer.toByteArray();
|
byte[] bits = byteBuffer.toByteArray();
|
||||||
return new ByteArrayInputStream(bits);
|
returnValue= new ByteArrayInputStream(bits);
|
||||||
|
|
||||||
} catch (final java.io.IOException e) {
|
} 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