use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class MapMarkersDbHelper method getAllGroupsMap.
public Map<String, MapMarkersGroup> getAllGroupsMap() {
Map<String, MapMarkersGroup> res = new LinkedHashMap<>();
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
if (query.moveToFirst()) {
do {
MapMarkersGroup group = readGroup(query);
res.put(group.getId(), group);
} while (query.moveToNext());
}
query.close();
} finally {
db.close();
}
}
return res;
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class MapMarkersDbHelper method getActiveMarkers.
public List<MapMarker> getActiveMarkers() {
Map<String, MapMarker> markers = new LinkedHashMap<>();
Set<String> nextKeys = new HashSet<>();
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", new String[] { String.valueOf(1) });
if (query.moveToFirst()) {
do {
MapMarker marker = readItem(query);
markers.put(marker.id, marker);
nextKeys.add(marker.nextKey);
} while (query.moveToNext());
}
query.close();
} finally {
db.close();
}
}
return buildLinkedList(markers, nextKeys);
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method insertImage.
/**
* Makes method synchronized to give a little more time for get methods and
* let all writing attempts to wait outside of this method
*/
public /*synchronized*/
void insertImage(int x, int y, int zoom, byte[] dataToSave) throws IOException {
SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly() || onlyReadonlyAvailable) {
return;
}
/*There is no sense to downoad and do not save. If needed, check should perform before downlad
if (exists(x, y, zoom)) {
return;
}*/
String query = timeSupported ? "INSERT OR REPLACE INTO tiles(x,y,z,s,image,time) VALUES(?, ?, ?, ?, ?, ?)" : "INSERT OR REPLACE INTO tiles(x,y,z,s,image) VALUES(?, ?, ?, ?, ?)";
// $NON-NLS-1$
net.osmand.plus.api.SQLiteAPI.SQLiteStatement statement = db.compileStatement(query);
statement.bindLong(1, x);
statement.bindLong(2, y);
statement.bindLong(3, getFileZoom(zoom));
statement.bindLong(4, 0);
statement.bindBlob(5, dataToSave);
if (timeSupported) {
statement.bindLong(6, System.currentTimeMillis());
}
statement.execute();
statement.close();
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method deleteImage.
public void deleteImage(int x, int y, int zoom) {
SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly()) {
return;
}
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
db.execSQL("DELETE FROM tiles WHERE x = ? AND y = ? AND z = ?", new String[] { x + "", y + "", getFileZoom(zoom) + "" });
}
use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.
the class SQLiteTileSource method getUrlToLoad.
@Override
public String getUrlToLoad(int x, int y, int zoom) {
if (zoom > maxZoom)
return null;
SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly() || urlTemplate == null) {
return null;
}
if (TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)) {
try {
if (bshInterpreter == null) {
bshInterpreter = new Interpreter();
bshInterpreter.eval(urlTemplate);
}
return (String) bshInterpreter.eval("getTileUrl(" + zoom + "," + x + "," + y + ");");
} catch (bsh.EvalError e) {
LOG.debug("getUrlToLoad Error" + e.getMessage());
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
LOG.error(e.getMessage(), e);
return null;
}
} else {
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
return MessageFormat.format(urlTemplate, zoom + "", x + "", y + "");
}
}
Aggregations