diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 88ee2848ae..39a5bca3ce 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -13,7 +13,9 @@ import net.osmand.LocationsHolder; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.measurementtool.command.ApplyGpxApproximationCommand; import net.osmand.plus.measurementtool.command.MeasurementCommandManager; +import net.osmand.plus.measurementtool.command.MeasurementModeCommand; import net.osmand.plus.routing.RouteCalculationParams; import net.osmand.plus.routing.RouteCalculationParams.RouteCalculationResultListener; import net.osmand.plus.routing.RouteCalculationResult; @@ -41,6 +43,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK; +import static net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType.*; public class MeasurementEditingContext { @@ -60,6 +63,7 @@ public class MeasurementEditingContext { private WptPt originalPointToMove; private boolean inAddPointMode; + private boolean inApproximationMode; private int calculatedPairs; private int pointsToCalculateSize; private CalculationMode lastCalculationMode = WHOLE_TRACK; @@ -68,6 +72,7 @@ public class MeasurementEditingContext { private RouteCalculationProgress calculationProgress; private Map, RoadSegmentData> roadSegmentData = new ConcurrentHashMap<>(); + public enum CalculationMode { NEXT_SEGMENT, WHOLE_TRACK @@ -175,6 +180,22 @@ public class MeasurementEditingContext { this.inAddPointMode = inAddPointMode; } + public boolean isInApproximationMode() { + return inApproximationMode; + } + + public void setInApproximationMode(boolean inApproximationMode) { + this.inApproximationMode = inApproximationMode; + } + + public List getOriginalTrackPointList() { + MeasurementModeCommand command = commandManager.getLastCommand(); + if (command.getType() == APPROXIMATE_POINTS) { + return ((ApplyGpxApproximationCommand) command).getPoints(); + } + return null; + } + @Nullable GpxData getGpxData() { return gpxData; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 16b0550c7a..a41408098e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -444,13 +444,21 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), createStartPlanRouteListener()); } else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) { - SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); + enterApproximationMode(mapActivity); } } return view; } + private void enterApproximationMode(MapActivity mapActivity) { + MeasurementToolLayer layer = getMeasurementLayer(); + if (layer != null) { + layer.setTapsDisabled(true); + SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); + } + } + public boolean isInEditMode() { return !planRouteMode && !editingCtx.isNewData() && !directionMode; } @@ -597,7 +605,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route : RouteBetweenPointsDialogMode.ALL, editingCtx.getAppMode()); } else { - SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); + enterApproximationMode(mapActivity); } } } @@ -629,6 +637,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE: toolBarController.setSaveViewVisible(true); directionMode = false; + exitApproximationMode(); updateToolbar(); break; case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE: @@ -694,7 +703,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route mapActions.enterRoutePlanningModeGivenGpx(gpx, appMode, null, null, true, true, MenuState.HEADER_ONLY); } else { directionMode = true; - SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); + enterApproximationMode(mapActivity); } } } @@ -2044,6 +2053,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route public void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode) { MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { + editingCtx.setInApproximationMode(true); ApplyGpxApproximationCommand command = new ApplyGpxApproximationCommand(measurementLayer, gpxApproximation, mode); if (!editingCtx.getCommandManager().update(command)) { editingCtx.getCommandManager().execute(command); @@ -2057,6 +2067,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onApplyGpxApproximation() { + exitApproximationMode(); doAddOrMovePointCommonStuff(); if (directionMode) { directionMode = false; @@ -2082,8 +2093,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onCancelGpxApproximation() { editingCtx.getCommandManager().undo(); + exitApproximationMode(); directionMode = false; updateSnapToRoadControls(); updateToolbar(); } + + private void exitApproximationMode() { + editingCtx.setInApproximationMode(false); + MeasurementToolLayer layer = getMeasurementLayer(); + if (layer != null) { + layer.setTapsDisabled(false); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 268696bb5f..63d10688dc 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -7,6 +7,8 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.PointF; +import androidx.core.content.ContextCompat; + import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; import net.osmand.Location; @@ -49,6 +51,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private OnEnterMovePointModeListener enterMovePointModeListener; private LatLon pressedPointLatLon; private boolean overlapped; + private boolean tapsDisabled; private MeasurementEditingContext editingCtx; @Override @@ -100,9 +103,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL this.inMeasurementMode = inMeasurementMode; } + public void setTapsDisabled(boolean tapsDisabled) { + this.tapsDisabled = tapsDisabled; + } + @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { - if (inMeasurementMode && editingCtx.getSelectedPointPosition() == -1) { + if (inMeasurementMode && !tapsDisabled && editingCtx.getSelectedPointPosition() == -1) { if (!overlapped) { selectPoint(point.x, point.y, true); } @@ -118,7 +125,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL @Override public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { - if (inMeasurementMode) { + if (inMeasurementMode && !tapsDisabled) { if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) { selectPoint(point.x, point.y, false); if (editingCtx.getSelectedPointPosition() != -1) { @@ -178,7 +185,15 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL TrkSegment after = editingCtx.getAfterTrkSegmentLine(); new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2). drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); - + if (editingCtx.isInApproximationMode()) { + List originalTrackPointList = editingCtx.getOriginalTrackPointList(); + if (originalTrackPointList != null) { + lineAttrs.customColorPaint.setColor(ContextCompat.getColor(view.getContext(), + R.color.activity_background_transparent_color_dark)); + new Renderable.StandardTrack(new ArrayList<>(originalTrackPointList), 17.2). + drawSegment(view.getZoom(), lineAttrs.customColorPaint, canvas, tb); + } + } drawPoints(canvas, tb); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java index 436f42aae5..2d4afe4ccd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/AddPointCommand.java @@ -64,7 +64,7 @@ public class AddPointCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.ADD_POINT; } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ApplyGpxApproximationCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ApplyGpxApproximationCommand.java index f9a79c96b6..99488a753e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ApplyGpxApproximationCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ApplyGpxApproximationCommand.java @@ -22,8 +22,12 @@ public class ApplyGpxApproximationCommand extends MeasurementModeCommand { this.mode = mode; } + public List getPoints() { + return points; + } + @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.APPROXIMATE_POINTS; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ChangeRouteModeCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ChangeRouteModeCommand.java index 9d3e9efaf0..383431bd65 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ChangeRouteModeCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ChangeRouteModeCommand.java @@ -123,7 +123,7 @@ public class ChangeRouteModeCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.CHANGE_ROUTE_MODE; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java index c447c18ba6..2e5b9aaf85 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java @@ -61,7 +61,7 @@ public class ClearPointsCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.CLEAR_POINTS; } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementCommandManager.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementCommandManager.java index d809029f76..a1b5cad3ef 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementCommandManager.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementCommandManager.java @@ -78,4 +78,8 @@ public class MeasurementCommandManager { command.setMeasurementLayer(layer); } } + + public MeasurementModeCommand getLastCommand() { + return undoCommands.getLast(); + } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementModeCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementModeCommand.java index 92eb938233..32fa3ee7cd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementModeCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/MeasurementModeCommand.java @@ -22,7 +22,7 @@ public abstract class MeasurementModeCommand implements Command { return false; } - abstract MeasurementCommandType getType(); + public abstract MeasurementCommandType getType(); MeasurementEditingContext getEditingCtx() { return measurementLayer.getEditingCtx(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java index c734e6810a..f0b690fc7e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/MovePointCommand.java @@ -36,7 +36,7 @@ public class MovePointCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.MOVE_POINT; } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java index d112b8dfbf..c420d1c42e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/RemovePointCommand.java @@ -34,7 +34,7 @@ public class RemovePointCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.REMOVE_POINT; } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java index 52ba7e8047..302371e490 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ReorderPointCommand.java @@ -41,7 +41,7 @@ public class ReorderPointCommand extends MeasurementModeCommand { } @Override - MeasurementCommandType getType() { + public MeasurementCommandType getType() { return MeasurementCommandType.REORDER_POINT; } }