Reputation: 4103
I am developing a Face Detection app. In this app, I have to draw circles nearby the eyes and mouth of the face and the user can click to drag circles for setting the position of the same according to him on the detected face. So, all circles have been drawn successfully on the face but I can't able to click on the particular circle and move on throughout the face with zoom out option. Please suggest me for the right solution regarding the same.
Thanks in advance.
Upvotes: 5
Views: 3542
Reputation: 573
Here is an example I used for rectangles. See if you can adjust the code to use circles instead.
@Override
public boolean onTouchEvent( MotionEvent event) {
super.onTouchEvent(event);
int x = (int)event.getX();
int y = (int)event.getY();
xStored = x; yStored=y;
if (event.getAction()==MotionEvent.ACTION_UP){
}else if(event.getAction()==MotionEvent.ACTION_DOWN){
System.out.println("Touching down!");
for(Rect rect : rectangles){
if(rect.contains(x,y)){
System.out.println("Touched Rectangle, start activity."+x+","+y);
invalidate();
}else{
}
}
}else if(event.getAction()==MotionEvent.ACTION_MOVE){
}
this.postInvalidate();
return true;
}
Upvotes: 2
Reputation: 5725
Math.sqrt(Math.pow(clickX - centerX, 2) + Math.pow(clickY - centerY, 2));
Calculate the distance between the center of your point and the touch event - if the distance is smaller than the radius of your circle - you pressed on the circle
Upvotes: 6