Add route points to track

This commit is contained in:
PavelRatushny 2017-08-17 15:54:34 +03:00
parent bc3683923a
commit 7f03ce321b
2 changed files with 36 additions and 16 deletions

View file

@ -935,6 +935,19 @@ public class GPXUtilities {
return false;
}
public void addRoutePoints(List<WptPt> points) {
if (routes.size() == 0) {
Route route = new Route();
routes.add(route);
}
Route lastRoute = routes.get(routes.size() - 1);
lastRoute.points.addAll(points);
modifiedTime = System.currentTimeMillis();
}
public void replaceRoutePoints(List<WptPt> points) {
routes.clear();
routes.add(new Route());

View file

@ -533,7 +533,7 @@ public class MeasurementToolFragment extends Fragment {
public void addToTheTrackOnClick() {
if (mapActivity != null && measurementLayer != null) {
if (measurementLayer.getPointsCount() > 0) {
// showAddSegmentDialog(mapActivity);
showAddSegmentDialog(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
@ -789,6 +789,9 @@ public class MeasurementToolFragment extends Fragment {
GPXFile gpxFile;
if (result != null && result.length > 0) {
gpxFile = result[0];
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
boolean showOnMap = selectedGpxFile != null;
saveExistingGpx(gpxFile, showOnMap, null, false);
}
return true;
}
@ -1059,7 +1062,7 @@ public class MeasurementToolFragment extends Fragment {
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null;
LineType lineType = newGpxLine.getLineType();
saveExistingGpx(gpx, showOnMap, lineType);
saveExistingGpx(gpx, showOnMap, lineType, true);
}
private void saveAsGpx(final SaveType saveType) {
@ -1135,8 +1138,8 @@ public class MeasurementToolFragment extends Fragment {
saveGpx(dir, fileName, checked, null, false, null, saveType);
}
private void saveExistingGpx(GPXFile gpx, boolean showOnMap, LineType lineType) {
saveGpx(null, null, showOnMap, gpx, true, lineType, null);
private void saveExistingGpx(GPXFile gpx, boolean showOnMap, LineType lineType, boolean openTrackActivity) {
saveGpx(null, null, showOnMap, gpx, openTrackActivity, lineType, null);
}
private void saveGpx(final File dir,
@ -1195,18 +1198,22 @@ public class MeasurementToolFragment extends Fragment {
toSave = new File(gpx.path);
if (measurementLayer != null) {
List<WptPt> points = measurementLayer.getMeasurementPoints();
switch (lineType) {
case ADD_SEGMENT:
gpx.addTrkSegment(points);
break;
case ADD_ROUTE_POINTS:
gpx.replaceRoutePoints(points);
break;
case EDIT_SEGMENT:
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
gpx.replaceSegment(newGpxLine.getTrkSegment(), segment);
break;
if (lineType != null) {
switch (lineType) {
case ADD_SEGMENT:
gpx.addTrkSegment(points);
break;
case ADD_ROUTE_POINTS:
gpx.replaceRoutePoints(points);
break;
case EDIT_SEGMENT:
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
gpx.replaceSegment(newGpxLine.getTrkSegment(), segment);
break;
}
} else {
gpx.addRoutePoints(points);
}
}
if (activity != null) {