I am trying to draw a shape on the map in android. If the user draws a closed path, its fine. If the User draws a open path, then how do I close the path to make it look better?
Please see the image,
Here I have drew an open path.
As soon as the onTouch action is ACTION_UP, it the path should get closed by itself,
like this,
Is there any way to do this? I have refereed this, How to draw a closed curved shape? , but it didn't help me.
This is my code,
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
Log.d("","OnTouch");
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
drawable.invalidate();
downx=upx;
downy=upy;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
Please suggest me. I am not completely aware of this canvas drawing.
Any help is appreciated.