diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 2874c708a5..fdc1edde1d 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -2,17 +2,23 @@ package net.osmand.plus; import android.content.Context; import android.support.annotation.Nullable; +import android.text.format.DateFormat; +import net.osmand.IndexConstants; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; +import java.io.File; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.List; +import java.util.Locale; public class MapMarkersHelper { public static final int MAP_MARKERS_COLORS_COUNT = 7; @@ -503,4 +509,28 @@ public class MapMarkersHelper { ctx.getGeocodingLookupService().cancel(latLon); } } + + public void generateGpx() { + final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + if (!dir.exists()) { + dir.mkdirs(); + } + Date date = new Date(); + String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date); + File fout = new File(dir, fileName + ".gpx"); + int ind = 1; + while (fout.exists()) { + fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); + } + GPXUtilities.GPXFile file = new GPXUtilities.GPXFile(); + for (MapMarker marker : markersDbHelper.getActiveMarkers()) { + GPXUtilities.WptPt wpt = new GPXUtilities.WptPt(); + wpt.lat = marker.getLatitude(); + wpt.lon = marker.getLongitude(); + wpt.setColor(ctx.getResources().getColor(MapMarker.getColorId(marker.colorIndex))); + wpt.name = marker.getOnlyName(); + file.points.add(wpt); + } + GPXUtilities.writeGpxFile(fout, file, ctx); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index e66348ef5a..73e09665da 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -154,7 +154,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void saveAsNewTrackOnClick() { - Toast.makeText(getContext(), "Save as new track", Toast.LENGTH_SHORT).show(); + mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(); } @Override