Refactor drawing

This commit is contained in:
PavelRatushny 2017-08-23 15:46:17 +03:00
parent 2214d4996b
commit 46bed0cf4b
3 changed files with 147 additions and 337 deletions

View file

@ -5,6 +5,7 @@ import android.util.Pair;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.views.Renderable;
import net.osmand.router.RoutingContext; import net.osmand.router.RoutingContext;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -24,6 +25,8 @@ public class MeasurementEditingContext {
private TrkSegment afterCacheForSnap; private TrkSegment afterCacheForSnap;
private boolean inMovePointMode; private boolean inMovePointMode;
private boolean inAddPointBeforeMode;
private boolean inAddPointAfterMode;
private boolean isInSnapToRoadMode; private boolean isInSnapToRoadMode;
private ApplicationMode snapToRoadAppMode; private ApplicationMode snapToRoadAppMode;
@ -33,10 +36,20 @@ public class MeasurementEditingContext {
public void setBefore(TrkSegment before) { public void setBefore(TrkSegment before) {
this.before = before; this.before = before;
addBeforeRenders();
} }
public void setAfter(TrkSegment after) { public void setAfter(TrkSegment after) {
this.after = after; this.after = after;
addAfterRenders();
}
public void addBeforeRenders() {
before.renders.add(new Renderable.StandardTrack(before.points, 17.2));
}
public void addAfterRenders() {
after.renders.add(new Renderable.StandardTrack(after.points, 17.2));
} }
public boolean isInMovePointMode() { public boolean isInMovePointMode() {
@ -51,6 +64,22 @@ public class MeasurementEditingContext {
return isInSnapToRoadMode; return isInSnapToRoadMode;
} }
public void setInAddPointBeforeMode(boolean inAddPointBeforeMode) {
this.inAddPointBeforeMode = inAddPointBeforeMode;
}
public boolean isInAddPointBeforeMode() {
return inAddPointBeforeMode;
}
public void setInAddPointAfterMode(boolean inAddPointAfterMode) {
this.inAddPointAfterMode = inAddPointAfterMode;
}
public boolean isInAddPointAfterMode() {
return inAddPointAfterMode;
}
public void setInSnapToRoadMode(boolean inSnapToRoadMode) { public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
isInSnapToRoadMode = inSnapToRoadMode; isInSnapToRoadMode = inSnapToRoadMode;
} }
@ -93,11 +122,11 @@ public class MeasurementEditingContext {
// return beforeCacheForSnap; // return beforeCacheForSnap;
// } // }
// calculate beforeCacheForSnap // calculate beforeCacheForSnap
return null; return before;
} }
public TrkSegment getAfterTrkSegmentLine() { public TrkSegment getAfterTrkSegmentLine() {
return null; return after;
} }
public void scheduleRouteCalculateIfNotEmpty() { public void scheduleRouteCalculateIfNotEmpty() {

View file

@ -125,9 +125,6 @@ public class MeasurementToolFragment extends Fragment {
private boolean gpxPointsAdded; private boolean gpxPointsAdded;
private ApplicationMode snapToRoadAppMode; private ApplicationMode snapToRoadAppMode;
private boolean inMovePointMode;
private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode;
private boolean isInSnapToRoadMode; private boolean isInSnapToRoadMode;
private int selectedPointPos = -1; private int selectedPointPos = -1;
@ -230,18 +227,16 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (inMovePointMode) { cancelMovePointMode();
cancelMovePointMode();
}
} }
}); });
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (inAddPointAfterMode) { if (measurementEditingContext.isInAddPointAfterMode()) {
cancelAddPointAfterMode(); cancelAddPointAfterMode();
} else if (inAddPointBeforeMode) { } else if (measurementEditingContext.isInAddPointBeforeMode()) {
cancelAddPointBeforeMode(); cancelAddPointBeforeMode();
} }
} }
@ -266,18 +261,16 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (inMovePointMode) { applyMovePointMode();
applyMovePointMode();
}
} }
}); });
mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (inAddPointAfterMode) { if (measurementEditingContext.isInAddPointAfterMode()) {
applyAddPointAfterMode(); applyAddPointAfterMode();
} else if (inAddPointBeforeMode) { } else if (measurementEditingContext.isInAddPointBeforeMode()) {
applyAddPointBeforeMode(); applyAddPointBeforeMode();
} }
} }
@ -286,9 +279,9 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (inAddPointAfterMode) { if (measurementEditingContext.isInAddPointAfterMode()) {
addPointAfter(); addPointAfter();
} else if (inAddPointBeforeMode) { } else if (measurementEditingContext.isInAddPointBeforeMode()) {
addPointBefore(); addPointBefore();
} }
} }
@ -313,6 +306,7 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
MeasurementCommandType type = commandManager.undo(); MeasurementCommandType type = commandManager.undo();
recreateSegments();
if (type != null && type != MeasurementCommandType.SNAP_TO_ROAD) { if (type != null && type != MeasurementCommandType.SNAP_TO_ROAD) {
recalculateSnapToRoadIfNedeed(); recalculateSnapToRoadIfNedeed();
} }
@ -336,6 +330,7 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
commandManager.redo(); commandManager.redo();
recreateSegments();
recalculateSnapToRoadIfNedeed(); recalculateSnapToRoadIfNedeed();
if (commandManager.canRedo()) { if (commandManager.canRedo()) {
enable(redoBtn); enable(redoBtn);
@ -407,7 +402,7 @@ public class MeasurementToolFragment extends Fragment {
} }
toolBarController = new MeasurementToolBarController(newGpxData); toolBarController = new MeasurementToolBarController(newGpxData);
if (inMovePointMode || inAddPointAfterMode || inAddPointBeforeMode) { if (measurementEditingContext.isInAddPointAfterMode() || measurementEditingContext.isInAddPointBeforeMode() || measurementEditingContext.isInMovePointMode()) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@ -487,6 +482,14 @@ public class MeasurementToolFragment extends Fragment {
return view; return view;
} }
private void recreateSegments() {
TrkSegment before = new TrkSegment();
before.points.addAll(measurementPoints);
measurementEditingContext.setBefore(before);
TrkSegment after = new TrkSegment();
measurementEditingContext.setAfter(after);
}
private void recalculateSnapToRoadIfNedeed() { private void recalculateSnapToRoadIfNedeed() {
if (calculationProgress != null) { if (calculationProgress != null) {
calculationProgress.isCancelled = true; calculationProgress.isCancelled = true;
@ -504,13 +507,13 @@ public class MeasurementToolFragment extends Fragment {
if (pointsListOpened) { if (pointsListOpened) {
hidePointsList(); hidePointsList();
} }
if (inMovePointMode) { if (measurementEditingContext.isInMovePointMode()) {
switchMovePointMode(false); switchMovePointMode(false);
} }
if (inAddPointAfterMode) { if (measurementEditingContext.isInAddPointAfterMode()) {
switchAddPointAfterMode(false); switchAddPointAfterMode(false);
} }
if (inAddPointBeforeMode) { if (measurementEditingContext.isInAddPointBeforeMode()) {
switchAddPointBeforeMode(false); switchAddPointBeforeMode(false);
} }
MeasurementToolLayer layer = getMeasurementLayer(); MeasurementToolLayer layer = getMeasurementLayer();
@ -608,6 +611,7 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void clearAllOnClick() { public void clearAllOnClick() {
commandManager.execute(new ClearPointsCommand(measurementLayer)); commandManager.execute(new ClearPointsCommand(measurementLayer));
recreateSegments();
if (calculationProgress != null) { if (calculationProgress != null) {
calculationProgress.isCancelled = true; calculationProgress.isCancelled = true;
} }
@ -695,6 +699,7 @@ public class MeasurementToolFragment extends Fragment {
private void removePoint(MeasurementToolLayer layer, int position) { private void removePoint(MeasurementToolLayer layer, int position) {
commandManager.execute(new RemovePointCommand(layer, position)); commandManager.execute(new RemovePointCommand(layer, position));
recreateSegments();
recalculateSnapToRoadIfNedeed(); recalculateSnapToRoadIfNedeed();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
disable(redoBtn); disable(redoBtn);
@ -762,6 +767,7 @@ public class MeasurementToolFragment extends Fragment {
toPosition = holder.getAdapterPosition(); toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
commandManager.execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition)); commandManager.execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
recreateSegments();
recalculateSnapToRoadIfNedeed(); recalculateSnapToRoadIfNedeed();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
disable(redoBtn); disable(redoBtn);
@ -870,6 +876,7 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer layer = getMeasurementLayer(); MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) { if (layer != null) {
commandManager.execute(new SnapToRoadCommand(layer, pts)); commandManager.execute(new SnapToRoadCommand(layer, pts));
recreateSegments();
} }
} }
}; };
@ -953,15 +960,14 @@ public class MeasurementToolFragment extends Fragment {
} }
private void applyMovePointMode() { private void applyMovePointMode() {
if (inMovePointMode) { switchMovePointMode(false);
switchMovePointMode(false);
}
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
WptPt newPoint = measurementLayer.getMovedPointToApply(); WptPt newPoint = measurementLayer.getMovedPointToApply();
WptPt oldPoint = measurementLayer.getSelectedCachedPoint(); WptPt oldPoint = measurementLayer.getSelectedCachedPoint();
int position = measurementLayer.getSelectedPointPos(); int position = measurementLayer.getSelectedPointPos();
commandManager.execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position)); commandManager.execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
recreateSegments();
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
measurementLayer.exitMovePointMode(); measurementLayer.exitMovePointMode();
measurementLayer.refreshMap(); measurementLayer.refreshMap();
@ -970,9 +976,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void cancelMovePointMode() { private void cancelMovePointMode() {
if (inMovePointMode) { switchMovePointMode(false);
switchMovePointMode(false);
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.exitMovePointMode(); measurementToolLayer.exitMovePointMode();
@ -996,9 +1000,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void applyAddPointAfterMode() { private void applyAddPointAfterMode() {
if (inAddPointAfterMode) { switchAddPointAfterMode(false);
switchAddPointAfterMode(false);
}
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.exitAddPointAfterMode(); measurementLayer.exitAddPointAfterMode();
@ -1009,9 +1011,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void cancelAddPointAfterMode() { private void cancelAddPointAfterMode() {
if (inAddPointAfterMode) { switchAddPointAfterMode(false);
switchAddPointAfterMode(false);
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointAfterMode(); measurementToolLayer.exitAddPointAfterMode();
@ -1034,9 +1034,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void applyAddPointBeforeMode() { private void applyAddPointBeforeMode() {
if (inAddPointBeforeMode) { switchAddPointBeforeMode(false);
switchAddPointBeforeMode(false);
}
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.exitAddPointBeforeMode(); measurementLayer.exitAddPointBeforeMode();
@ -1047,9 +1045,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void cancelAddPointBeforeMode() { private void cancelAddPointBeforeMode() {
if (inAddPointBeforeMode) { switchAddPointBeforeMode(false);
switchAddPointBeforeMode(false);
}
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointBeforeMode(); measurementToolLayer.exitAddPointBeforeMode();
@ -1069,8 +1065,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void switchMovePointMode(boolean enable) { private void switchMovePointMode(boolean enable) {
inMovePointMode = enable; if (measurementEditingContext.isInMovePointMode()) {
if (inMovePointMode) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@ -1089,8 +1084,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void switchAddPointAfterMode(boolean enable) { private void switchAddPointAfterMode(boolean enable) {
inAddPointAfterMode = enable; if (measurementEditingContext.isInAddPointAfterMode()) {
if (inAddPointAfterMode) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@ -1109,8 +1103,7 @@ public class MeasurementToolFragment extends Fragment {
} }
private void switchAddPointBeforeMode(boolean enable) { private void switchAddPointBeforeMode(boolean enable) {
inAddPointBeforeMode = enable; if (measurementEditingContext.isInAddPointBeforeMode()) {
if (inAddPointBeforeMode) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back); toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else { } else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
@ -1141,14 +1134,21 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
commandManager.execute(new AddPointCommand(measurementLayer, false)); commandManager.execute(new AddPointCommand(measurementLayer, false));
recreateSegments();
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
} }
TrkSegment before = new TrkSegment();
before.points.addAll(measurementPoints);
measurementEditingContext.setBefore(before);
TrkSegment after = new TrkSegment();
measurementEditingContext.setAfter(after);
} }
private void addCenterPoint() { private void addCenterPoint() {
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
commandManager.execute(new AddPointCommand(measurementLayer, true)); commandManager.execute(new AddPointCommand(measurementLayer, true));
recreateSegments();
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
} }
} }
@ -1158,6 +1158,7 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
added = commandManager.execute(new AddPointCommand(measurementLayer, position)); added = commandManager.execute(new AddPointCommand(measurementLayer, position));
recreateSegments();
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
} }
return added; return added;
@ -1550,15 +1551,15 @@ public class MeasurementToolFragment extends Fragment {
} }
public void quit(boolean hidePointsListFirst) { public void quit(boolean hidePointsListFirst) {
if (inMovePointMode) { if (measurementEditingContext.isInMovePointMode()) {
cancelMovePointMode(); cancelMovePointMode();
return; return;
} }
if (inAddPointAfterMode) { if (measurementEditingContext.isInAddPointAfterMode()) {
cancelAddPointAfterMode(); cancelAddPointAfterMode();
return; return;
} }
if (inAddPointBeforeMode) { if (measurementEditingContext.isInAddPointBeforeMode()) {
cancelAddPointBeforeMode(); cancelAddPointBeforeMode();
return; return;
} }

View file

@ -11,6 +11,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -39,19 +40,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private Bitmap applyingPointIcon; private Bitmap applyingPointIcon;
private Paint bitmapPaint; private Paint bitmapPaint;
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private final Path leftPath = new Path();
private final Path centerPath = new Path();
private final Path rightPath = new Path();
private int marginPointIconX; private int marginPointIconX;
private int marginPointIconY; private int marginPointIconY;
private int marginApplyingPointIconX; private int marginApplyingPointIconX;
private int marginApplyingPointIconY; private int marginApplyingPointIconY;
private final TIntArrayList leftTx = new TIntArrayList(); private Path path = new Path();
private final TIntArrayList leftTy = new TIntArrayList(); private TIntArrayList tx = new TIntArrayList();
private final TIntArrayList centerTx = new TIntArrayList(); private TIntArrayList ty = new TIntArrayList();
private final TIntArrayList centerTy = new TIntArrayList();
private final TIntArrayList rightTx = new TIntArrayList();
private final TIntArrayList rightTy = new TIntArrayList();
private OnMeasureDistanceToCenter measureDistanceToCenterListener; private OnMeasureDistanceToCenter measureDistanceToCenterListener;
private OnSingleTapListener singleTapListener; private OnSingleTapListener singleTapListener;
private OnEnterMovePointModeListener enterMovePointModeListener; private OnEnterMovePointModeListener enterMovePointModeListener;
@ -248,175 +243,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
if (inMeasurementMode) { if (inMeasurementMode) {
lineAttrs.updatePaints(view, settings, tb); lineAttrs.updatePaints(view, settings, tb);
List<WptPt> drawPoints; TrkSegment before = measurementEditingContext.getBeforeTrkSegmentLine();
if (snappedToRoadPoints.size() > 0) { before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
drawPoints = snappedToRoadPoints;
} else {
drawPoints = measurementPoints;
}
if (drawPoints.size() > 0) {
leftPath.reset();
leftTx.reset();
leftTy.reset();
rightPath.reset(); TrkSegment after = measurementEditingContext.getAfterTrkSegmentLine();
rightTx.reset(); after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
rightTy.reset();
if (selectedPointPos == -1) {
for (int i = 0; i < drawPoints.size(); i++) {
WptPt pt = drawPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (i == 0) {
leftPath.moveTo(locX, locY);
} else {
leftPath.lineTo(locX, locY);
}
leftTx.add(locX);
leftTy.add(locY);
}
if (leftTx.size() > 1) {
calculatePath(tb, leftTx, leftTy, leftPath);
canvas.drawPath(leftPath, lineAttrs.paint);
}
} else if (selectedPointPos == drawPoints.size() - 1) {
for (int i = 0; i < drawPoints.size() - 1; i++) {
WptPt pt = drawPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (i == 0) {
leftPath.moveTo(locX, locY);
} else {
leftPath.lineTo(locX, locY);
}
leftTx.add(locX);
leftTy.add(locY);
}
if (!inAddPointAfterMode && !inAddPointBeforeMode && !inMovePointMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
leftPath.lineTo(locX, locY);
leftTx.add(locX);
leftTy.add(locY);
}
if (inAddPointAfterMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
leftPath.lineTo(locX, locY);
leftTx.add(locX);
leftTy.add(locY);
}
if (leftTx.size() > 1) {
calculatePath(tb, leftTx, leftTy, leftPath);
canvas.drawPath(leftPath, lineAttrs.paint);
}
} else {
for (int i = 0; i < selectedPointPos; i++) {
WptPt pt = drawPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (i == 0) {
leftPath.moveTo(locX, locY);
} else {
leftPath.lineTo(locX, locY);
}
leftTx.add(locX);
leftTy.add(locY);
}
if (!inAddPointAfterMode && !inAddPointBeforeMode && !inMovePointMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
leftPath.lineTo(locX, locY);
leftTx.add(locX);
leftTy.add(locY);
}
if (inAddPointAfterMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
leftPath.lineTo(locX, locY);
leftTx.add(locX);
leftTy.add(locY);
}
if (leftTx.size() > 1) {
calculatePath(tb, leftTx, leftTy, leftPath);
canvas.drawPath(leftPath, lineAttrs.paint);
}
if (inAddPointBeforeMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
rightPath.moveTo(locX, locY);
rightTx.add(locX);
rightTy.add(locY);
}
if (inAddPointAfterMode) {
WptPt pt = drawPoints.get(selectedPointPos + 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
rightPath.moveTo(locX, locY);
rightTx.add(locX);
rightTy.add(locY);
}
if (!inAddPointAfterMode && !inAddPointBeforeMode && !inMovePointMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
rightPath.moveTo(locX, locY);
rightTx.add(locX);
rightTy.add(locY);
}
for (int i = selectedPointPos + 1; i < drawPoints.size(); i++) {
WptPt pt = drawPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (inMovePointMode && i == selectedPointPos + 1) {
rightPath.moveTo(locX, locY);
} else {
rightPath.lineTo(locX, locY);
}
rightTx.add(locX);
rightTy.add(locY);
}
if (rightTx.size() > 1) {
calculatePath(tb, rightTx, rightTy, rightPath);
canvas.drawPath(rightPath, lineAttrs.paint);
}
}
overlapped = false;
int drawn = 0;
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
if (!(inMovePointMode && i == selectedPointPos)) {
drawn++;
if (drawn > pointsToDraw) {
overlapped = true;
break;
}
}
}
}
if (!overlapped) {
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
if (!(inMovePointMode && i == selectedPointPos)) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
}
}
}
} }
} }
@ -437,129 +268,78 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
measureDistanceToCenterListener.onMeasure(distance); measureDistanceToCenterListener.onMeasure(distance);
} }
} }
List<WptPt> drawPoints; List<WptPt> drawPoints;
if (snappedToRoadPoints.size() > 0) { if (snappedToRoadPoints.size() > 0) {
drawPoints = snappedToRoadPoints; drawPoints = snappedToRoadPoints;
} else { } else {
drawPoints = measurementPoints; drawPoints = measurementPoints;
} }
if (drawPoints.size() > 0) {
if (inMovePointMode || inAddPointBeforeMode || inAddPointAfterMode) {
centerPath.reset();
centerTx.reset();
centerTy.reset();
if (selectedPointPos == 0) { if (drawPoints.size() > 0) {
if (inMovePointMode) { path.reset();
centerPath.moveTo(tb.getCenterPixelX(), tb.getCenterPixelY()); tx.reset();
centerTx.add(tb.getCenterPixelX()); ty.reset();
centerTy.add(tb.getCenterPixelY());
if (drawPoints.size() > 1) { WptPt pt = drawPoints.get(drawPoints.size() - 1);
WptPt pt = drawPoints.get(selectedPointPos + 1); int locX = tb.getPixXFromLonNoRot(pt.lon);
int locX = tb.getPixXFromLonNoRot(pt.lon); int locY = tb.getPixYFromLatNoRot(pt.lat);
int locY = tb.getPixYFromLatNoRot(pt.lat); path.moveTo(locX, locY);
centerPath.lineTo(locX, locY); tx.add(locX);
centerTx.add(locX); ty.add(locY);
centerTy.add(locY); path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
} tx.add(tb.getCenterPixelX());
} else if (inAddPointAfterMode) { ty.add(tb.getCenterPixelY());
WptPt pt = drawPoints.get(selectedPointPos); calculatePath(tb, tx, ty, path);
int locX = tb.getPixXFromLonNoRot(pt.lon); canvas.drawPath(path, lineAttrs.paint);
int locY = tb.getPixYFromLatNoRot(pt.lat); }
centerPath.moveTo(locX, locY);
centerTx.add(locX); overlapped = false;
centerTy.add(locY); int drawn = 0;
centerPath.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY()); for (int i = 0; i < measurementPoints.size(); i++) {
centerTx.add(tb.getCenterPixelX()); WptPt pt = measurementPoints.get(i);
centerTy.add(tb.getCenterPixelY()); int locX = tb.getPixXFromLonNoRot(pt.lon);
} else if (inAddPointBeforeMode) { int locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.moveTo(tb.getCenterPixelX(), tb.getCenterPixelY()); if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
centerTx.add(tb.getCenterPixelX()); if (!(inMovePointMode && i == selectedPointPos)) {
centerTy.add(tb.getCenterPixelY()); drawn++;
WptPt pt = drawPoints.get(selectedPointPos); if (drawn > pointsToDraw) {
int locX = tb.getPixXFromLonNoRot(pt.lon); overlapped = true;
int locY = tb.getPixYFromLatNoRot(pt.lat); break;
centerPath.moveTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
}
} else {
if (inMovePointMode) {
WptPt pt = drawPoints.get(selectedPointPos - 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.moveTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
centerPath.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
centerTx.add(tb.getCenterPixelX());
centerTy.add(tb.getCenterPixelY());
if (selectedPointPos != drawPoints.size() - 1) {
pt = drawPoints.get(selectedPointPos + 1);
locX = tb.getPixXFromLonNoRot(pt.lon);
locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.lineTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
}
} else if (inAddPointAfterMode) {
WptPt pt = drawPoints.get(selectedPointPos);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.moveTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
centerPath.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
centerTx.add(tb.getCenterPixelX());
centerTy.add(tb.getCenterPixelY());
if (selectedPointPos != drawPoints.size() - 1) {
pt = drawPoints.get(selectedPointPos + 1);
locX = tb.getPixXFromLonNoRot(pt.lon);
locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.lineTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
}
} else if (inAddPointBeforeMode) {
WptPt pt = drawPoints.get(selectedPointPos - 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.moveTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
centerPath.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
centerTx.add(tb.getCenterPixelX());
centerTy.add(tb.getCenterPixelY());
pt = drawPoints.get(selectedPointPos);
locX = tb.getPixXFromLonNoRot(pt.lon);
locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.lineTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
} }
} }
calculatePath(tb, centerTx, centerTy, centerPath);
canvas.drawPath(centerPath, lineAttrs.paint);
} else {
centerPath.reset();
centerTx.reset();
centerTy.reset();
WptPt pt = drawPoints.get(drawPoints.size() - 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
centerPath.moveTo(locX, locY);
centerTx.add(locX);
centerTy.add(locY);
centerPath.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
centerTx.add(tb.getCenterPixelX());
centerTy.add(tb.getCenterPixelY());
calculatePath(tb, centerTx, centerTy, centerPath);
canvas.drawPath(centerPath, lineAttrs.paint);
} }
} }
if (overlapped) {
WptPt pt = measurementPoints.get(0);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
if (!(inMovePointMode && 0 == selectedPointPos)) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
pt = measurementPoints.get(measurementPoints.size() - 1);
locX = tb.getPixXFromLonNoRot(pt.lon);
locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
if (!(inMovePointMode && measurementPoints.size() - 1 == selectedPointPos)) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
} else {
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
if (!(inMovePointMode && i == selectedPointPos)) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
}
}
if (inAddPointAfterMode || inAddPointBeforeMode || inMovePointMode) { if (inAddPointAfterMode || inAddPointBeforeMode || inMovePointMode) {
int locX = tb.getCenterPixelX(); int locX = tb.getCenterPixelX();
int locY = tb.getCenterPixelY(); int locY = tb.getCenterPixelY();