Add ability to add point on single tap

This commit is contained in:
Alexander Sytnyk 2017-08-08 14:03:04 +03:00
parent 8ffb4688f2
commit ab023859a1
2 changed files with 46 additions and 5 deletions

View file

@ -145,11 +145,14 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
measurementLayer.addPointOnClick(); addPoint(undoBtn, upDownBtn, redoBtn);
enable(undoBtn, upDownBtn); }
disable(redoBtn); });
updateText();
adapter.notifyDataSetChanged(); measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {
@Override
public void onSingleTap() {
addPoint(undoBtn, upDownBtn, redoBtn);
} }
}); });
@ -230,6 +233,17 @@ public class MeasurementToolFragment extends Fragment {
return view; 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) { private void upBtnOnClick(View view, Drawable icon) {
pointsDetailsOpened = true; pointsDetailsOpened = true;
view.findViewById(R.id.points_list_container).setVisibility(View.VISIBLE); view.findViewById(R.id.points_list_container).setVisibility(View.VISIBLE);
@ -396,6 +410,10 @@ public class MeasurementToolFragment extends Fragment {
if (pointsDetailsOpened) { if (pointsDetailsOpened) {
setPreviousMapPosition(); setPreviousMapPosition();
} }
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setOnSingleTapListener(null);
}
} }
private MapActivity getMapActivity() { private MapActivity getMapActivity() {

View file

@ -6,6 +6,7 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.view.MotionEvent;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -40,6 +41,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
private int marginY; private int marginY;
private final TIntArrayList tx = new TIntArrayList(); private final TIntArrayList tx = new TIntArrayList();
private final TIntArrayList ty = new TIntArrayList(); private final TIntArrayList ty = new TIntArrayList();
private OnSingleTapListener singleTapListener;
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
@ -58,6 +60,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
marginX = pointIcon.getWidth() / 2; marginX = pointIcon.getWidth() / 2;
} }
public void setOnSingleTapListener(OnSingleTapListener listener) {
this.singleTapListener = listener;
}
public boolean isInMeasurementMode() { public boolean isInMeasurementMode() {
return inMeasurementMode; return inMeasurementMode;
} }
@ -91,6 +97,19 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
view.refreshMap(); 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 @Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (inMeasurementMode) { if (inMeasurementMode) {
@ -222,4 +241,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
public boolean isObjectClickable(Object o) { public boolean isObjectClickable(Object o) {
return !isInMeasurementMode(); return !isInMeasurementMode();
} }
interface OnSingleTapListener {
void onSingleTap();
}
} }