Merge branch 'master' of git://github.com/osmandapp/Osmand into android_http_server

This commit is contained in:
simon 2020-09-03 14:33:50 +03:00
commit c0c07b95c2
12 changed files with 78 additions and 14 deletions

View file

@ -13,7 +13,9 @@ import net.osmand.LocationsHolder;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; 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.MeasurementCommandManager;
import net.osmand.plus.measurementtool.command.MeasurementModeCommand;
import net.osmand.plus.routing.RouteCalculationParams; import net.osmand.plus.routing.RouteCalculationParams;
import net.osmand.plus.routing.RouteCalculationParams.RouteCalculationResultListener; import net.osmand.plus.routing.RouteCalculationParams.RouteCalculationResultListener;
import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult;
@ -41,6 +43,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK;
import static net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType.*;
public class MeasurementEditingContext { public class MeasurementEditingContext {
@ -60,6 +63,7 @@ public class MeasurementEditingContext {
private WptPt originalPointToMove; private WptPt originalPointToMove;
private boolean inAddPointMode; private boolean inAddPointMode;
private boolean inApproximationMode;
private int calculatedPairs; private int calculatedPairs;
private int pointsToCalculateSize; private int pointsToCalculateSize;
private CalculationMode lastCalculationMode = WHOLE_TRACK; private CalculationMode lastCalculationMode = WHOLE_TRACK;
@ -68,6 +72,7 @@ public class MeasurementEditingContext {
private RouteCalculationProgress calculationProgress; private RouteCalculationProgress calculationProgress;
private Map<Pair<WptPt, WptPt>, RoadSegmentData> roadSegmentData = new ConcurrentHashMap<>(); private Map<Pair<WptPt, WptPt>, RoadSegmentData> roadSegmentData = new ConcurrentHashMap<>();
public enum CalculationMode { public enum CalculationMode {
NEXT_SEGMENT, NEXT_SEGMENT,
WHOLE_TRACK WHOLE_TRACK
@ -175,6 +180,22 @@ public class MeasurementEditingContext {
this.inAddPointMode = inAddPointMode; this.inAddPointMode = inAddPointMode;
} }
public boolean isInApproximationMode() {
return inApproximationMode;
}
public void setInApproximationMode(boolean inApproximationMode) {
this.inApproximationMode = inApproximationMode;
}
public List<WptPt> getOriginalTrackPointList() {
MeasurementModeCommand command = commandManager.getLastCommand();
if (command.getType() == APPROXIMATE_POINTS) {
return ((ApplyGpxApproximationCommand) command).getPoints();
}
return null;
}
@Nullable @Nullable
GpxData getGpxData() { GpxData getGpxData() {
return gpxData; return gpxData;

View file

@ -444,13 +444,21 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createStartPlanRouteListener()); createStartPlanRouteListener());
} else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) { } else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) {
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); enterApproximationMode(mapActivity);
} }
} }
return view; return view;
} }
private void enterApproximationMode(MapActivity mapActivity) {
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setTapsDisabled(true);
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
}
}
public boolean isInEditMode() { public boolean isInEditMode() {
return !planRouteMode && !editingCtx.isNewData() && !directionMode; return !planRouteMode && !editingCtx.isNewData() && !directionMode;
} }
@ -597,7 +605,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
: RouteBetweenPointsDialogMode.ALL, : RouteBetweenPointsDialogMode.ALL,
editingCtx.getAppMode()); editingCtx.getAppMode());
} else { } else {
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); enterApproximationMode(mapActivity);
} }
} }
} }
@ -629,6 +637,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE: case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE:
toolBarController.setSaveViewVisible(true); toolBarController.setSaveViewVisible(true);
directionMode = false; directionMode = false;
exitApproximationMode();
updateToolbar(); updateToolbar();
break; break;
case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE: 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); mapActions.enterRoutePlanningModeGivenGpx(gpx, appMode, null, null, true, true, MenuState.HEADER_ONLY);
} else { } else {
directionMode = true; 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) { public void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode) {
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
editingCtx.setInApproximationMode(true);
ApplyGpxApproximationCommand command = new ApplyGpxApproximationCommand(measurementLayer, gpxApproximation, mode); ApplyGpxApproximationCommand command = new ApplyGpxApproximationCommand(measurementLayer, gpxApproximation, mode);
if (!editingCtx.getCommandManager().update(command)) { if (!editingCtx.getCommandManager().update(command)) {
editingCtx.getCommandManager().execute(command); editingCtx.getCommandManager().execute(command);
@ -2057,6 +2067,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void onApplyGpxApproximation() { public void onApplyGpxApproximation() {
exitApproximationMode();
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
if (directionMode) { if (directionMode) {
directionMode = false; directionMode = false;
@ -2082,8 +2093,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void onCancelGpxApproximation() { public void onCancelGpxApproximation() {
editingCtx.getCommandManager().undo(); editingCtx.getCommandManager().undo();
exitApproximationMode();
directionMode = false; directionMode = false;
updateSnapToRoadControls(); updateSnapToRoadControls();
updateToolbar(); updateToolbar();
} }
private void exitApproximationMode() {
editingCtx.setInApproximationMode(false);
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setTapsDisabled(false);
}
}
} }

View file

@ -7,6 +7,8 @@ import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import androidx.core.content.ContextCompat;
import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location; import net.osmand.Location;
@ -49,6 +51,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private OnEnterMovePointModeListener enterMovePointModeListener; private OnEnterMovePointModeListener enterMovePointModeListener;
private LatLon pressedPointLatLon; private LatLon pressedPointLatLon;
private boolean overlapped; private boolean overlapped;
private boolean tapsDisabled;
private MeasurementEditingContext editingCtx; private MeasurementEditingContext editingCtx;
@Override @Override
@ -100,9 +103,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.inMeasurementMode = inMeasurementMode; this.inMeasurementMode = inMeasurementMode;
} }
public void setTapsDisabled(boolean tapsDisabled) {
this.tapsDisabled = tapsDisabled;
}
@Override @Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode && editingCtx.getSelectedPointPosition() == -1) { if (inMeasurementMode && !tapsDisabled && editingCtx.getSelectedPointPosition() == -1) {
if (!overlapped) { if (!overlapped) {
selectPoint(point.x, point.y, true); selectPoint(point.x, point.y, true);
} }
@ -118,7 +125,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
@Override @Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode) { if (inMeasurementMode && !tapsDisabled) {
if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) { if (!overlapped && getEditingCtx().getSelectedPointPosition() == -1 && editingCtx.getPointsCount() > 0) {
selectPoint(point.x, point.y, false); selectPoint(point.x, point.y, false);
if (editingCtx.getSelectedPointPosition() != -1) { if (editingCtx.getSelectedPointPosition() != -1) {
@ -178,7 +185,15 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
TrkSegment after = editingCtx.getAfterTrkSegmentLine(); TrkSegment after = editingCtx.getAfterTrkSegmentLine();
new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2). new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2).
drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb);
if (editingCtx.isInApproximationMode()) {
List<WptPt> 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); drawPoints(canvas, tb);
} }
} }

View file

@ -64,7 +64,7 @@ public class AddPointCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.ADD_POINT; return MeasurementCommandType.ADD_POINT;
} }
} }

View file

@ -22,8 +22,12 @@ public class ApplyGpxApproximationCommand extends MeasurementModeCommand {
this.mode = mode; this.mode = mode;
} }
public List<WptPt> getPoints() {
return points;
}
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.APPROXIMATE_POINTS; return MeasurementCommandType.APPROXIMATE_POINTS;
} }

View file

@ -123,7 +123,7 @@ public class ChangeRouteModeCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.CHANGE_ROUTE_MODE; return MeasurementCommandType.CHANGE_ROUTE_MODE;
} }

View file

@ -61,7 +61,7 @@ public class ClearPointsCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.CLEAR_POINTS; return MeasurementCommandType.CLEAR_POINTS;
} }
} }

View file

@ -78,4 +78,8 @@ public class MeasurementCommandManager {
command.setMeasurementLayer(layer); command.setMeasurementLayer(layer);
} }
} }
public MeasurementModeCommand getLastCommand() {
return undoCommands.getLast();
}
} }

View file

@ -22,7 +22,7 @@ public abstract class MeasurementModeCommand implements Command {
return false; return false;
} }
abstract MeasurementCommandType getType(); public abstract MeasurementCommandType getType();
MeasurementEditingContext getEditingCtx() { MeasurementEditingContext getEditingCtx() {
return measurementLayer.getEditingCtx(); return measurementLayer.getEditingCtx();

View file

@ -36,7 +36,7 @@ public class MovePointCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.MOVE_POINT; return MeasurementCommandType.MOVE_POINT;
} }
} }

View file

@ -34,7 +34,7 @@ public class RemovePointCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.REMOVE_POINT; return MeasurementCommandType.REMOVE_POINT;
} }
} }

View file

@ -41,7 +41,7 @@ public class ReorderPointCommand extends MeasurementModeCommand {
} }
@Override @Override
MeasurementCommandType getType() { public MeasurementCommandType getType() {
return MeasurementCommandType.REORDER_POINT; return MeasurementCommandType.REORDER_POINT;
} }
} }