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 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<WptPt> 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<WptPt> 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<WptPt> points = measurementLayer.getMeasurementPoints();
List<WptPt> 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();

View file

@ -32,7 +32,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private boolean inMovePointMode;
private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode;
private final LinkedList<WptPt> measurementPoints = new LinkedList<>();
private List<WptPt> 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<WptPt> getMeasurementPoints() {
public List<WptPt> getMeasurementPoints() {
return measurementPoints;
}
public void setMeasurementPoints(List<WptPt> points) {
measurementPoints.clear();
measurementPoints.addAll(points);
measurementPoints = points;
}
String getDistanceSt() {