From 17412ef7839e4ae65c461643585fbaea5d76da7e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 15 Aug 2017 19:00:59 +0300 Subject: [PATCH] Fix points on rotate --- .../MeasurementToolFragment.java | 44 +++++++++++-------- .../measurementtool/MeasurementToolLayer.java | 19 ++++++-- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 85b0169b74..b363c5933c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -96,6 +96,7 @@ public class MeasurementToolFragment extends Fragment { private boolean nightMode; private int previousMapPosition; private NewGpxLine newGpxLine; + private boolean routePointsAdded; private boolean inMovePointMode; private boolean inAddPointAfterMode; @@ -103,6 +104,8 @@ public class MeasurementToolFragment extends Fragment { private int positionToAddPoint = -1; + private List measurementPoints = new LinkedList<>(); + public void setNewGpxLine(NewGpxLine newGpxLine) { this.newGpxLine = newGpxLine; } @@ -112,6 +115,10 @@ public class MeasurementToolFragment extends Fragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); + measurementLayer.setMeasurementPoints(measurementPoints); + measurementLayer.setInMovePointMode(inMovePointMode); + measurementLayer.setInAddPointBeforeMode(inAddPointBeforeMode); + measurementLayer.setInAddPointAfterMode(inAddPointAfterMode); iconsCache = mapActivity.getMyApplication().getIconsCache(); nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -417,10 +424,11 @@ public class MeasurementToolFragment extends Fragment { enterMeasurementMode(); - if (newGpxLine != null) { + if (newGpxLine != null && !routePointsAdded) { LineType lineType = newGpxLine.getLineType(); if (lineType == LineType.ROUTE_POINTS) { displayRoutePoints(mapActivity); + routePointsAdded = true; } } @@ -435,8 +443,21 @@ public class MeasurementToolFragment extends Fragment { if (pointsListOpened) { setPreviousMapPosition(); } + if (inMovePointMode) { + switchMovePointMode(false); + } + if (inAddPointAfterMode) { + switchAddPointAfterMode(false); + } + if (inAddPointBeforeMode) { + switchAddPointBeforeMode(false); + } MeasurementToolLayer layer = getMeasurementLayer(); if (layer != null) { + layer.clearSelection(); + layer.exitMovePointMode(); + layer.exitAddPointAfterMode(); + layer.exitAddPointBeforeMode(); layer.setOnSingleTapListener(null); layer.setOnEnterMovePointModeListener(null); } @@ -448,7 +469,7 @@ public class MeasurementToolFragment extends Fragment { GPXFile gpx = newGpxLine.getGpxFile(); List points = gpx.getLastRoutePoints(); if (measurementLayer != null) { - measurementLayer.setMeasurementPoints(points); + measurementPoints.addAll(points); adapter.notifyDataSetChanged(); updateText(); } @@ -866,9 +887,9 @@ public class MeasurementToolFragment extends Fragment { toSave = new File(dir, fileName); GPXFile gpx = new GPXFile(); if (measurementLayer != null) { - LinkedList points = measurementLayer.getMeasurementPoints(); + List points = measurementLayer.getMeasurementPoints(); if (points.size() == 1) { - gpx.points.add(points.getFirst()); + gpx.points.add(points.get(0)); } else if (points.size() > 1) { Route rt = new Route(); gpx.routes.add(rt); @@ -1033,7 +1054,6 @@ public class MeasurementToolFragment extends Fragment { collapseButton.setVisibility(View.VISIBLE); } - measurementLayer.getMeasurementPoints().clear(); mapActivity.refreshMap(); } } @@ -1078,21 +1098,9 @@ public class MeasurementToolFragment extends Fragment { private void dismiss(MapActivity mapActivity) { try { - if (inMovePointMode) { - switchMovePointMode(false); - } - if (inAddPointAfterMode) { - switchAddPointAfterMode(false); - } - if (inAddPointBeforeMode) { - switchAddPointBeforeMode(false); - } MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); if (measurementToolLayer != null) { - measurementToolLayer.clearSelection(); - measurementToolLayer.exitMovePointMode(); - measurementToolLayer.exitAddPointAfterMode(); - measurementToolLayer.exitAddPointBeforeMode(); + measurementToolLayer.getMeasurementPoints().clear(); } if (newGpxLine != null) { GPXFile gpx = newGpxLine.getGpxFile(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 3badbda38b..dab2aabf04 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -32,7 +32,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private boolean inMovePointMode; private boolean inAddPointAfterMode; private boolean inAddPointBeforeMode; - private final LinkedList measurementPoints = new LinkedList<>(); + private List measurementPoints = new LinkedList<>(); private Bitmap centerIconDay; private Bitmap centerIconNight; private Bitmap pointIcon; @@ -104,17 +104,28 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL this.inMeasurementMode = inMeasurementMode; } + void setInMovePointMode(boolean inMovePointMode) { + this.inMovePointMode = inMovePointMode; + } + + void setInAddPointAfterMode(boolean inAddPointAfterMode) { + this.inAddPointAfterMode = inAddPointAfterMode; + } + + void setInAddPointBeforeMode(boolean inAddPointBeforeMode) { + this.inAddPointBeforeMode = inAddPointBeforeMode; + } + public int getPointsCount() { return measurementPoints.size(); } - public LinkedList getMeasurementPoints() { + public List getMeasurementPoints() { return measurementPoints; } public void setMeasurementPoints(List points) { - measurementPoints.clear(); - measurementPoints.addAll(points); + measurementPoints = points; } String getDistanceSt() {