Search in sources :

Example 16 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class FavouritesDbHelper method editFavouriteNameDB.

public boolean editFavouriteNameDB(FavouritePoint p, String newName, String category) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            String oldCategory = p.getCategory();
            db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET " + FAVOURITE_COL_NAME + " = ?, " + FAVOURITE_COL_CATEGORY + "= ? WHERE " + whereNameLatLon(), // $NON-NLS-1$ //$NON-NLS-2$
            new Object[] { newName, category, p.getName(), p.getLatitude(), p.getLongitude() });
            p.setName(newName);
            p.setCategory(category);
            if (!oldCategory.equals(category)) {
                FavoriteGroup old = flatGroups.get(oldCategory);
                if (old != null) {
                    old.points.remove(p);
                }
                FavoriteGroup pg = getOrCreateGroup(p, 0);
                p.setVisible(pg.visible);
                p.setColor(pg.color);
                pg.points.add(p);
            }
            sortAll();
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 17 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class FavouritesDbHelper method editFavouriteDB.

public boolean editFavouriteDB(FavouritePoint p, double lat, double lon) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), // $NON-NLS-1$ //$NON-NLS-2$
            new Object[] { lat, lon, p.getName(), p.getLatitude(), p.getLongitude() });
            p.setLatitude(lat);
            p.setLongitude(lon);
            saveCurrentPointsIntoFile();
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 18 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class FavouritesDbHelper method addFavouriteDB.

public boolean addFavouriteDB(FavouritePoint p) {
    if (p.getName().equals("") && flatGroups.containsKey(p.getCategory())) {
        return true;
    }
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            db.execSQL("INSERT INTO " + FAVOURITE_TABLE_NAME + " (" + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + ", " + FAVOURITE_COL_LON + ")" + " VALUES (?, ?, ?, ?)", // $NON-NLS-1$ //$NON-NLS-2$
            new Object[] { p.getName(), p.getCategory(), p.getLatitude(), p.getLongitude() });
            FavoriteGroup group = getOrCreateGroup(p, 0);
            if (!p.getName().equals("")) {
                p.setVisible(group.visible);
                p.setColor(group.color);
                group.points.add(p);
                cachedFavoritePoints.add(p);
            }
            saveCurrentPointsIntoFile();
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 19 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class MapMarkersDbHelper method getMarker.

@Nullable
public MapMarker getMarker(String id) {
    MapMarker res = null;
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ID + " = ?", new String[] { id });
            if (query.moveToFirst()) {
                res = readItem(query);
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return res;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) Nullable(android.support.annotation.Nullable)

Example 20 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class MapMarkersDbHelper method updateMarker.

public void updateMarker(MapMarker marker) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
            db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_LAT + " = ?, " + MARKERS_COL_LON + " = ?, " + MARKERS_COL_DESCRIPTION + " = ?, " + MARKERS_COL_COLOR + " = ?, " + MARKERS_COL_SELECTED + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", new Object[] { marker.getLatitude(), marker.getLongitude(), descr, marker.colorIndex, marker.selected, marker.id });
        } finally {
            db.close();
        }
    }
}
Also used : 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