I have a problem getting X and Y values โโfrom mutlitouch events. Below is the code showing how I get the value when the POINTER_DOWN and POINTER_UP events are fired, however the X and Y values โโseem to mix / duplicate in the POINTER_UP event.
@Override public void onTouchEvent(MotionEvent event) { int id, pointerIndex; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; id = event.getPointerId(pointerIndex); Log.e("Down", ""+id+" "+event.getX(id)+" "+event.getY(id)); break; case MotionEvent.ACTION_POINTER_UP: pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; id = event.getPointerId(pointerIndex); Log.e("UP", ""+id+" "+event.getX(id)+" "+event.getY(id)); break; } super.onTouchEvent(event); }
This usually results in the following lolcat:
E/DOWN (25070): 0 279.60922 279.17447 E/DOWN (25070): 1 513.20044 520.3252 E/DOWN (25070): 2 422.6651 358.72418 E/UP (25070): 0 279.60922 279.17447 E/UP (25070): 1 422.6651 358.72418 E/UP (25070): 2 422.6651 358.72418
Here you can see that the XY location for id 1 is incorrect, instead it displays the values โโof id 2.
Note that no ACTION_CANCEL events are raised. I guess this is wrong with my use of MASKS / ANDING. Any help would be greatly appreciated!
source share