diff --git a/OsmAnd/src/net/osmand/GPXUtilities.java b/OsmAnd/src/net/osmand/GPXUtilities.java index 24263bb880..e583cabcd7 100644 --- a/OsmAnd/src/net/osmand/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/GPXUtilities.java @@ -203,11 +203,13 @@ public class GPXUtilities { } private static void writeExtensions(XmlSerializer serializer, GPXExtensions p) throws IOException { - serializer.startTag(null, "extensions"); - for(Map.Entry s : p.getExtensionsToRead().entrySet()){ - writeNotNullText(serializer, s.getKey(), s.getValue()); + if (!p.getExtensionsToRead().isEmpty()) { + serializer.startTag(null, "extensions"); + for (Map.Entry s : p.getExtensionsToRead().entrySet()) { + writeNotNullText(serializer, s.getKey(), s.getValue()); + } + serializer.endTag(null, "extensions"); } - serializer.endTag(null, "extensions"); } private static void writeWpt(SimpleDateFormat format, XmlSerializer serializer, WptPt p) throws IOException { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index e40aea8a52..4787e6f4c5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -4,11 +4,13 @@ import java.io.File; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.Iterator; import java.util.List; import net.osmand.CallbackWithObject; import net.osmand.FavouritePoint; +import net.osmand.GPXUtilities; import net.osmand.LogUtil; import net.osmand.GPXUtilities.GPXFile; import net.osmand.data.Amenity; @@ -516,7 +518,8 @@ public class MapActivityActions { dlg.setTitle(R.string.save_route_dialog_title); dlg.setContentView(R.layout.save_directions_dialog); final EditText edit = (EditText) dlg.findViewById(R.id.FileNameEdit); - edit.setText(""); + + edit.setText(MessageFormat.format("{0,date,dd-MM-yyyy}", new Date())); ((Button) dlg.findViewById(R.id.Save)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -532,7 +535,8 @@ public class MapActivityActions { if(toSave.exists()){ dlg.findViewById(R.id.DuplicateFileName).setVisibility(View.VISIBLE); } else { - new SaveDirectionsAsyncTask().execute(fileDir); + dlg.dismiss(); + new SaveDirectionsAsyncTask().execute(toSave); } } }); @@ -555,7 +559,8 @@ public class MapActivityActions { protected String doInBackground(File... params) { if (params.length > 0) { File file = params[0]; - + GPXFile gpx = mapActivity.getRoutingHelper().generateGPXFileWithRoute(); + GPXUtilities.writeGpxFile(file, gpx, mapActivity); return mapActivity.getString(R.string.route_successfully_saved_at, file.getName()); } return null; @@ -564,7 +569,7 @@ public class MapActivityActions { @Override protected void onPostExecute(String result) { if(result != null){ - Toast.makeText(mapActivity, result, Toast.LENGTH_SHORT); + Toast.makeText(mapActivity, result, Toast.LENGTH_LONG).show(); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java index 790ebc5f96..a25bbb015d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java @@ -6,6 +6,10 @@ import java.util.List; import net.osmand.LogUtil; import net.osmand.OsmAndFormatter; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.Track; +import net.osmand.GPXUtilities.TrkSegment; +import net.osmand.GPXUtilities.WptPt; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; import net.osmand.plus.OsmandSettings; @@ -23,6 +27,7 @@ import android.widget.Toast; public class RoutingHelper { private static final org.apache.commons.logging.Log log = LogUtil.getLog(RoutingHelper.class); + private static final String OSMAND_ROUTER = "OsmandRouter"; public static interface IRouteInformationListener { @@ -558,7 +563,35 @@ public class RoutingHelper { } } - + public GPXFile generateGPXFileWithRoute(){ + GPXFile gpx = new GPXFile(); + gpx.author = OSMAND_ROUTER; + Track track = new Track(); + gpx.tracks.add(track); + TrkSegment trkSegment = new TrkSegment(); + track.segments.add(trkSegment); + int cRoute = currentRoute; + int cDirInfo = currentDirectionInfo; + + for(int i = cRoute; i< routeNodes.size(); i++){ + Location loc = routeNodes.get(i); + WptPt pt = new WptPt(); + pt.lat = loc.getLatitude(); + pt.lon = loc.getLongitude(); + if(loc.hasSpeed()){ + pt.speed = loc.getSpeed(); + } + if(loc.hasAltitude()){ + pt.ele = loc.getAltitude(); + } + if(loc.hasAccuracy()){ + pt.hdop = loc.getAccuracy(); + } + trkSegment.points.add(pt); + } + // TODO save dir info + return gpx; + } public static class TurnType {