use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class MapSourcesSettingsItem method writeItemsToJson.
@NonNull
@Override
JSONObject writeItemsToJson(@NonNull JSONObject json) {
JSONArray jsonArray = new JSONArray();
if (!items.isEmpty()) {
try {
for (ITileSource template : items) {
JSONObject jsonObject = new JSONObject();
boolean sql = template instanceof SQLiteTileSource;
jsonObject.put("sql", sql);
jsonObject.put("name", template.getName());
jsonObject.put("minZoom", template.getMinimumZoomSupported());
jsonObject.put("maxZoom", template.getMaximumZoomSupported());
jsonObject.put("url", template.getUrlTemplate());
jsonObject.put("randoms", template.getRandoms());
jsonObject.put("ellipsoid", template.isEllipticYTile());
jsonObject.put("inverted_y", template.isInvertedYTile());
jsonObject.put("referer", template.getReferer());
jsonObject.put("userAgent", template.getUserAgent());
jsonObject.put("timesupported", template.isTimeSupported());
jsonObject.put("expire", template.getExpirationTimeMinutes());
jsonObject.put("inversiveZoom", template.getInversiveZoom());
jsonObject.put("ext", template.getTileFormat());
jsonObject.put("tileSize", template.getTileSize());
jsonObject.put("bitDensity", template.getBitDensity());
jsonObject.put("avgSize", template.getAvgSize());
jsonObject.put("rule", template.getRule());
jsonArray.put(jsonObject);
}
json.put("items", jsonArray);
} catch (JSONException e) {
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed write to json", e);
}
}
return json;
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class ExportItemsBottomSheet method setupBottomSheetItem.
private void setupBottomSheetItem(BottomSheetItemWithCompoundButton item, Object object) {
if (object instanceof ApplicationModeBean) {
ApplicationModeBean modeBean = (ApplicationModeBean) object;
String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = Algorithms.capitalizeFirstLetter(modeBean.stringKey);
}
}
item.setTitle(profileName);
String routingProfile = "";
String routingProfileValue = modeBean.routingProfile;
if (!routingProfileValue.isEmpty()) {
try {
routingProfile = getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
} catch (IllegalArgumentException e) {
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
}
}
if (!Algorithms.isEmpty(routingProfile)) {
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.nav_type_hint), routingProfile));
} else {
item.setDescription(getString(R.string.profile_type_osmand_string));
}
int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
ProfileIconColors iconColor = modeBean.iconColor;
Integer customIconColor = modeBean.customIconColor;
int actualIconColor;
if (selectedItems.contains(object)) {
actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
} else {
actualIconColor = ContextCompat.getColor(app, secondaryColorRes);
}
int iconRes = profileIconRes != 0 ? profileIconRes : R.drawable.ic_world_globe_dark;
item.setIcon(uiUtilities.getPaintedIcon(iconRes, actualIconColor));
} else if (object instanceof QuickAction) {
QuickAction quickAction = (QuickAction) object;
item.setTitle(quickAction.getName(app));
item.setIcon(uiUtilities.getIcon(quickAction.getIconRes(), getItemIconColor(object)));
} else if (object instanceof PoiUIFilter) {
PoiUIFilter poiUIFilter = (PoiUIFilter) object;
item.setTitle(poiUIFilter.getName());
int iconRes = RenderingIcons.getBigIconResourceId(poiUIFilter.getIconId());
item.setIcon(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
} else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
ITileSource tileSource = (ITileSource) object;
item.setTitle(tileSource.getName());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_map, getItemIconColor(object)));
} else if (object instanceof File) {
setupBottomSheetItemForFile(item, (File) object);
} else if (object instanceof GpxSettingsItem) {
GpxSettingsItem settingsItem = (GpxSettingsItem) object;
setupBottomSheetItemForGpx(item, settingsItem.getFile(), settingsItem.getAppearanceInfo());
} else if (object instanceof FileSettingsItem) {
FileSettingsItem settingsItem = (FileSettingsItem) object;
setupBottomSheetItemForFile(item, settingsItem.getFile());
} else if (object instanceof AvoidRoadInfo) {
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) object;
item.setTitle(avoidRoadInfo.name);
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_alert, getItemIconColor(object)));
} else if (object instanceof OsmNotesPoint) {
OsmNotesPoint osmNotesPoint = (OsmNotesPoint) object;
item.setTitle(osmNotesPoint.getText());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_osm_note_add, getItemIconColor(object)));
} else if (object instanceof OpenstreetmapPoint) {
OpenstreetmapPoint openstreetmapPoint = (OpenstreetmapPoint) object;
item.setTitle(OsmEditingPlugin.getTitle(openstreetmapPoint, app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_info_dark, getItemIconColor(object)));
} else if (object instanceof FavoriteGroup) {
FavoriteGroup group = (FavoriteGroup) object;
item.setTitle(group.getDisplayName(app));
int color;
if (selectedItems.contains(object)) {
color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
} else {
color = ContextCompat.getColor(app, secondaryColorRes);
}
item.setIcon(uiUtilities.getPaintedIcon(R.drawable.ic_action_folder, color));
int points = group.getPoints().size();
String itemsDescr = getString(R.string.shared_string_gpx_points);
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, points));
} else if (object instanceof GlobalSettingsItem) {
GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
item.setTitle(globalSettingsItem.getPublicName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
} else if (object instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.map_markers));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.markers_history));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
} else {
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
if (markersGroup.getType() == ItineraryType.FAVOURITES) {
groupName = app.getString(R.string.shared_string_favorites);
} else if (markersGroup.getType() == ItineraryType.MARKERS) {
groupName = app.getString(R.string.map_markers);
}
}
item.setTitle(groupName);
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
}
int selectedMarkers = markersGroup.getMarkers().size();
String itemsDescr = getString(R.string.shared_string_items);
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers));
} else if (object instanceof HistoryEntry) {
HistoryEntry historyEntry = (HistoryEntry) object;
item.setTitle(historyEntry.getName().getName());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
} else if (object instanceof OnlineRoutingEngine) {
OnlineRoutingEngine onlineRoutingEngine = (OnlineRoutingEngine) object;
item.setTitle(onlineRoutingEngine.getName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_world_globe_dark, getItemIconColor(object)));
}
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class TerrainLayer method indexTerrainFiles.
private void indexTerrainFiles(final OsmandApplication app) {
@SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
private SQLiteDatabase sqliteDb;
private final String type = mode.name().toLowerCase();
@Override
protected Void doInBackground(Void... params) {
File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File cacheDir = app.getCacheDir();
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs
try {
sqliteDb = SQLiteDatabase.openDatabase(new File(cacheDir, mode == HILLSHADE ? HILLSHADE_CACHE : SLOPE_CACHE).getPath(), null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING | SQLiteDatabase.CREATE_IF_NECESSARY);
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
sqliteDb = null;
}
if (sqliteDb != null) {
try {
if (sqliteDb.getVersion() == 0) {
sqliteDb.setVersion(1);
}
sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)");
Map<String, Long> fileModified = new HashMap<>();
Map<String, SQLiteTileSource> rs = readFiles(app, tilesDir, fileModified);
indexCachedResources(fileModified, rs);
indexNonCachedResources(fileModified, rs);
sqliteDb.close();
resources = rs;
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
app.getResourceManager().reloadTilesFromFS();
}
private void indexNonCachedResources(Map<String, Long> fileModified, Map<String, SQLiteTileSource> rs) {
for (Map.Entry<String, Long> entry : fileModified.entrySet()) {
String filename = entry.getKey();
try {
log.info("Indexing " + type + " file " + filename);
ContentValues cv = new ContentValues();
cv.put("filename", filename);
cv.put("date_modified", entry.getValue());
SQLiteTileSource ts = rs.get(filename);
QuadRect rt = ts.getRectBoundary(ZOOM_BOUNDARY, 1);
if (rt != null) {
indexedResources.insert(filename, rt);
cv.put("left", (int) rt.left);
cv.put("right", (int) rt.right);
cv.put("top", (int) rt.top);
cv.put("bottom", (int) rt.bottom);
sqliteDb.insert("TILE_SOURCES", null, cv);
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
}
private void indexCachedResources(Map<String, Long> fileModified, Map<String, SQLiteTileSource> rs) {
Cursor cursor = sqliteDb.rawQuery("SELECT filename, date_modified, left, right, top, bottom FROM TILE_SOURCES", new String[0]);
if (cursor.moveToFirst()) {
do {
String filename = cursor.getString(0);
long lastModified = cursor.getLong(1);
Long read = fileModified.get(filename);
if (rs.containsKey(filename) && read != null && lastModified == read) {
int left = cursor.getInt(2);
int right = cursor.getInt(3);
int top = cursor.getInt(4);
float bottom = cursor.getInt(5);
indexedResources.insert(filename, new QuadRect(left, top, right, bottom));
fileModified.remove(filename);
}
} while (cursor.moveToNext());
}
cursor.close();
}
private Map<String, SQLiteTileSource> readFiles(final OsmandApplication app, File tilesDir, Map<String, Long> fileModified) {
Map<String, SQLiteTileSource> rs = new LinkedHashMap<>();
File[] files = tilesDir.listFiles();
if (files != null) {
for (File f : files) {
if (f != null && f.getName().endsWith(IndexConstants.SQLITE_EXT) && f.getName().toLowerCase().startsWith(type)) {
SQLiteTileSource ts = new SQLiteTileSource(app, f, new ArrayList<>());
rs.put(f.getName(), ts);
fileModified.put(f.getName(), f.lastModified());
}
}
}
return rs;
}
};
executeTaskInBackground(task);
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class LocalIndexHelper method updateDescription.
public void updateDescription(@NonNull LocalIndexInfo info) {
File f = new File(info.getPathToData());
if (info.getType() == LocalIndexType.MAP_DATA) {
Map<String, String> ifns = app.getResourceManager().getIndexFileNames();
if (ifns.containsKey(info.getFileName())) {
try {
Date dt = app.getResourceManager().getDateFormat().parse(ifns.get(info.getFileName()));
info.setDescription(getInstalledDate(dt.getTime(), null));
} catch (ParseException e) {
e.printStackTrace();
}
} else {
info.setDescription(getInstalledDate(f));
}
} else if (info.getType() == LocalIndexType.TILES_DATA) {
ITileSource template;
if (f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)) {
template = TileSourceManager.createTileSourceTemplate(new File(info.getPathToData()));
} else if (f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)) {
template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
} else {
return;
}
String descr = "";
if (template.getExpirationTimeMinutes() >= 0) {
descr += app.getString(R.string.local_index_tile_data_expire, String.valueOf(template.getExpirationTimeMinutes()));
}
info.setAttachedObject(template);
info.setDescription(descr);
} else if (info.getType() == LocalIndexType.SRTM_DATA) {
info.setDescription(app.getString(R.string.download_srtm_maps));
} else if (info.getType() == LocalIndexType.WIKI_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TRAVEL_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.DEACTIVATED) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.VOICE_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.FONT_DATA) {
info.setDescription(getInstalledDate(f));
}
}
use of net.osmand.plus.resources.SQLiteTileSource in project Osmand by osmandapp.
the class CustomOsmandPlugin method removePluginItemsFromFile.
private void removePluginItemsFromFile(final File file, final PluginItemsListener itemsListener) {
app.getFileSettingsHelper().collectSettings(file, "", 1, new CollectListener() {
@Override
public void onCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
if (succeed && !items.isEmpty()) {
for (SettingsItem item : items) {
if (item instanceof QuickActionsSettingsItem) {
QuickActionsSettingsItem quickActionsSettingsItem = (QuickActionsSettingsItem) item;
List<QuickAction> quickActions = quickActionsSettingsItem.getItems();
QuickActionRegistry actionRegistry = app.getQuickActionRegistry();
for (QuickAction action : quickActions) {
QuickAction savedAction = actionRegistry.getQuickAction(app, action.getType(), action.getName(app), action.getParams());
if (savedAction != null) {
actionRegistry.deleteQuickAction(savedAction);
}
}
} else if (item instanceof MapSourcesSettingsItem) {
MapSourcesSettingsItem mapSourcesSettingsItem = (MapSourcesSettingsItem) item;
List<ITileSource> mapSources = mapSourcesSettingsItem.getItems();
for (ITileSource tileSource : mapSources) {
String tileSourceName = tileSource.getName();
if (tileSource instanceof SQLiteTileSource) {
tileSourceName += SQLITE_EXT;
}
ITileSource savedTileSource = app.getSettings().getTileSourceByName(tileSourceName, false);
if (savedTileSource != null) {
if (savedTileSource instanceof SQLiteTileSource) {
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) savedTileSource);
sqLiteTileSource.closeDB();
}
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileSourceName);
Algorithms.removeAllFiles(dir);
}
}
} else if (item instanceof PoiUiFiltersSettingsItem) {
PoiUiFiltersSettingsItem poiUiFiltersSettingsItem = (PoiUiFiltersSettingsItem) item;
List<PoiUIFilter> poiUIFilters = poiUiFiltersSettingsItem.getItems();
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().removePoiFilter(filter);
}
app.getPoiFilters().reloadAllPoiFilters();
app.getPoiFilters().loadSelectedPoiFilters();
app.getSearchUICore().refreshCustomPoiFilters();
} else if (item instanceof AvoidRoadsSettingsItem) {
AvoidRoadsSettingsItem avoidRoadsSettingsItem = (AvoidRoadsSettingsItem) item;
List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = avoidRoadsSettingsItem.getItems();
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : avoidRoadInfos) {
app.getAvoidSpecificRoads().removeImpassableRoad(avoidRoad);
}
} else if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileSettingsItem.getAppMode();
ApplicationMode savedMode = ApplicationMode.valueOfStringKey(mode.getStringKey(), null);
if (savedMode != null) {
ApplicationMode.changeProfileAvailability(savedMode, false, app);
}
}
}
}
if (itemsListener != null) {
itemsListener.onItemsRemoved();
}
}
});
}
Aggregations