From c013510f50fd5c3623b1eb4a8a2f70d8df68a39b Mon Sep 17 00:00:00 2001 From: crimean Date: Thu, 27 Sep 2018 22:33:30 +0300 Subject: [PATCH] Map cache done. Testing... --- .../src/main/java/net/osmand/NativeLibrary.java | 4 ++-- .../samples/android/sample1/SampleApplication.java | 13 +++++++++++-- .../android/sample1/resources/ResourceManager.java | 13 +++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java b/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java index bce63b5cee..3eaebd56e5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java +++ b/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java @@ -117,7 +117,7 @@ public class NativeLibrary { } public boolean initMapFile(String filePath, boolean useLive) { - return initBinaryMapFile(filePath, useLive); + return initBinaryMapFile(filePath, useLive, false); } public boolean initCacheMapFile(String filePath) { @@ -160,7 +160,7 @@ public class NativeLibrary { 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); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleApplication.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleApplication.java index 08c2e9246a..4bffc6c5a3 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleApplication.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleApplication.java @@ -75,14 +75,23 @@ public class SampleApplication extends Application { resourceManager = new ResourceManager(this); regions = new OsmandRegions(); updateRegionVars(); - indexRegionsBoundaries(); uiHandler = new Handler(); poiTypes = MapPoiTypes.getDefaultNoInit(); if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == 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 diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/resources/ResourceManager.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/resources/ResourceManager.java index 5ef96b3dad..d06db10c35 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/resources/ResourceManager.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/resources/ResourceManager.java @@ -4,6 +4,7 @@ package net.osmand.core.samples.android.sample1.resources; import net.osmand.IndexConstants; import net.osmand.ResultMatcher; 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.SampleUtils; import net.osmand.data.Amenity; @@ -33,10 +34,18 @@ public class ResourceManager { SampleUtils.collectFiles(appPath, 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) { try { - RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r"); - BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f); + BinaryMapIndexReader reader = cachedOsmandIndexes.getReader(f); if (reader.containsPoiData()) { amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(reader)); }