I draw a shapedrawables on a canvas and I want to detect on touch event what shapes has been touched. without calculating by (x,y), just automatically as exists in html.. Thanks! :)
I succeeded to draw the shapes, and read a lot about how I can detect ontouch by calculating with (x,y), but it's not clever to do that if I have the possibility to detect the touched shapes automatically. If I can't do that with a canvas I will be glad to hear how can I draw shapes and detect touched shapes with another widgets in android.
public class CanvasView extends View implements View.OnTouchListener
{
private List<ShapeDrawable> shapes;
private ShapeDrawable currentCircle;
public CanvasViewenter code here(Context context, @Nullable AttributeSet attrs)
{
super(context, attrs);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
this.shapes = new ArrayList<>();
}
@Override
protected void onDraw(final Canvas canvas)
{
super.onDraw(canvas);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
//here I want to get all the shapes that have been touched
List<ShapeDrawable> touchedShapes = null;
return true;
}
}