public boolean onTouchEvent(final MotionEvent event)
{
final int action = event.getAction();
if(mIsMultiTouchSupported)
{
switch (action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_POINTER_DOWN : {
if(mActivePointerId == -1)
{
final int pind = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
int pid = event.getPointerId(pind);
final int x = (int)event.getX(pid);
final int y = (int)event.getY(pid);
if(pointInArea(x, y))
{
mActivePointerId = pid;
// System.out.println("down pointer x = "+x+" , y = "+y);
onAction(UIAREA_ACTION_DOWN, x, y);
}
}
}
break;
case MotionEvent.ACTION_DOWN: {
if(mActivePointerId == -1)
{
final int x = (int)event.getX();
final int y = (int)event.getY();
if(pointInArea(x, y))
{
mActivePointerId = event.getPointerId(0);
// System.out.println("down x = "+x+" , y = "+y);
onAction(UIAREA_ACTION_DOWN, x, y);
}
}
break;
}
case MotionEvent.ACTION_MOVE: {
if(mActivePointerId != -1)
{
// Find the index of the active pointer and fetch its position
final int pointerIndex = event.findPointerIndex(mActivePointerId);
final int x = (int)event.getX(pointerIndex);
final int y = (int)event.getY(pointerIndex);
onAction(UIAREA_ACTION_MOVE, x, y);
}
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = -1;
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP: {
final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = event.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int x = (int)event.getX(mActivePointerId);
final int y = (int)event.getY(mActivePointerId);
mActivePointerId = -1;
// System.out.println(" up x = "+x+" , y = "+y);
onAction(UIAREA_ACTION_UP, x, y);
}
break;
}
}//end of switch
}
else
{
switch (action)
{
case MotionEvent.ACTION_DOWN: {
final int x = (int)event.getX();
final int y = (int)event.getY();
if(pointInArea(x, y))
{
// System.out.println("down x = "+x+" , y = "+y);
onAction(UIAREA_ACTION_DOWN, x, y);
}
break;
}
case MotionEvent.ACTION_MOVE: {
final int x = (int)event.getX();
final int y = (int)event.getY();
if(pointInArea(x, y))
{
// System.out.println("move x = "+x+" , y = "+y);
onAction(UIAREA_ACTION_MOVE, x, y);
}
break;
}
case MotionEvent.ACTION_CANCEL: {
break;
}
case MotionEvent.ACTION_UP:{
final int x = (int)event.getX();
final int y = (int)event.getY();
onAction(UIAREA_ACTION_UP, x, y);
break;
}
}//end of switch
}
return true;
}