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.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<Pair<WptPt, WptPt>, 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<WptPt> getOriginalTrackPointList() {
MeasurementModeCommand command = commandManager.getLastCommand();
if (command.getType() == APPROXIMATE_POINTS) {
return ((ApplyGpxApproximationCommand) command).getPoints();
}
return null;
}
@Nullable
GpxData getGpxData() {
return gpxData;

View file

@ -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);
}
}
}

View file

@ -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<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);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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