Implement Save track functionality (one of the issue). Still ToDo implement save directions (not only path).
This commit is contained in:
parent
f14194558d
commit
91d46426ed
3 changed files with 49 additions and 9 deletions
|
@ -203,11 +203,13 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
private static void writeExtensions(XmlSerializer serializer, GPXExtensions p) throws IOException {
|
||||
serializer.startTag(null, "extensions");
|
||||
for(Map.Entry<String, String> s : p.getExtensionsToRead().entrySet()){
|
||||
writeNotNullText(serializer, s.getKey(), s.getValue());
|
||||
if (!p.getExtensionsToRead().isEmpty()) {
|
||||
serializer.startTag(null, "extensions");
|
||||
for (Map.Entry<String, String> 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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue