Merge pull request #6661 from osmandapp/gpx_issues

Gpx issues #6222, #6140
This commit is contained in:
Alexey 2019-03-14 18:21:07 +03:00 committed by GitHub
commit 662dc8c8b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 7 deletions

View file

@ -414,7 +414,18 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (editingCtx.getPointsCount() > 0) { if (editingCtx.getPointsCount() > 0) {
if (newGpxData != null && newGpxData.getActionType() == NewGpxData.ActionType.EDIT_SEGMENT
&& editingCtx.isInSnapToRoadMode()) {
if (mapActivity != null && measurementLayer != null) {
if (editingCtx.getPointsCount() > 0) {
openSaveAsNewTrackMenu(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
} else {
addToGpx(mapActivity); addToGpx(mapActivity);
}
} else { } else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
} }
@ -594,6 +605,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
} }
} }
@Override
public void overwriteOldTrackOnClick() {
if (mapActivity != null && measurementLayer != null) {
if (editingCtx.getPointsCount() > 0) {
overwriteGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
}
@Override @Override
public void clearAllOnClick() { public void clearAllOnClick() {
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer)); editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer));
@ -1116,6 +1138,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
saveExistingGpx(gpx, showOnMap, actionType, true); saveExistingGpx(gpx, showOnMap, actionType, true);
} }
private void overwriteGpx(MapActivity mapActivity) {
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null;
ActionType actionType = ActionType.OVERWRITE_SEGMENT;
saveExistingGpx(gpx, showOnMap, actionType, true);
}
private void saveAsGpx(final SaveType saveType) { private void saveAsGpx(final SaveType saveType) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
@ -1297,6 +1327,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
segment.points.addAll(points); segment.points.addAll(points);
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment); gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
break; break;
case OVERWRITE_SEGMENT:
List<WptPt> snappedPoints = new ArrayList<>();
snappedPoints.addAll(before.points);
snappedPoints.addAll(after.points);
TrkSegment segment1 = new TrkSegment();
segment1.points.addAll(snappedPoints);
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment1);
break;
} }
} else { } else {
gpx.addRoutePoints(points); gpx.addRoutePoints(points);

View file

@ -8,7 +8,8 @@ public class NewGpxData {
public enum ActionType { public enum ActionType {
ADD_SEGMENT, ADD_SEGMENT,
ADD_ROUTE_POINTS, ADD_ROUTE_POINTS,
EDIT_SEGMENT EDIT_SEGMENT,
OVERWRITE_SEGMENT
} }
private GPXUtilities.GPXFile gpxFile; private GPXUtilities.GPXFile gpxFile;

View file

@ -70,6 +70,39 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
}) })
.create(); .create();
items.add(saveAsNewSegmentItem); items.add(saveAsNewSegmentItem);
} else if (addLineMode) {
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle(getString(R.string.shared_string_save_as_gpx))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.saveAsNewTrackOnClick();
}
dismiss();
}
})
.create();
items.add(saveAsNewTrackItem);
BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle("Overwrite GPX")
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.overwriteOldTrackOnClick();
}
dismiss();
}
})
.create();
items.add(saveAsNewSegmentItem);
} else { } else {
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder() BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
@ -138,6 +171,8 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
void addToTheTrackOnClick(); void addToTheTrackOnClick();
void overwriteOldTrackOnClick();
void clearAllOnClick(); void clearAllOnClick();
} }
} }

View file

@ -1,5 +1,8 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -108,12 +111,17 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@ColorInt @ColorInt
private int grayColor; private int grayColor;
private CommonPreference<String> currentTrackColorPref;
private CommonPreference<String> currentTrackWidthPref;
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
selectedGpxHelper = view.getApplication().getSelectedGpxHelper(); selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
mapMarkersHelper = view.getApplication().getMapMarkersHelper(); mapMarkersHelper = view.getApplication().getMapMarkersHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer(); osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
currentTrackColorPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
currentTrackWidthPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
initUI(); initUI();
} }
@ -214,23 +222,24 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) { private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) {
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
final boolean isNight = nightMode != null && nightMode.isNightMode(); final boolean isNight = nightMode != null && nightMode.isNightMode();
int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom()); int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(),
currentTrackColorPref.get(), currentTrackWidthPref.get());
if (hsh != cachedHash) { if (hsh != cachedHash) {
cachedHash = hsh; cachedHash = hsh;
cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track); cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
if (rrs != null) { if (rrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight); req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight);
CommonPreference<String> p = view.getSettings().getCustomRenderProperty("currentTrackColor"); CommonPreference<String> p = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
if (p != null && p.isSet()) { if (p != null && p.isSet()) {
RenderingRuleProperty ctColor = rrs.PROPS.get("currentTrackColor"); RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR);
if (ctColor != null) { if (ctColor != null) {
req.setStringFilter(ctColor, p.get()); req.setStringFilter(ctColor, p.get());
} }
} }
CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty("currentTrackWidth"); CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
if (p2 != null && p2.isSet()) { if (p2 != null && p2.isSet()) {
RenderingRuleProperty ctWidth = rrs.PROPS.get("currentTrackWidth"); RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
if (ctWidth != null) { if (ctWidth != null) {
req.setStringFilter(ctWidth, p2.get()); req.setStringFilter(ctWidth, p2.get());
} }