Merge pull request #5962 from ntruchsess/trackname
Add name element to track and route when saving gpx-files
This commit is contained in:
commit
3ea079bcd8
5 changed files with 20 additions and 7 deletions
|
@ -74,6 +74,8 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.helpers.ImportHelper.GPX_SUFFIX;
|
||||
|
||||
public class MapActivityActions implements DialogProvider {
|
||||
private static final Log LOG = PlatformUtil.getLog(MapActivityActions.class);
|
||||
public static final String KEY_LONGITUDE = "longitude";
|
||||
|
@ -226,8 +228,8 @@ public class MapActivityActions implements DialogProvider {
|
|||
fileDir.mkdirs();
|
||||
File toSave = fileDir;
|
||||
if (name.length() > 0) {
|
||||
if (!name.endsWith(".gpx")) {
|
||||
name += ".gpx";
|
||||
if (!name.endsWith(GPX_SUFFIX)) {
|
||||
name += GPX_SUFFIX;
|
||||
}
|
||||
toSave = new File(fileDir, name);
|
||||
}
|
||||
|
@ -263,7 +265,8 @@ public class MapActivityActions implements DialogProvider {
|
|||
protected String doInBackground(File... params) {
|
||||
if (params.length > 0) {
|
||||
File file = params[0];
|
||||
GPXFile gpx = app.getRoutingHelper().generateGPXFileWithRoute();
|
||||
String fileName = file.getName();
|
||||
GPXFile gpx = app.getRoutingHelper().generateGPXFileWithRoute(fileName.substring(0,fileName.length()-GPX_SUFFIX.length()));
|
||||
GPXUtilities.writeGpxFile(file, gpx, app);
|
||||
return app.getString(R.string.route_successfully_saved_at, file.getName());
|
||||
}
|
||||
|
|
|
@ -65,8 +65,11 @@ import java.io.File;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
|
||||
|
||||
|
@ -439,7 +442,8 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
|||
shareRoute.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final GPXFile gpx = helper.generateGPXFileWithRoute();
|
||||
final String trackName = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
|
||||
final GPXFile gpx = helper.generateGPXFileWithRoute(trackName);
|
||||
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), new File(gpx.path));
|
||||
File dir = new File(getActivity().getCacheDir(), "share");
|
||||
if (!dir.exists()) {
|
||||
|
|
|
@ -1214,6 +1214,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
|
||||
if (gpx == null) {
|
||||
toSave = new File(dir, fileName);
|
||||
String trackName = fileName.substring(0,fileName.length()-GPX_SUFFIX.length());
|
||||
GPXFile gpx = new GPXFile();
|
||||
if (measurementLayer != null) {
|
||||
if (saveType == SaveType.LINE) {
|
||||
|
@ -1225,6 +1226,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
segment.points.addAll(points);
|
||||
}
|
||||
Track track = new Track();
|
||||
track.name = trackName;
|
||||
track.segments.add(segment);
|
||||
gpx.tracks.add(track);
|
||||
} else if (saveType == SaveType.ROUTE_POINT) {
|
||||
|
@ -1233,10 +1235,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
segment.points.addAll(before.points);
|
||||
segment.points.addAll(after.points);
|
||||
Track track = new Track();
|
||||
track.name = trackName;
|
||||
track.segments.add(segment);
|
||||
gpx.tracks.add(track);
|
||||
}
|
||||
Route rt = new Route();
|
||||
rt.name = trackName;
|
||||
gpx.routes.add(rt);
|
||||
rt.points.addAll(points);
|
||||
}
|
||||
|
|
|
@ -1005,7 +1005,7 @@ public class RouteProvider {
|
|||
return directions;
|
||||
}
|
||||
|
||||
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx) {
|
||||
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx, String name) {
|
||||
TargetPointsHelper helper = ctx.getTargetPointsHelper();
|
||||
int currentRoute = srcRoute.currentRoute;
|
||||
List<Location> routeNodes = srcRoute.getImmutableAllLocations();
|
||||
|
@ -1015,6 +1015,7 @@ public class RouteProvider {
|
|||
GPXFile gpx = new GPXFile();
|
||||
gpx.author = OSMAND_ROUTER;
|
||||
Track track = new Track();
|
||||
track.name = name;
|
||||
gpx.tracks.add(track);
|
||||
TrkSegment trkSegment = new TrkSegment();
|
||||
track.segments.add(trkSegment);
|
||||
|
@ -1055,6 +1056,7 @@ public class RouteProvider {
|
|||
}
|
||||
|
||||
Route route = new Route();
|
||||
route.name = name;
|
||||
gpx.routes.add(route);
|
||||
for (int i = cDirInfo; i < directionInfo.size(); i++) {
|
||||
RouteDirectionInfo dirInfo = directionInfo.get(i);
|
||||
|
|
|
@ -1080,8 +1080,8 @@ public class RoutingHelper {
|
|||
return route;
|
||||
}
|
||||
|
||||
public GPXFile generateGPXFileWithRoute(){
|
||||
return provider.createOsmandRouterGPX(route, app);
|
||||
public GPXFile generateGPXFileWithRoute(String name){
|
||||
return provider.createOsmandRouterGPX(route, app, name);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue