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.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.views.Renderable;
import net.osmand.router.RoutingContext;
import java.util.LinkedHashMap;
@ -24,6 +25,8 @@ public class MeasurementEditingContext {
private TrkSegment afterCacheForSnap;
private boolean inMovePointMode;
private boolean inAddPointBeforeMode;
private boolean inAddPointAfterMode;
private boolean isInSnapToRoadMode;
private ApplicationMode snapToRoadAppMode;
@ -33,10 +36,20 @@ public class MeasurementEditingContext {
public void setBefore(TrkSegment before) {
this.before = before;
addBeforeRenders();
}
public void setAfter(TrkSegment 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() {
@ -51,6 +64,22 @@ public class MeasurementEditingContext {
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) {
isInSnapToRoadMode = inSnapToRoadMode;
}
@ -93,11 +122,11 @@ public class MeasurementEditingContext {
// return beforeCacheForSnap;
// }
// calculate beforeCacheForSnap
return null;
return before;
}
public TrkSegment getAfterTrkSegmentLine() {
return null;
return after;
}
public void scheduleRouteCalculateIfNotEmpty() {

View file

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

View file

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