4

I have made an application which is running perfectly fine on devices below ver 4.0 or we can say ics, but above ics its not working as it have to. In my application i was trying to make multitouch on two buttons simultaneously and it was working perfect below ver 4.0. The value of action_mask was 6 nd 5 on touch and off touch.. whereas in versions above 4.0 its 1, 2, 0. why this?

enter code here

@override
public boolean ontouch(Event ev , MotionEvent event)    
{
    int actionResolved = event.getAction() & MotionEvent.ACTION_MASK;
    int action = paramMotionEvent.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK;
//  int actionShift = paramMotionEvent.getAction() & MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    Log.i("fil", "action resolved" +actionResolved);
    if(i==MotionEvent.ACTION_DOWN)
    {

        Log.i("fil", "action down");
        Log.i("fil", "action down value" +MotionEvent.ACTION_DOWN);
    }


    if(actionResolved == 5);
    {

        Log.i("fil", "action resolved" +actionResolved);
        scannerview1.startAnimation(anim1);
        scannerView2.startAnimation(anim1);




    }   


    if(actionResolved ==6)
            {

            scannerView2.clearAnimation();
            scannerview1.clearAnimation();      
        }


return true;         
}
hemantsb
  • 2,049
  • 2
  • 20
  • 29
  • Just use the enum constants instead and then you don't need to worry about it. e.g. MotionEvent.ACTION_POINTER_2_DOWN – Simon Mar 02 '13 at 06:47
  • 1
    actually i am using action_mask values to perform some specific task. because action_pointer_down is not working as its documentation says. is there any other way to perform different task on different touch events? – hemantsb Mar 02 '13 at 07:31
  • Then please post your code and describe exactly how it's not working in accordance with the documentation. I don't enjoy guessing games. – Simon Mar 02 '13 at 07:59
  • 1
    @Simon i have updated my code here, – hemantsb Mar 02 '13 at 10:19
  • This is what I'm saying. `if(actionResolved ==6)` You should use the constants. Where and how is actionResolved set? – Simon Mar 02 '13 at 10:31
  • i m storing my value of action_mask in it @Simon – hemantsb Mar 02 '13 at 10:36

2 Answers2

1

i have resolved above problem by using pointer ids in action down. but this code is not usable below version 4.0

here is my code

@override
public boolean ontouch(Event ev , MotionEvent event)    
{
    switch (event.getAction() & MotionEvent.ACTION_MASK) 
    {               
        case MotionEvent.ACTION_DOWN:
            Log.i("D3", "pid" +event.getPointerId(0));
            //Log.i("D3", "pid" +event.getPointerId(1));
            if(event.getPointerId(0)==0){

            }
            if(event.getPointerId(0)==1) 
            {
                scannerview1.startAnimation(anim1);
                scannerView2.startAnimation(anim1);
            }
            break;
        case MotionEvent.ACTION_UP:
            scannerView2.clearAnimation();
            scannerview1.clearAnimation();
            break;
    }
    return true;
}
nobalG
  • 4,544
  • 3
  • 34
  • 72
hemantsb
  • 2,049
  • 2
  • 20
  • 29
0

Instead of

if(actionResolved == 5);

Use

if(actionResolved == ACTION_POINTER_1_DOWN);

The constant values may, and do change between API versions.

Also note that MotionEvent.ACTION_MASK is deprecated. You should use 'MotionEvent.ACTION_POINTER_INDEX_MASK' instead.

http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_POINTER_INDEX_MASK

Simon
  • 14,407
  • 8
  • 46
  • 61
  • 1
    ACTION_POINTER_1_DOWN is deprecated, and above code after applying changes is not working. – hemantsb Mar 02 '13 at 11:31
  • I know it's deprecated. If you read the docs, you will see all of the currently supported constants. – Simon Mar 02 '13 at 14:21