From ab023859a1f4289e1d4753e6415cea19fec0711c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 8 Aug 2017 14:03:04 +0300 Subject: [PATCH] Add ability to add point on single tap --- .../MeasurementToolFragment.java | 28 +++++++++++++++---- .../measurementtool/MeasurementToolLayer.java | 23 +++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index ff0254940d..72f5d87590 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -145,11 +145,14 @@ public class MeasurementToolFragment extends Fragment { mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - measurementLayer.addPointOnClick(); - enable(undoBtn, upDownBtn); - disable(redoBtn); - updateText(); - adapter.notifyDataSetChanged(); + addPoint(undoBtn, upDownBtn, redoBtn); + } + }); + + measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() { + @Override + public void onSingleTap() { + addPoint(undoBtn, upDownBtn, redoBtn); } }); @@ -230,6 +233,17 @@ public class MeasurementToolFragment extends Fragment { return view; } + private void addPoint(View undoBtn, View upDownBtn, View redoBtn) { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.addPointOnClick(); + enable(undoBtn, upDownBtn); + disable(redoBtn); + updateText(); + adapter.notifyDataSetChanged(); + } + } + private void upBtnOnClick(View view, Drawable icon) { pointsDetailsOpened = true; view.findViewById(R.id.points_list_container).setVisibility(View.VISIBLE); @@ -396,6 +410,10 @@ public class MeasurementToolFragment extends Fragment { if (pointsDetailsOpened) { setPreviousMapPosition(); } + MeasurementToolLayer layer = getMeasurementLayer(); + if (layer != null) { + layer.setOnSingleTapListener(null); + } } private MapActivity getMapActivity() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 722b59b5b2..63b80cc6dc 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -6,6 +6,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PointF; +import android.view.MotionEvent; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -40,6 +41,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private int marginY; private final TIntArrayList tx = new TIntArrayList(); private final TIntArrayList ty = new TIntArrayList(); + private OnSingleTapListener singleTapListener; @Override public void initLayer(OsmandMapTileView view) { @@ -58,6 +60,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL marginX = pointIcon.getWidth() / 2; } + public void setOnSingleTapListener(OnSingleTapListener listener) { + this.singleTapListener = listener; + } + public boolean isInMeasurementMode() { return inMeasurementMode; } @@ -91,6 +97,19 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL view.refreshMap(); } + @Override + public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { + if (inMeasurementMode && singleTapListener != null) { + singleTapListener.onSingleTap(); + } + return false; + } + + @Override + public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { + return super.onTouchEvent(event, tileBox); + } + @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { if (inMeasurementMode) { @@ -222,4 +241,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL public boolean isObjectClickable(Object o) { return !isInMeasurementMode(); } + + interface OnSingleTapListener { + void onSingleTap(); + } }