Search in sources :

Example 21 with SQLiteConnection

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;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with SQLiteConnection

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);
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 23 with SQLiteConnection

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();
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 24 with SQLiteConnection

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) + "" });
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 25 with SQLiteConnection

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 + "");
    }
}
Also used : Interpreter(bsh.Interpreter) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Aggregations

SQLiteConnection (net.osmand.plus.api.SQLiteAPI.SQLiteConnection)34 SQLiteCursor (net.osmand.plus.api.SQLiteAPI.SQLiteCursor)12 Nullable (android.support.annotation.Nullable)3 ArrayList (java.util.ArrayList)3 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)3 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)2 LinkedHashMap (java.util.LinkedHashMap)2 FavouritePoint (net.osmand.data.FavouritePoint)2 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 Interpreter (bsh.Interpreter)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 QuadRect (net.osmand.data.QuadRect)1 MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)1