Reputation: 3235
If there are multiple fingers on the device, does the onTouch-listener run once for every finger, or it runs once per event(finger down, move, etc..) and include every active touch pointer?
And if
(e.getAction() & MotionEvent.ACTION_MASK == MotionEvent.ACTION_MOVE)
how do I know which pointer is moving currently?
final int pointerIndex = e.getActionIndex();
pointerID = e.getPointerId(pointerIndex);
Always gives back 0(while MotionEvent.ACTION_MOVE) for some reason..
Upvotes: 2
Views: 493
Reputation: 4165
First, you get these events:
MotionEvent.ACTION_DOWN
MotionEvent.ACTION_POINTER_DOWN
MotionEvent.ACTION_UP
MotionEvent.ACTION_POINTER_UP
MotionEvent.ACTION_MOVE
do it like this:
@Override
public boolean onTouchEvent(MotionEvent ev)
{
final int action = ev.getAction();
final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; //index of this pointer
switch (action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
//your first touch on the screen
break;
case MotionEvent.ACTION_MOVE:
//one of the touches has moved
for (unsigned int i = 0; i < ev.getPointerCount(); i++)
{
//The pointer id is ev.getPointerId(i);
//for loop through all touches
}
break;
case MotionEvent.ACTION_UP:
//your last touch has gone up
break;
case MotionEvent.ACTION_POINTER_DOWN:
//non-primary pointer has gone down
break;
case MotionEvent.ACTION_POINTER_UP:
//non-primary pointer has gone up
break;
}
}
return true;
}
I hope this helps you a little bit :)
Upvotes: 3