Fix points on rotate

This commit is contained in:
PavelRatushny 2017-08-15 19:00:59 +03:00
parent dc4fd71802
commit 17412ef783
2 changed files with 41 additions and 22 deletions

View file

@ -96,6 +96,7 @@ public class MeasurementToolFragment extends Fragment {
private boolean nightMode; private boolean nightMode;
private int previousMapPosition; private int previousMapPosition;
private NewGpxLine newGpxLine; private NewGpxLine newGpxLine;
private boolean routePointsAdded;
private boolean inMovePointMode; private boolean inMovePointMode;
private boolean inAddPointAfterMode; private boolean inAddPointAfterMode;
@ -103,6 +104,8 @@ public class MeasurementToolFragment extends Fragment {
private int positionToAddPoint = -1; private int positionToAddPoint = -1;
private List<WptPt> measurementPoints = new LinkedList<>();
public void setNewGpxLine(NewGpxLine newGpxLine) { public void setNewGpxLine(NewGpxLine newGpxLine) {
this.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) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
measurementLayer.setMeasurementPoints(measurementPoints);
measurementLayer.setInMovePointMode(inMovePointMode);
measurementLayer.setInAddPointBeforeMode(inAddPointBeforeMode);
measurementLayer.setInAddPointAfterMode(inAddPointAfterMode);
iconsCache = mapActivity.getMyApplication().getIconsCache(); iconsCache = mapActivity.getMyApplication().getIconsCache();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
@ -417,10 +424,11 @@ public class MeasurementToolFragment extends Fragment {
enterMeasurementMode(); enterMeasurementMode();
if (newGpxLine != null) { if (newGpxLine != null && !routePointsAdded) {
LineType lineType = newGpxLine.getLineType(); LineType lineType = newGpxLine.getLineType();
if (lineType == LineType.ROUTE_POINTS) { if (lineType == LineType.ROUTE_POINTS) {
displayRoutePoints(mapActivity); displayRoutePoints(mapActivity);
routePointsAdded = true;
} }
} }
@ -435,8 +443,21 @@ public class MeasurementToolFragment extends Fragment {
if (pointsListOpened) { if (pointsListOpened) {
setPreviousMapPosition(); setPreviousMapPosition();
} }
if (inMovePointMode) {
switchMovePointMode(false);
}
if (inAddPointAfterMode) {
switchAddPointAfterMode(false);
}
if (inAddPointBeforeMode) {
switchAddPointBeforeMode(false);
}
MeasurementToolLayer layer = getMeasurementLayer(); MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) { if (layer != null) {
layer.clearSelection();
layer.exitMovePointMode();
layer.exitAddPointAfterMode();
layer.exitAddPointBeforeMode();
layer.setOnSingleTapListener(null); layer.setOnSingleTapListener(null);
layer.setOnEnterMovePointModeListener(null); layer.setOnEnterMovePointModeListener(null);
} }
@ -448,7 +469,7 @@ public class MeasurementToolFragment extends Fragment {
GPXFile gpx = newGpxLine.getGpxFile(); GPXFile gpx = newGpxLine.getGpxFile();
List<WptPt> points = gpx.getLastRoutePoints(); List<WptPt> points = gpx.getLastRoutePoints();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.setMeasurementPoints(points); measurementPoints.addAll(points);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateText(); updateText();
} }
@ -866,9 +887,9 @@ public class MeasurementToolFragment extends Fragment {
toSave = new File(dir, fileName); toSave = new File(dir, fileName);
GPXFile gpx = new GPXFile(); GPXFile gpx = new GPXFile();
if (measurementLayer != null) { if (measurementLayer != null) {
LinkedList<WptPt> points = measurementLayer.getMeasurementPoints(); List<WptPt> points = measurementLayer.getMeasurementPoints();
if (points.size() == 1) { if (points.size() == 1) {
gpx.points.add(points.getFirst()); gpx.points.add(points.get(0));
} else if (points.size() > 1) { } else if (points.size() > 1) {
Route rt = new Route(); Route rt = new Route();
gpx.routes.add(rt); gpx.routes.add(rt);
@ -1033,7 +1054,6 @@ public class MeasurementToolFragment extends Fragment {
collapseButton.setVisibility(View.VISIBLE); collapseButton.setVisibility(View.VISIBLE);
} }
measurementLayer.getMeasurementPoints().clear();
mapActivity.refreshMap(); mapActivity.refreshMap();
} }
} }
@ -1078,21 +1098,9 @@ public class MeasurementToolFragment extends Fragment {
private void dismiss(MapActivity mapActivity) { private void dismiss(MapActivity mapActivity) {
try { try {
if (inMovePointMode) {
switchMovePointMode(false);
}
if (inAddPointAfterMode) {
switchAddPointAfterMode(false);
}
if (inAddPointBeforeMode) {
switchAddPointBeforeMode(false);
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.clearSelection(); measurementToolLayer.getMeasurementPoints().clear();
measurementToolLayer.exitMovePointMode();
measurementToolLayer.exitAddPointAfterMode();
measurementToolLayer.exitAddPointBeforeMode();
} }
if (newGpxLine != null) { if (newGpxLine != null) {
GPXFile gpx = newGpxLine.getGpxFile(); GPXFile gpx = newGpxLine.getGpxFile();

View file

@ -32,7 +32,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private boolean inMovePointMode; private boolean inMovePointMode;
private boolean inAddPointAfterMode; private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode; private boolean inAddPointBeforeMode;
private final LinkedList<WptPt> measurementPoints = new LinkedList<>(); private List<WptPt> measurementPoints = new LinkedList<>();
private Bitmap centerIconDay; private Bitmap centerIconDay;
private Bitmap centerIconNight; private Bitmap centerIconNight;
private Bitmap pointIcon; private Bitmap pointIcon;
@ -104,17 +104,28 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.inMeasurementMode = inMeasurementMode; 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() { public int getPointsCount() {
return measurementPoints.size(); return measurementPoints.size();
} }
public LinkedList<WptPt> getMeasurementPoints() { public List<WptPt> getMeasurementPoints() {
return measurementPoints; return measurementPoints;
} }
public void setMeasurementPoints(List<WptPt> points) { public void setMeasurementPoints(List<WptPt> points) {
measurementPoints.clear(); measurementPoints = points;
measurementPoints.addAll(points);
} }
String getDistanceSt() { String getDistanceSt() {