Q:

How to determine whether or not user touch the oval in canvas?

I draw a oval in canvas by following codes and that works fine:
Paint paint = new Paint();
canvas.drawOval(new RectF(10, 10, 300, 100), paint);

When user click on screen, how could I determine whether or not user click within the oval?
Notes: 
When I draw a Rect, I can use Rect.contains(int x, int y) to determine whether user click within it. But now I am drawing a oval.
Thanks in advance!

A:

When you touch the screen you'll get the x and y coordinates. You also can know the center or you oval.
x, y are coordiantes when touched, center_x and center_y are coordinates of the center of the oval. R is the radius.
float dx = Math.abs(x-center_x);
float dy = Math.abs(y-center_y);
float R = radius ;//radius of circle.

boolean checkDistance(float dx,float dy,float R)
{
if(dx>R)
{
return false;//outside
}
else if(dy>R)
{
return false;//
}
else
{
return true;
}
}

Actually this solution is for a circle but you can get a good approximation using it or maybe could open your mind to change this code for your purpose.

