Map cache done. Testing...
This commit is contained in:
parent
844d25452b
commit
c013510f50
3 changed files with 24 additions and 6 deletions
|
@ -117,7 +117,7 @@ public class NativeLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean initMapFile(String filePath, boolean useLive) {
|
public boolean initMapFile(String filePath, boolean useLive) {
|
||||||
return initBinaryMapFile(filePath, useLive);
|
return initBinaryMapFile(filePath, useLive, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean initCacheMapFile(String filePath) {
|
public boolean initCacheMapFile(String filePath) {
|
||||||
|
@ -160,7 +160,7 @@ public class NativeLibrary {
|
||||||
|
|
||||||
protected static native void deleteSearchResult(long searchResultHandle);
|
protected static native void deleteSearchResult(long searchResultHandle);
|
||||||
|
|
||||||
protected static native boolean initBinaryMapFile(String filePath, boolean useLive);
|
protected static native boolean initBinaryMapFile(String filePath, boolean useLive, boolean routingOnly);
|
||||||
|
|
||||||
protected static native boolean initCacheMapFiles(String filePath);
|
protected static native boolean initCacheMapFiles(String filePath);
|
||||||
|
|
||||||
|
|
|
@ -75,14 +75,23 @@ public class SampleApplication extends Application {
|
||||||
resourceManager = new ResourceManager(this);
|
resourceManager = new ResourceManager(this);
|
||||||
regions = new OsmandRegions();
|
regions = new OsmandRegions();
|
||||||
updateRegionVars();
|
updateRegionVars();
|
||||||
indexRegionsBoundaries();
|
|
||||||
|
|
||||||
uiHandler = new Handler();
|
uiHandler = new Handler();
|
||||||
|
|
||||||
poiTypes = MapPoiTypes.getDefaultNoInit();
|
poiTypes = MapPoiTypes.getDefaultNoInit();
|
||||||
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
== PackageManager.PERMISSION_GRANTED) {
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
initPoiTypes();
|
new Thread(new Runnable() { //$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
indexRegionsBoundaries();
|
||||||
|
initPoiTypes();
|
||||||
|
} finally {
|
||||||
|
//applicationBgInitializing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "Initializing app").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize native core
|
// Initialize native core
|
||||||
|
|
|
@ -4,6 +4,7 @@ package net.osmand.core.samples.android.sample1.resources;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
|
import net.osmand.binary.CachedOsmandIndexes;
|
||||||
import net.osmand.core.samples.android.sample1.SampleApplication;
|
import net.osmand.core.samples.android.sample1.SampleApplication;
|
||||||
import net.osmand.core.samples.android.sample1.SampleUtils;
|
import net.osmand.core.samples.android.sample1.SampleUtils;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
@ -33,10 +34,18 @@ public class ResourceManager {
|
||||||
SampleUtils.collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
SampleUtils.collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
SampleUtils.collectFiles(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
SampleUtils.collectFiles(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
|
|
||||||
|
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
|
||||||
|
File indCache = app.getAppPath("ind_core.cache");
|
||||||
|
if (indCache.exists()) {
|
||||||
|
try {
|
||||||
|
cachedOsmandIndexes.readFromFile(indCache, CachedOsmandIndexes.VERSION);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
try {
|
try {
|
||||||
RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r");
|
BinaryMapIndexReader reader = cachedOsmandIndexes.getReader(f);
|
||||||
BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f);
|
|
||||||
if (reader.containsPoiData()) {
|
if (reader.containsPoiData()) {
|
||||||
amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(reader));
|
amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(reader));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue