Merge pull request #4668 from osmandapp/fix_measurement_tool

Fix measurement tool
This commit is contained in:
Alexey 2017-10-30 19:33:29 +03:00 committed by GitHub
commit f4aae01649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -36,6 +36,7 @@ public class MeasurementEditingContext {
private int selectedPointPosition = -1; private int selectedPointPosition = -1;
private WptPt originalPointToMove; private WptPt originalPointToMove;
private boolean inAddPointMode;
private boolean inSnapToRoadMode; private boolean inSnapToRoadMode;
private boolean needUpdateCacheForSnap; private boolean needUpdateCacheForSnap;
private int calculatedPairs; private int calculatedPairs;
@ -53,6 +54,10 @@ public class MeasurementEditingContext {
return commandManager; return commandManager;
} }
boolean isInAddPointMode() {
return inAddPointMode;
}
boolean isInSnapToRoadMode() { boolean isInSnapToRoadMode() {
return inSnapToRoadMode; return inSnapToRoadMode;
} }
@ -82,6 +87,10 @@ public class MeasurementEditingContext {
this.originalPointToMove = originalPointToMove; this.originalPointToMove = originalPointToMove;
} }
void setInAddPointMode(boolean inAddPointMode) {
this.inAddPointMode = inAddPointMode;
}
void setInSnapToRoadMode(boolean inSnapToRoadMode) { void setInSnapToRoadMode(boolean inSnapToRoadMode) {
this.inSnapToRoadMode = inSnapToRoadMode; this.inSnapToRoadMode = inSnapToRoadMode;
} }

View file

@ -609,6 +609,7 @@ public class MeasurementToolFragment extends Fragment {
public void addPointAfterOnClick() { public void addPointAfterOnClick() {
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
editingCtx.setInAddPointMode(true);
editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1); editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1);
} }
((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after));
@ -620,6 +621,7 @@ public class MeasurementToolFragment extends Fragment {
public void addPointBeforeOnClick() { public void addPointBeforeOnClick() {
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
editingCtx.setInAddPointMode(true);
editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
} }
((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before));
@ -875,7 +877,7 @@ public class MeasurementToolFragment extends Fragment {
private void cancelModes() { private void cancelModes() {
if (editingCtx.getOriginalPointToMove() != null) { if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode(); cancelMovePointMode();
} else if (editingCtx.getSelectedPointPosition() != -1) { } else if (editingCtx.isInAddPointMode()) {
cancelAddPointBeforeOrAfterMode(); cancelAddPointBeforeOrAfterMode();
} }
} }
@ -900,6 +902,7 @@ public class MeasurementToolFragment extends Fragment {
switchAddPointBeforeAfterMode(false); switchAddPointBeforeAfterMode(false);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
editingCtx.setInAddPointMode(false);
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.refreshMap(); measurementLayer.refreshMap();
@ -911,6 +914,7 @@ public class MeasurementToolFragment extends Fragment {
switchAddPointBeforeAfterMode(false); switchAddPointBeforeAfterMode(false);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
editingCtx.setInAddPointMode(false);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.refreshMap(); measurementToolLayer.refreshMap();
@ -1397,7 +1401,7 @@ public class MeasurementToolFragment extends Fragment {
if (editingCtx.getOriginalPointToMove() != null) { if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode(); cancelMovePointMode();
return; return;
} else if (editingCtx.getSelectedPointPosition() != -1) { } else if (editingCtx.isInAddPointMode()) {
cancelAddPointBeforeOrAfterMode(); cancelAddPointBeforeOrAfterMode();
return; return;
} }