Android Touch Events Pointer Down

android, touch

Solution

I'm working on pointer stuff myself right now. You want to switch as follows

 switch(event.getAction() & MotionEvent.ACTION_MASK);
     case MotionEvent.ACTION_POINTER_DOWN:

ACTION_DOWN is about the first finger down. ACTION_POINTER_DOWN is about the second finger.

See http://www.vogella.com/articles/AndroidTouch/article.html for a fairly clear description.

Problem

Hi I am trying to detect when 2 fingers are touching the screen: ``` case MotionEvent.ACTION_POINTER_2_DOWN: { twoFing=true; return true; } ``` the problem is that: ``` public static final int ACTION_POINTER_2_DOWN ``` is depreceted, the doc says: *Constant for getActionMasked(): A non-primary pointer has gone down. Use getActionIndex() to retrieve the index of the pointer that changed. The index is encoded in the ACTION_POINTER_INDEX_MASK bits of the unmasked action returned by getAction().* but I don't understand how to use it... How could I detect that there are 2 pointers? ActionUP and DOwn always say there is only one pointer if I try getPointerIndex() thanks a lot EDIT: I post here the full code to be more clear about the problem. My code is working BUT as the ACTION_POINTER_2_DOWN is a deprecated value I want to replace it by something else but I don't know how. ``` @SuppressWarnings("deprecation") public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_DOWN : { Log.i(TAG, "Action Down"); downX = event.getX(0); downY = event.getY(0); return true; } case MotionEvent.ACTION_UP: { upX = event.getX(0); upY = event.getY(0); float deltaX = downX - upX; float deltaY = downY - upY; Log.i(TAG, "Action UP deltaX="+deltaX+", deltaY="+deltaY); // swipe vertical? if(Math.abs(deltaY) > MIN_DISTANCE && twoFing){ twoFing=false; // top or down if(deltaY < 0 ) { if(slide.zoom==1) slide.zoom=0; Log.i(TAG, "Going Down zooming in"); //return true; } if((deltaY > 0) ) { if(slide.zoom==0) slide.zoom=1; Log.i(TAG, "Going up zoomig out"); //return true; } return true; } // swipe horizontal? if(Math.abs(deltaX) > MIN_DISTANCE && !twoFing){ // left or right if(deltaX < 0) { this.slideToTheLeft(); return true; } if(deltaX > 0) { this.slideToTheRight(); return true; } return true; } return false; } case MotionEvent.ACTION_POINTER_2_DOWN: { twoFing=true; //inform that the touch was made with 2 fingers Log.i(TAG, "Action Second pointer down"); return true; } } return false; ``` }

Original source