Question

I'm trying to implement an Android multi touch application and I'm observing inconsistent behavior on two different devices (a Samsung Galaxy Ace running Android 2.3.3 and a FairPhone running Android 4.2.2).

Here's the relevant code:

@Override
public boolean onTouchEvent(MotionEvent event){

    int action = MotionEventCompat.getActionMasked(event);
    int index = MotionEventCompat.getActionIndex(event);
    int id = MotionEventCompat.getPointerId(event, index);

    if (action == MotionEvent.ACTION_DOWN || action == MotionEventCompat.ACTION_POINTER_DOWN) {
        Log.d("FOO", "DOWN (" + id + ")");
    } else if (action == MotionEvent.ACTION_UP || action == MotionEventCompat.ACTION_POINTER_UP) {
        Log.d("FOO", "UP (" + id + ")");    
    }

    return true;
}

Using this code and the gesture "Finger 1 down, Finger 2 down, Finger 1 up, Finger 2 up", here's the log output on the Galaxy Ace:

DOWN (0)
DOWN (1)
UP (0)
UP (1)

This what I would have expected. However, here's the output on the FairPhone for the same gesture sequence:

DOWN (0)
DOWN (1)
UP (1)
UP (0)
DOWN (1)
UP (1)

So the FairPhone is emitting some kind of pseudo "ID switch" events that do not correspond to actual gestures.

Is there a way to achieve consistent event streams regardless of Android device and version? Ideally the events should correspond to actual guestures (i.e. no pseudo events).

EDIT: I'd also be happy to at least know what kind of events other Android devices/versions produce, i.e. whether one of these sequences listed above can be regarded as the "correct" one.

Was it helpful?

Solution

Here's a few other things you could try to help diagnose this further:

  1. What moment in time did the switch happen? This could be done by logging not only the ACTION_UP, but also the ACTION_MOVE. Look for sudden jumps.
  2. Look at some of the Historical Data (getHistoricalX(int pointerIndex, int pos). Look to see if there is a sudden jump.
  3. Try removing the MotionEventCompat calls, and just calling the index directly. Nobody uses pre-Eclair anymore, there's no reason to still have the compatibility feature in use.

The bottom line is, however, that the expected behavior is as you saw in the Galaxy Ace. It looks to me like you found a bug in FairPhone. I'm not sure how much work you want to spend debugging it, but you can probably find a way around it if you want to, via the steps I provided above.

OTHER TIPS

This may happen based on OEMs, because it also depends on hardware of the device. How accurately & how it(tuch function) is implemented by OEMs have a great role to play. Beacuse of this we very often find that all device's touch systems are not same according to resopnsiveness, accuracy, smoothness etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top