Add ability to add point on single tap
This commit is contained in:
parent
8ffb4688f2
commit
ab023859a1
2 changed files with 46 additions and 5 deletions
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue