I have some situation here, I have one screen and when I touch on it drawing a dot on this coordinates, problem is that I want to draw second dot on the same line x or y it depend if we touch under the dot or next to it? Have you got any ideas about that?
Here is my drawing method at the moment:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
points.add(new MapPoint(event.getX(), event.getY()));
if (surfaceHolder.getSurface().isValid()) {
canvas = surfaceHolder.lockCanvas();
canvas.drawColor(Color.WHITE);
for (MapPoint point : points) {
canvas.drawCircle(point.getX(), point.getY(), 10, paint);
}
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
return false;
}
This is what I am trying to do, but my problem now is that if I find any point with this coord it draws near the point not on the touched place:
public void addPoint(float x, float y){
if(points.size() < 1) {
points.add(new MapPoint(x, y));
} else {
float deltaX = Math.abs(x - points.get(points.size() - 1).getX());
float deltaY = Math.abs(y - points.get(points.size() - 1).getY());
for (int i = 0; i < points.size(); i++) {
if(Math.max(deltaX , deltaY) == deltaX){
y = points.get(i).getY();
}else{
x = points.get(i).getX();
}
}
points.add(new MapPoint(x, y));
}
}