Search in sources :

Example 31 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavoritesTreeFragment method selectMapMarkersImpl.

private void selectMapMarkersImpl() {
    if (getSelectedFavoritesCount() > 0) {
        MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
        List<LatLon> points = new ArrayList<>();
        List<PointDescription> names = new ArrayList<>();
        for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
            FavoriteGroup favGr = helper.getGroup(entry.getKey());
            MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(favGr);
            if (entry.getValue().size() == favGr.points.size()) {
                markersHelper.addOrEnableGroup(markersGr);
            } else {
                for (FavouritePoint fp : entry.getValue()) {
                    points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
                    names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
                }
                markersHelper.addMapMarkers(points, names, markersGr);
                points.clear();
                names.clear();
            }
        }
        MapActivity.launchMapActivityMoveToTop(getActivity());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PointDescription(net.osmand.data.PointDescription) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavoritesTreeFragment method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    if (selectionMode) {
        CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item);
        FavouritePoint model = favouritesAdapter.getChild(groupPosition, childPosition);
        FavoriteGroup group = favouritesAdapter.getGroup(groupPosition);
        ch.setChecked(!ch.isChecked());
        if (ch.isChecked()) {
            Set<FavouritePoint> set = favoritesSelected.get(group.name);
            if (set != null) {
                set.add(model);
            } else {
                set = new LinkedHashSet<>();
                set.add(model);
                favoritesSelected.put(group.name, set);
            }
        } else {
            Set<FavouritePoint> set = favoritesSelected.get(group.name);
            if (set != null) {
                set.remove(model);
            }
        }
        updateSelectionMode(actionMode);
    } else {
        final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
        showOnMap(point);
    }
    return true;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) CheckBox(android.widget.CheckBox) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 33 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavoritesTreeFragment method generateHtmlPrint.

private StringBuilder generateHtmlPrint(List<FavoriteGroup> groups) {
    StringBuilder html = new StringBuilder();
    html.append("<h1>My Favorites</h1>");
    for (FavoriteGroup group : groups) {
        html.append("<h3>" + group.name + "</h3>");
        for (FavouritePoint fp : group.points) {
            String url = "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "?m=" + fp.getName();
            html.append("<p>" + fp.getName() + " - " + "<a href=\"" + url + "\">geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "</a><br>");
            if (!Algorithms.isEmpty(fp.getDescription())) {
                html.append(": " + fp.getDescription());
            }
            html.append("</p>");
        }
    }
    return html;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 34 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method sortAll.

public void sortAll() {
    final Collator collator = Collator.getInstance();
    collator.setStrength(Collator.SECONDARY);
    Collections.sort(favoriteGroups, new Comparator<FavoriteGroup>() {

        @Override
        public int compare(FavoriteGroup lhs, FavoriteGroup rhs) {
            return collator.compare(lhs.name, rhs.name);
        }
    });
    Comparator<FavouritePoint> favoritesComparator = getComparator();
    for (FavoriteGroup g : favoriteGroups) {
        Collections.sort(g.points, favoritesComparator);
    }
    if (cachedFavoritePoints != null) {
        Collections.sort(cachedFavoritePoints, favoritesComparator);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) Collator(java.text.Collator)

Example 35 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method saveCurrentPointsIntoFile.

public void saveCurrentPointsIntoFile() {
    try {
        Map<String, FavouritePoint> deletedInMemory = new LinkedHashMap<String, FavouritePoint>();
        loadGPXFile(getInternalFile(), deletedInMemory);
        for (FavouritePoint fp : cachedFavoritePoints) {
            deletedInMemory.remove(getKey(fp));
        }
        saveFile(cachedFavoritePoints, getInternalFile());
        saveExternalFile(deletedInMemory.keySet());
        backup(getBackupFile(), getExternalFile());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) LinkedHashMap(java.util.LinkedHashMap)

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