use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class SettingsHelper method getResourcesItems.
private Map<ExportSettingsType, List<?>> getResourcesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
Map<ExportSettingsType, List<?>> resourcesItems = new LinkedHashMap<>();
Map<String, File> externalRenderers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.CUSTOM_RENDER_STYLE) ? app.getRendererRegistry().getExternalRenderers() : Collections.emptyMap();
if (!externalRenderers.isEmpty() || addEmptyItems) {
resourcesItems.put(ExportSettingsType.CUSTOM_RENDER_STYLE, new ArrayList<>(externalRenderers.values()));
}
List<File> routingProfiles = new ArrayList<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.CUSTOM_ROUTING)) {
File routingProfilesFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
if (routingProfilesFolder.exists() && routingProfilesFolder.isDirectory()) {
File[] fl = routingProfilesFolder.listFiles();
if (fl != null && fl.length > 0) {
routingProfiles.addAll(Arrays.asList(fl));
}
}
}
if (!Algorithms.isEmpty(routingProfiles) || addEmptyItems) {
resourcesItems.put(ExportSettingsType.CUSTOM_ROUTING, routingProfiles);
}
List<OnlineRoutingEngine> onlineRoutingEngines = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ONLINE_ROUTING_ENGINES) ? app.getOnlineRoutingHelper().getOnlyCustomEngines() : Collections.emptyList();
if (!Algorithms.isEmpty(onlineRoutingEngines) || addEmptyItems) {
resourcesItems.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines);
}
List<ITileSource> iTileSources = new ArrayList<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MAP_SOURCES)) {
Set<String> tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet();
for (String name : tileSourceNames) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + name);
if (f != null) {
ITileSource template;
if (f.getName().endsWith(SQLiteTileSource.EXT)) {
template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
} else {
template = TileSourceManager.createTileSourceTemplate(f);
}
if (template.getUrlTemplate() != null) {
iTileSources.add(template);
}
}
}
}
if (!iTileSources.isEmpty() || addEmptyItems) {
resourcesItems.put(ExportSettingsType.MAP_SOURCES, iTileSources);
}
List<LocalIndexInfo> localIndexInfoList;
List<LocalIndexType> dataTypes = new ArrayList<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.OFFLINE_MAPS)) {
dataTypes.add(LocalIndexType.MAP_DATA);
dataTypes.add(LocalIndexType.TILES_DATA);
dataTypes.add(LocalIndexType.SRTM_DATA);
dataTypes.add(LocalIndexType.WIKI_DATA);
}
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.TTS_VOICE)) {
dataTypes.add(LocalIndexType.TTS_VOICE_DATA);
}
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.VOICE)) {
dataTypes.add(LocalIndexType.VOICE_DATA);
}
localIndexInfoList = !dataTypes.isEmpty() ? getLocalIndexData(dataTypes.toArray(new LocalIndexType[0])) : Collections.emptyList();
List<File> files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA, LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA);
if (!files.isEmpty() || addEmptyItems) {
sortLocalFiles(files);
resourcesItems.put(ExportSettingsType.OFFLINE_MAPS, files);
}
files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
if (!files.isEmpty() || addEmptyItems) {
resourcesItems.put(ExportSettingsType.TTS_VOICE, files);
}
files = getFilesByType(localIndexInfoList, LocalIndexType.VOICE_DATA);
if (!files.isEmpty() || addEmptyItems) {
resourcesItems.put(ExportSettingsType.VOICE, files);
}
return resourcesItems;
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class SettingsHelper method prepareSettingsItems.
public List<SettingsItem> prepareSettingsItems(List<?> data, List<SettingsItem> settingsItems, boolean export) {
List<SettingsItem> result = new ArrayList<>();
List<QuickAction> quickActions = new ArrayList<>();
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
List<ITileSource> tileSourceTemplates = new ArrayList<>();
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
List<ApplicationModeBean> appModeBeans = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
List<HistoryEntry> historyEntries = new ArrayList<>();
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
List<MapMarkersGroup> itineraryGroups = new ArrayList<>();
for (Object object : data) {
if (object instanceof QuickAction) {
quickActions.add((QuickAction) object);
} else if (object instanceof PoiUIFilter) {
poiUIFilters.add((PoiUIFilter) object);
} else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
tileSourceTemplates.add((ITileSource) object);
} else if (object instanceof File) {
try {
File file = (File) object;
if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) {
result.add(new GpxSettingsItem(app, file));
} else {
result.add(new FileSettingsItem(app, file));
}
} catch (IllegalArgumentException e) {
LOG.warn("Trying to export unsuported file type", e);
}
} else if (object instanceof FileSettingsItem) {
result.add((FileSettingsItem) object);
} else if (object instanceof AvoidRoadInfo) {
avoidRoads.add((AvoidRoadInfo) object);
} else if (object instanceof ApplicationModeBean) {
appModeBeans.add((ApplicationModeBean) object);
} else if (object instanceof OsmNotesPoint) {
osmNotesPointList.add((OsmNotesPoint) object);
} else if (object instanceof OpenstreetmapPoint) {
osmEditsPointList.add((OpenstreetmapPoint) object);
} else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object);
} else if (object instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
markersGroups.add((MapMarkersGroup) object);
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
markersHistoryGroups.add((MapMarkersGroup) object);
} else {
itineraryGroups.add((MapMarkersGroup) object);
}
} else if (object instanceof HistoryEntry) {
historyEntries.add((HistoryEntry) object);
} else if (object instanceof GlobalSettingsItem) {
result.add((GlobalSettingsItem) object);
} else if (object instanceof OnlineRoutingEngine) {
onlineRoutingEngines.add((OnlineRoutingEngine) object);
}
}
if (!quickActions.isEmpty()) {
QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems);
result.add(new QuickActionsSettingsItem(app, baseItem, quickActions));
}
if (!poiUIFilters.isEmpty()) {
PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems);
result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters));
}
if (!tileSourceTemplates.isEmpty()) {
MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems);
result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates));
}
if (!avoidRoads.isEmpty()) {
AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems);
result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads));
}
if (!appModeBeans.isEmpty()) {
for (ApplicationModeBean modeBean : appModeBeans) {
if (export) {
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (mode != null) {
result.add(new ProfileSettingsItem(app, mode));
}
} else {
result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean));
}
}
}
if (!osmNotesPointList.isEmpty()) {
OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems);
result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList));
}
if (!osmEditsPointList.isEmpty()) {
OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems);
result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList));
}
if (!favoriteGroups.isEmpty()) {
FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems);
result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
}
if (!markersGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : markersGroups) {
mapMarkers.addAll(group.getMarkers());
}
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
result.add(new MarkersSettingsItem(app, baseItem, mapMarkers));
}
if (!markersHistoryGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : markersHistoryGroups) {
mapMarkers.addAll(group.getMarkers());
}
HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers));
}
if (!historyEntries.isEmpty()) {
SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems);
result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries));
}
if (!onlineRoutingEngines.isEmpty()) {
OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems);
result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines));
}
if (!itineraryGroups.isEmpty()) {
ItinerarySettingsItem baseItem = getBaseItem(SettingsItemType.ITINERARY_GROUPS, ItinerarySettingsItem.class, settingsItems);
result.add(new ItinerarySettingsItem(app, baseItem, itineraryGroups));
}
return result;
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class MapSourcesSettingsItem method renameItem.
@NonNull
@Override
public ITileSource renameItem(@NonNull ITileSource item) {
int number = 0;
while (true) {
number++;
if (item instanceof SQLiteTileSource) {
SQLiteTileSource oldItem = (SQLiteTileSource) item;
SQLiteTileSource renamedItem = new SQLiteTileSource(oldItem, oldItem.getName() + "_" + number, app);
if (!isDuplicate(renamedItem)) {
return renamedItem;
}
} else if (item instanceof TileSourceManager.TileSourceTemplate) {
TileSourceManager.TileSourceTemplate oldItem = (TileSourceManager.TileSourceTemplate) item;
oldItem.setName(oldItem.getName() + "_" + number);
if (!isDuplicate(oldItem)) {
return oldItem;
}
}
}
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class MapSourcesSettingsItem method readItemsFromJson.
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
try {
if (!json.has("items")) {
return;
}
JSONArray jsonArray = json.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
boolean sql = object.optBoolean("sql");
String name = object.optString("name");
int minZoom = object.optInt("minZoom");
int maxZoom = object.optInt("maxZoom");
String url = object.optString("url");
String randoms = object.optString("randoms");
boolean ellipsoid = object.optBoolean("ellipsoid", false);
boolean invertedY = object.optBoolean("inverted_y", false);
String referer = object.optString("referer");
String userAgent = object.optString("userAgent");
boolean timeSupported = object.optBoolean("timesupported", false);
long expire = object.optLong("expire", -1);
boolean inversiveZoom = object.optBoolean("inversiveZoom", false);
String ext = object.optString("ext");
int tileSize = object.optInt("tileSize");
int bitDensity = object.optInt("bitDensity");
int avgSize = object.optInt("avgSize");
String rule = object.optString("rule");
if (expire > 0 && expire < 3600000) {
expire = expire * 60 * 1000L;
}
ITileSource template;
if (!sql) {
TileSourceManager.TileSourceTemplate tileSourceTemplate = new TileSourceManager.TileSourceTemplate(name, url, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize);
tileSourceTemplate.setRule(rule);
tileSourceTemplate.setRandoms(randoms);
tileSourceTemplate.setReferer(referer);
tileSourceTemplate.setUserAgent(userAgent);
tileSourceTemplate.setEllipticYTile(ellipsoid);
tileSourceTemplate.setInvertedYTile(invertedY);
tileSourceTemplate.setExpirationTimeMillis(timeSupported ? expire : -1);
template = tileSourceTemplate;
} else {
template = new SQLiteTileSource(app, name, minZoom, maxZoom, url, randoms, ellipsoid, invertedY, referer, userAgent, timeSupported, expire, inversiveZoom, rule);
}
items.add(template);
}
} catch (JSONException e) {
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
throw new IllegalArgumentException("Json parse error", e);
}
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class OsmandSettings method getTileSourceByName.
@Nullable
public ITileSource getTileSourceByName(String tileName, boolean warnWhenSelected) {
if (tileName == null || tileName.length() == 0) {
return null;
}
List<TileSourceTemplate> knownTemplates = TileSourceManager.getKnownSourceTemplates();
File tPath = ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileName);
if (!dir.exists()) {
return checkAmongAvailableTileSources(dir, knownTemplates);
} else if (tileName.endsWith(IndexConstants.SQLITE_EXT)) {
return new SQLiteTileSource(ctx, dir, knownTemplates);
} else if (dir.isDirectory() && !dir.getName().startsWith(".")) {
TileSourceTemplate t = TileSourceManager.createTileSourceTemplate(dir);
if (warnWhenSelected && !t.isRuleAcceptable()) {
ctx.showToastMessage(R.string.warning_tile_layer_not_downloadable, dir.getName());
}
if (!TileSourceManager.isTileSourceMetaInfoExist(dir)) {
TileSourceTemplate ret = checkAmongAvailableTileSources(dir, knownTemplates);
if (ret != null) {
t = ret;
}
}
return t;
}
return null;
}
Aggregations