Search in sources :

Example 41 with FavouritePoint

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;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 42 with FavouritePoint

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

Example 43 with FavouritePoint

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

Example 44 with FavouritePoint

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;
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper)

Example 45 with FavouritePoint

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;
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) FavouritePoint(net.osmand.data.FavouritePoint) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4