use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavouritesDbHelper method asGpxFile.
private GPXFile asGpxFile(List<FavouritePoint> favoritePoints) {
GPXFile gpx = new GPXFile();
for (FavouritePoint p : favoritePoints) {
WptPt pt = new WptPt();
pt.lat = p.getLatitude();
pt.lon = p.getLongitude();
if (!p.isVisible()) {
pt.getExtensionsToWrite().put(HIDDEN, "true");
}
if (p.getColor() != 0) {
pt.setColor(p.getColor());
}
pt.name = p.getName();
pt.desc = p.getDescription();
if (p.getCategory().length() > 0)
pt.category = p.getCategory();
if (p.getOriginObjectName().length() > 0) {
pt.comment = p.getOriginObjectName();
}
context.getSelectedGpxHelper().addPoint(pt, gpx);
}
return gpx;
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavouritesDbHelper method loadAndCheckDatabasePoints.
private void loadAndCheckDatabasePoints() {
if (favoriteGroups == null) {
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"SELECT " + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + "," + FAVOURITE_COL_LON + " FROM " + FAVOURITE_TABLE_NAME, null);
cachedFavoritePoints.clear();
if (query.moveToFirst()) {
do {
String name = query.getString(0);
String cat = query.getString(1);
FavouritePoint p = new FavouritePoint();
p.setName(name);
p.setCategory(cat);
FavoriteGroup group = getOrCreateGroup(p, 0);
if (!name.equals("")) {
p.setLatitude(query.getDouble(2));
p.setLongitude(query.getDouble(3));
group.points.add(p);
}
} while (query.moveToNext());
}
query.close();
} finally {
db.close();
}
sortAll();
}
recalculateCachedFavPoints();
}
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class FavouritesDbHelper method deleteFavouriteDB.
public boolean deleteFavouriteDB(FavouritePoint p) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE category = ? AND " + whereNameLatLon(), // $NON-NLS-1$ //$NON-NLS-2$
new Object[] { p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude() });
FavouritePoint fp = findFavoriteByAllProperties(p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude());
if (fp != null) {
FavoriteGroup group = flatGroups.get(p.getCategory());
if (group != null) {
group.points.remove(fp);
}
cachedFavoritePoints.remove(fp);
}
saveCurrentPointsIntoFile();
} finally {
db.close();
}
return true;
}
return false;
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class OsmandAidlApi method updateFavorite.
boolean updateFavorite(AFavorite fPrev, AFavorite fNew) {
if (fPrev != null && fNew != null) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritePoint> favorites = favoritesHelper.getFavouritePoints();
for (FavouritePoint f : favorites) {
if (f.getName().equals(fPrev.getName()) && f.getCategory().equals(fPrev.getCategory()) && f.getLatitude() == fPrev.getLat() && f.getLongitude() == fPrev.getLon()) {
if (fNew.getLat() != f.getLatitude() || fNew.getLon() != f.getLongitude()) {
favoritesHelper.editFavourite(f, fNew.getLat(), fNew.getLon());
}
if (!fNew.getName().equals(f.getName()) || !fNew.getDescription().equals(f.getDescription()) || !fNew.getCategory().equals(f.getCategory())) {
favoritesHelper.editFavouriteName(f, fNew.getName(), fNew.getCategory(), fNew.getDescription());
}
refreshMap();
return true;
}
}
return false;
} else {
return false;
}
}
use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.
the class OsmandAidlApi method addFavorite.
boolean addFavorite(AFavorite favorite) {
if (favorite != null) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
FavouritePoint point = new FavouritePoint(favorite.getLat(), favorite.getLon(), favorite.getName(), favorite.getCategory());
point.setDescription(favorite.getDescription());
int color = 0;
if (!Algorithms.isEmpty(favorite.getColor())) {
color = ColorDialogs.getColorByTag(favorite.getColor());
}
point.setColor(color);
point.setVisible(favorite.isVisible());
favoritesHelper.addFavourite(point);
refreshMap();
return true;
} else {
return false;
}
}
Aggregations