travel obf resource manager reader added
This commit is contained in:
parent
c949f98329
commit
16ae7b28c1
2 changed files with 132 additions and 112 deletions
|
@ -19,8 +19,10 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryIndexPart;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||
import net.osmand.binary.BinaryMapPoiReaderAdapter;
|
||||
import net.osmand.binary.CachedOsmandIndexes;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
|
@ -75,15 +77,14 @@ import java.util.Map.Entry;
|
|||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
|
||||
|
||||
/**
|
||||
* Resource manager is responsible to work with all resources
|
||||
* Resource manager is responsible to work with all resources
|
||||
* that could consume memory (especially with file resources).
|
||||
* Such as indexes, tiles.
|
||||
* Also it is responsible to create cache for that resources if they
|
||||
* can't be loaded fully into memory & clear them on request.
|
||||
* can't be loaded fully into memory & clear them on request.
|
||||
*/
|
||||
public class ResourceManager {
|
||||
|
||||
|
@ -91,10 +92,10 @@ public class ResourceManager {
|
|||
private static final String INDEXES_CACHE = "ind.cache";
|
||||
|
||||
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
|
||||
|
||||
|
||||
protected static ResourceManager manager = null;
|
||||
|
||||
protected File dirWithTiles ;
|
||||
protected File dirWithTiles;
|
||||
|
||||
private List<TilesCache> tilesCacheList = new ArrayList<>();
|
||||
private BitmapTilesCache bitmapTilesCache;
|
||||
|
@ -115,21 +116,22 @@ public class ResourceManager {
|
|||
STREET_LOOKUP,
|
||||
TRANSPORT,
|
||||
ADDRESS,
|
||||
QUICK_SEARCH,
|
||||
QUICK_SEARCH,
|
||||
ROUTING,
|
||||
TRANSPORT_ROUTING
|
||||
}
|
||||
|
||||
|
||||
public static class BinaryMapReaderResource {
|
||||
private BinaryMapIndexReader initialReader;
|
||||
private File filename;
|
||||
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
|
||||
private boolean useForRouting;
|
||||
private boolean useForPublicTransport;
|
||||
|
||||
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
|
||||
this.filename = f;
|
||||
this.initialReader = initialReader;
|
||||
while(readers.size() < BinaryMapReaderResourceType.values().length) {
|
||||
while (readers.size() < BinaryMapReaderResourceType.values().length) {
|
||||
readers.add(null);
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +175,7 @@ public class ResourceManager {
|
|||
}
|
||||
initialReader = null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isClosed() {
|
||||
return initialReader == null;
|
||||
}
|
||||
|
@ -189,7 +191,7 @@ public class ResourceManager {
|
|||
public void setUseForRouting(boolean useForRouting) {
|
||||
this.useForRouting = useForRouting;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUseForRouting() {
|
||||
return useForRouting;
|
||||
}
|
||||
|
@ -202,34 +204,34 @@ public class ResourceManager {
|
|||
this.useForPublicTransport = useForPublicTransport;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
||||
|
||||
|
||||
|
||||
|
||||
private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>();
|
||||
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
|
||||
// protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>();
|
||||
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
|
||||
// protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>();
|
||||
protected final Map<String, BinaryMapReaderResource> transportRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
||||
|
||||
|
||||
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
|
||||
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
|
||||
|
||||
|
||||
|
||||
|
||||
protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this);
|
||||
|
||||
|
||||
protected final MapRenderRepositories renderer;
|
||||
|
||||
protected final MapTileDownloader tileDownloader;
|
||||
|
||||
|
||||
public final AsyncLoadingThread asyncLoadingThread = new AsyncLoadingThread(this);
|
||||
|
||||
|
||||
private HandlerThread renderingBufferImageThread;
|
||||
|
||||
|
||||
protected boolean internetIsNotAccessible = false;
|
||||
private boolean depthContours;
|
||||
|
||||
|
||||
public ResourceManager(OsmandApplication context) {
|
||||
|
||||
|
||||
this.context = context;
|
||||
this.renderer = new MapRenderRepositories(context);
|
||||
|
||||
|
@ -271,7 +273,7 @@ public class ResourceManager {
|
|||
public MapTileDownloader getMapTileDownloader() {
|
||||
return tileDownloader;
|
||||
}
|
||||
|
||||
|
||||
public HandlerThread getRenderingBufferImageThread() {
|
||||
return renderingBufferImageThread;
|
||||
}
|
||||
|
@ -293,17 +295,17 @@ public class ResourceManager {
|
|||
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery app
|
||||
try {
|
||||
context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$
|
||||
} catch( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
for (TilesCache tilesCache : tilesCacheList) {
|
||||
tilesCache.setDirWithTiles(dirWithTiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public java.text.DateFormat getDateFormat() {
|
||||
return DateFormat.getDateFormat(context);
|
||||
}
|
||||
|
||||
|
||||
public OsmandApplication getContext() {
|
||||
return context;
|
||||
}
|
||||
|
@ -323,7 +325,7 @@ public class ResourceManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public synchronized void tileDownloaded(DownloadRequest request){
|
||||
public synchronized void tileDownloaded(DownloadRequest request) {
|
||||
if (request instanceof TileLoadDownloadRequest) {
|
||||
TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
|
||||
TilesCache cache = getTilesCache(req.tileSource);
|
||||
|
@ -332,13 +334,13 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean tileExistOnFileSystem(String file, ITileSource map, int x, int y, int zoom) {
|
||||
TilesCache cache = getTilesCache(map);
|
||||
return cache != null && cache.tileExistOnFileSystem(file, map, x, y, zoom);
|
||||
}
|
||||
|
||||
public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom){
|
||||
|
||||
public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom) {
|
||||
TilesCache cache = getTilesCache(map);
|
||||
if (cache != null) {
|
||||
cache.getTileForMap(file, map, x, y, zoom, true, false, true, true);
|
||||
|
@ -376,7 +378,7 @@ public class ResourceManager {
|
|||
|
||||
////////////////////////////////////////////// Working with indexes ////////////////////////////////////////////////
|
||||
|
||||
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings){
|
||||
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings) {
|
||||
close();
|
||||
// check we have some assets to copy to sdcard
|
||||
warnings.addAll(checkAssets(progress, false));
|
||||
|
@ -429,7 +431,7 @@ public class ResourceManager {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
public List<String> indexFontFiles(IProgress progress){
|
||||
public List<String> indexFontFiles(IProgress progress) {
|
||||
File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR);
|
||||
file.mkdirs();
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
|
@ -473,10 +475,10 @@ public class ResourceManager {
|
|||
log.error("Error while loading tts files from assets", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
|
||||
String fv = Version.getFullVersion(context);
|
||||
if(context.getAppInitializer().isAppVersionChanged()) {
|
||||
if (context.getAppInitializer().isAppVersionChanged()) {
|
||||
copyMissingJSAssets();
|
||||
}
|
||||
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) {
|
||||
|
@ -509,7 +511,7 @@ public class ResourceManager {
|
|||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
private void copyRegionsBoundaries() {
|
||||
try {
|
||||
File file = context.getAppPath("regions.ocbf");
|
||||
|
@ -522,7 +524,7 @@ public class ResourceManager {
|
|||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void copyPoiTypes() {
|
||||
try {
|
||||
File file = context.getAppPath(IndexConstants.SETTINGS_DIR + "poi_types.xml");
|
||||
|
@ -540,6 +542,7 @@ public class ResourceManager {
|
|||
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";
|
||||
private final static String ASSET_COPY_MODE__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy";
|
||||
private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
|
||||
|
||||
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
|
||||
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
|
||||
for (AssetEntry asset : assetEntries) {
|
||||
|
@ -581,7 +584,7 @@ public class ResourceManager {
|
|||
}
|
||||
|
||||
public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException {
|
||||
if(file.exists()){
|
||||
if (file.exists()) {
|
||||
Algorithms.removeAllFiles(file);
|
||||
}
|
||||
file.getParentFile().mkdirs();
|
||||
|
@ -593,9 +596,9 @@ public class ResourceManager {
|
|||
}
|
||||
|
||||
private List<File> collectFiles(File dir, String ext, List<File> files) {
|
||||
if(dir.exists() && dir.canRead()) {
|
||||
if (dir.exists() && dir.canRead()) {
|
||||
File[] lf = dir.listFiles();
|
||||
if(lf == null || lf.length == 0) {
|
||||
if (lf == null || lf.length == 0) {
|
||||
return files;
|
||||
}
|
||||
for (File f : lf) {
|
||||
|
@ -606,12 +609,11 @@ public class ResourceManager {
|
|||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
|
||||
Iterator<File> it = files.iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
File f = it.next();
|
||||
if (f.getName().endsWith("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
f.renameTo(new File(roadsPath, f.getName().replace("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT,
|
||||
|
@ -628,17 +630,18 @@ public class ResourceManager {
|
|||
File appPath = context.getAppPath(null);
|
||||
File roadsPath = context.getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
||||
roadsPath.mkdirs();
|
||||
|
||||
|
||||
collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
renameRoadsFiles(files, roadsPath);
|
||||
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
if (Version.isPaidVersion(context)) {
|
||||
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
}
|
||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
|
||||
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
}
|
||||
|
||||
|
||||
changesManager.collectChangesFiles(context.getAppPath(IndexConstants.LIVE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
|
||||
Collections.sort(files, Algorithms.getFileVersionComparator());
|
||||
|
@ -707,9 +710,9 @@ public class ResourceManager {
|
|||
if (dateCreated == 0) {
|
||||
dateCreated = f.lastModified();
|
||||
}
|
||||
if(f.getParentFile().getName().equals(liveDir.getName())) {
|
||||
if (f.getParentFile().getName().equals(liveDir.getName())) {
|
||||
boolean toUse = changesManager.index(f, dateCreated, mapReader);
|
||||
if(!toUse) {
|
||||
if (!toUse) {
|
||||
try {
|
||||
mapReader.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -717,7 +720,7 @@ public class ResourceManager {
|
|||
}
|
||||
continue;
|
||||
}
|
||||
} else if(!wikiMap && !srtmMap) {
|
||||
} else if (!wikiMap && !srtmMap) {
|
||||
changesManager.indexMainMap(f, dateCreated);
|
||||
}
|
||||
indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$
|
||||
|
@ -726,7 +729,7 @@ public class ResourceManager {
|
|||
}
|
||||
renderer.initializeNewResource(progress, f, mapReader);
|
||||
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
|
||||
|
||||
|
||||
fileReaders.put(f.getName(), resource);
|
||||
if (!mapReader.getRegionNames().isEmpty()) {
|
||||
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource);
|
||||
|
@ -736,7 +739,7 @@ public class ResourceManager {
|
|||
transportRepositories.put(f.getName(), resource);
|
||||
}
|
||||
// disable osmc for routing temporarily due to some bugs
|
||||
if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) ||
|
||||
if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) ||
|
||||
context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) {
|
||||
resource.setUseForRouting(true);
|
||||
}
|
||||
|
@ -779,7 +782,7 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
Entry<PoiCategory, Map<String, PoiType>> next = it.next();
|
||||
PoiCategory category = next.getKey();
|
||||
category.addExtraPoiTypes(next.getValue());
|
||||
|
@ -798,7 +801,6 @@ public class ResourceManager {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void initMapBoundariesCacheNative() {
|
||||
File indCache = context.getAppPath(INDEXES_CACHE);
|
||||
|
@ -809,7 +811,7 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||
|
||||
public List<AmenityIndexRepository> getAmenityRepositories() {
|
||||
|
@ -826,7 +828,7 @@ public class ResourceManager {
|
|||
}
|
||||
|
||||
public List<Amenity> searchAmenities(SearchPoiTypeFilter filter,
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||
final List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
searchAmenitiesInProgress = true;
|
||||
try {
|
||||
|
@ -855,8 +857,8 @@ public class ResourceManager {
|
|||
return amenities;
|
||||
}
|
||||
|
||||
public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter,
|
||||
ResultMatcher<Amenity> matcher) {
|
||||
public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter,
|
||||
ResultMatcher<Amenity> matcher) {
|
||||
searchAmenitiesInProgress = true;
|
||||
final List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
try {
|
||||
|
@ -875,9 +877,9 @@ public class ResourceManager {
|
|||
if (!filter.isEmpty()) {
|
||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||
if (index.checkContainsInt(
|
||||
MapUtils.get31TileNumberY(topLatitude),
|
||||
MapUtils.get31TileNumberX(leftLongitude),
|
||||
MapUtils.get31TileNumberY(bottomLatitude),
|
||||
MapUtils.get31TileNumberY(topLatitude),
|
||||
MapUtils.get31TileNumberX(leftLongitude),
|
||||
MapUtils.get31TileNumberY(bottomLatitude),
|
||||
MapUtils.get31TileNumberX(rightLongitude))) {
|
||||
repos.add(index);
|
||||
}
|
||||
|
@ -885,7 +887,7 @@ public class ResourceManager {
|
|||
if (!repos.isEmpty()) {
|
||||
for (AmenityIndexRepository r : repos) {
|
||||
List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
|
||||
if(res != null) {
|
||||
if (res != null) {
|
||||
amenities.addAll(res);
|
||||
}
|
||||
}
|
||||
|
@ -897,12 +899,12 @@ public class ResourceManager {
|
|||
}
|
||||
return amenities;
|
||||
}
|
||||
|
||||
|
||||
public boolean containsAmenityRepositoryToSearch(boolean searchByName){
|
||||
|
||||
|
||||
public boolean containsAmenityRepositoryToSearch(boolean searchByName) {
|
||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||
if(searchByName){
|
||||
if(index instanceof AmenityIndexRepositoryBinary){
|
||||
if (searchByName) {
|
||||
if (index instanceof AmenityIndexRepositoryBinary) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
@ -911,10 +913,10 @@ public class ResourceManager {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public List<Amenity> searchAmenitiesByName(String searchQuery,
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||
double lat, double lon, ResultMatcher<Amenity> matcher) {
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||
double lat, double lon, ResultMatcher<Amenity> matcher) {
|
||||
List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>();
|
||||
int left = MapUtils.get31TileNumberX(leftLongitude);
|
||||
|
@ -927,16 +929,16 @@ public class ResourceManager {
|
|||
}
|
||||
if (index instanceof AmenityIndexRepositoryBinary) {
|
||||
if (index.checkContainsInt(top, left, bottom, right)) {
|
||||
if(index.checkContains(lat, lon)){
|
||||
if (index.checkContains(lat, lon)) {
|
||||
list.add(0, (AmenityIndexRepositoryBinary) index);
|
||||
} else {
|
||||
list.add((AmenityIndexRepositoryBinary) index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Not using boundares results in very slow initial search if user has many maps installed
|
||||
// int left = 0;
|
||||
// int top = 0;
|
||||
|
@ -954,7 +956,7 @@ public class ResourceManager {
|
|||
|
||||
return amenities;
|
||||
}
|
||||
|
||||
|
||||
public Map<PoiCategory, List<String>> searchAmenityCategoriesByName(String searchQuery, double lat, double lon) {
|
||||
Map<PoiCategory, List<String>> map = new LinkedHashMap<PoiCategory, List<String>>();
|
||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||
|
@ -970,17 +972,17 @@ public class ResourceManager {
|
|||
public AmenityIndexRepositoryBinary getAmenityRepositoryByFileName(String filename) {
|
||||
return (AmenityIndexRepositoryBinary) amenityRepositories.get(filename);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////// Working with address ///////////////////////////////////////////
|
||||
|
||||
public RegionAddressRepository getRegionRepository(String name){
|
||||
|
||||
public RegionAddressRepository getRegionRepository(String name) {
|
||||
return addressMap.get(name);
|
||||
}
|
||||
|
||||
public Collection<RegionAddressRepository> getAddressRepositories(){
|
||||
|
||||
public Collection<RegionAddressRepository> getAddressRepositories() {
|
||||
return addressMap.values();
|
||||
}
|
||||
|
||||
|
||||
public Collection<BinaryMapReaderResource> getFileReaders() {
|
||||
List<String> fileNames = new ArrayList<>(fileReaders.keySet());
|
||||
Collections.sort(fileNames, Algorithms.getStringVersionComparator());
|
||||
|
@ -993,8 +995,8 @@ public class ResourceManager {
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////// Working with transport ////////////////////////////////////////////////
|
||||
|
||||
private List<BinaryMapIndexReader> getTransportRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
|
||||
|
@ -1013,7 +1015,7 @@ public class ResourceManager {
|
|||
|
||||
|
||||
public List<TransportStop> searchTransportSync(double topLat, double leftLon, double bottomLat, double rightLon,
|
||||
ResultMatcher<TransportStop> matcher) throws IOException {
|
||||
ResultMatcher<TransportStop> matcher) throws IOException {
|
||||
TransportStopsRouteReader readers =
|
||||
new TransportStopsRouteReader(getTransportRepositories(topLat, leftLon, bottomLat, rightLon));
|
||||
List<TransportStop> stops = new ArrayList<>();
|
||||
|
@ -1030,7 +1032,7 @@ public class ResourceManager {
|
|||
|
||||
public List<TransportRoute> getRoutesForStop(TransportStop stop) {
|
||||
List<TransportRoute> rts = stop.getRoutes();
|
||||
if(rts != null) {
|
||||
if (rts != null) {
|
||||
return rts;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
@ -1040,26 +1042,26 @@ public class ResourceManager {
|
|||
public boolean updateRenderedMapNeeded(RotatedTileBox rotatedTileBox, DrawSettings drawSettings) {
|
||||
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
|
||||
}
|
||||
|
||||
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){
|
||||
|
||||
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener) {
|
||||
renderer.interruptLoadingMap();
|
||||
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
|
||||
}
|
||||
|
||||
public void interruptRendering(){
|
||||
|
||||
public void interruptRendering() {
|
||||
renderer.interruptLoadingMap();
|
||||
}
|
||||
|
||||
|
||||
public boolean isSearchAmenitiesInProgress() {
|
||||
return searchAmenitiesInProgress;
|
||||
}
|
||||
|
||||
|
||||
public MapRenderRepositories getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////// Closing methods ////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void closeFile(String fileName) {
|
||||
amenityRepositories.remove(fileName);
|
||||
addressMap.remove(fileName);
|
||||
|
@ -1067,12 +1069,12 @@ public class ResourceManager {
|
|||
indexFileNames.remove(fileName);
|
||||
renderer.closeConnection(fileName);
|
||||
BinaryMapReaderResource resource = fileReaders.remove(fileName);
|
||||
if(resource != null) {
|
||||
if (resource != null) {
|
||||
resource.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void close(){
|
||||
public synchronized void close() {
|
||||
for (TilesCache tc : tilesCacheList) {
|
||||
tc.close();
|
||||
}
|
||||
|
@ -1082,13 +1084,13 @@ public class ResourceManager {
|
|||
transportRepositories.clear();
|
||||
addressMap.clear();
|
||||
amenityRepositories.clear();
|
||||
for(BinaryMapReaderResource res : fileReaders.values()) {
|
||||
for (BinaryMapReaderResource res : fileReaders.values()) {
|
||||
res.close();
|
||||
}
|
||||
fileReaders.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public BinaryMapIndexReader[] getRoutingMapFiles() {
|
||||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||
|
@ -1107,7 +1109,7 @@ public class ResourceManager {
|
|||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||
for (BinaryMapReaderResource r : fileReaders) {
|
||||
if (r.isUseForPublicTransport()) {
|
||||
if (r.isUseForPublicTransport()) {
|
||||
BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.TRANSPORT_ROUTING);
|
||||
if (reader != null) {
|
||||
readers.add(reader);
|
||||
|
@ -1132,12 +1134,29 @@ public class ResourceManager {
|
|||
return readers.toArray(new BinaryMapIndexReader[0]);
|
||||
}
|
||||
|
||||
public BinaryMapIndexReader[] getTravelFiles() {
|
||||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||
for (BinaryMapReaderResource res : fileReaders) {
|
||||
if (!res.filename.toString().toLowerCase().contains("wiki")) {
|
||||
continue;
|
||||
}
|
||||
BinaryMapIndexReader index = res.getReader(BinaryMapReaderResourceType.POI);
|
||||
for (BinaryIndexPart p : index.getIndexes()) {
|
||||
if (p instanceof BinaryMapPoiReaderAdapter.PoiRegion) {
|
||||
readers.add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return readers.toArray(new BinaryMapIndexReader[0]);
|
||||
}
|
||||
|
||||
public Map<String, String> getIndexFileNames() {
|
||||
return new LinkedHashMap<String, String>(indexFileNames);
|
||||
}
|
||||
|
||||
|
||||
public boolean containsBasemap(){
|
||||
|
||||
|
||||
public boolean containsBasemap() {
|
||||
return !basemapFileNames.isEmpty();
|
||||
}
|
||||
|
||||
|
@ -1171,13 +1190,13 @@ public class ResourceManager {
|
|||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void reloadTilesFromFS() {
|
||||
for (TilesCache tc : tilesCacheList) {
|
||||
tc.tilesOnFS.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// On low memory method ///
|
||||
public void onLowMemory() {
|
||||
log.info("On low memory");
|
||||
|
@ -1186,10 +1205,10 @@ public class ResourceManager {
|
|||
r.clearCache();
|
||||
}
|
||||
renderer.clearCache();
|
||||
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
public GeoidAltitudeCorrection getGeoidAltitudeCorrection() {
|
||||
return geoidAltitudeCorrection;
|
||||
}
|
||||
|
@ -1204,7 +1223,7 @@ public class ResourceManager {
|
|||
tc.clearTiles();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IncrementalChangesManager getChangesManager() {
|
||||
return changesManager;
|
||||
}
|
||||
|
|
|
@ -85,23 +85,23 @@ public class TravelObfHelper implements TravelHelper {
|
|||
* 2. check settings for default?
|
||||
*/
|
||||
public void initTravelBooks() {
|
||||
List<File> files = getPossibleFiles();
|
||||
BinaryMapIndexReader[] readers = application.getResourceManager().getTravelFiles();
|
||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
existingTravelBooks.clear();
|
||||
if (files != null && !files.isEmpty()) {
|
||||
for (File f : files) {
|
||||
if (readers != null) {
|
||||
for (BinaryMapIndexReader reader : readers) {
|
||||
File f = reader.getFile();
|
||||
existingTravelBooks.add(f);
|
||||
if (selectedTravelBook == null) {
|
||||
selectedTravelBook = f;
|
||||
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
|
||||
selectedTravelBook = f;
|
||||
}
|
||||
selectedTravelBook = reader.getFile();
|
||||
}
|
||||
selectedTravelBook = files.get(0);
|
||||
} else {
|
||||
selectedTravelBook = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,6 +147,7 @@ public class TravelObfHelper implements TravelHelper {
|
|||
@NonNull
|
||||
@Override
|
||||
public List<WikivoyageSearchResult> search(String searchQuery) {
|
||||
|
||||
List<WikivoyageSearchResult> res = new ArrayList<>();
|
||||
CollatorStringMatcher matcher = new CollatorStringMatcher(searchQuery,
|
||||
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
||||
|
|
Loading…
Reference in a new issue