The button is drawn on the canvas via onDraw
. In the following method I am getting the location of the drawn button and detecting a touch inside it. Once it is sensed snapShot();
is called. I've replaced the content of snapShot();
with System.out.println("snapShot(); is called");
. Every touch I constantly get four lines printed out. I don't understand how this method is calling snapShot() for times in a row?
public boolean onTouch(View view, MotionEvent me) {
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.camera);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int w = metrics.widthPixels;
int h = metrics.heightPixels;
int heightOffset = - bitmap.getHeight() + h;
int widthOffset = w - bitmap.getWidth();
//See if the motion event is on a Marker
if((me.getRawX() >= widthOffset && me.getRawX() < (widthOffset + bitmap.getWidth())
&& me.getRawY() >= heightOffset && me.getRawY() < (heightOffset + bitmap.getHeight())))
{
snapShot();
return true;
}
return super.onTouchEvent(me);
};