Search code examples
androidmulti-touchtalkback

Detect multitouch in explore by touch mode


I am writting an app with blind support. I need to detect two-fingers touch. When any accessibility features are off I try to use TouchListener:

 RelativeLayout rl = (RelativeLayout) findViewById(R.id.main);
    rl.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // get masked (not specific to a pointer) action
            int maskedAction = event.getActionMasked();

            Log.d(TAG, "onTouch: " + actionToString(maskedAction) + " " + event.getPointerCount());

            return true;
        }
    });


}

// Given an action int, returns a string description
public static String actionToString(int action) {
    switch (action) {

        case MotionEvent.ACTION_DOWN: return "Down";
        case MotionEvent.ACTION_MOVE: return "Move";
        case MotionEvent.ACTION_POINTER_DOWN: return "Pointer Down";
        case MotionEvent.ACTION_UP: return "Up";
        case MotionEvent.ACTION_POINTER_UP: return "Pointer Up";
        case MotionEvent.ACTION_OUTSIDE: return "Outside";
        case MotionEvent.ACTION_CANCEL: return "Cancel";
    }
    return "";
}

and I get

  1. D/MainActivity: onTouch: Pointer Down 2
  2. D/MainActivity: onTouch: Pointer Down 3
  3. D/MainActivity: onTouch: Pointer Up 3
  4. D/MainActivity: onTouch: Pointer Up 2

Everything is fine. But when I switch on TalkBack I get multitouch event very rarely. It means I need to repeat the same gesture a few times, but I get any log only once.

Can someone provide my with any hint. Tanks a lot.

P.S. It may be useful. There are gestures I need to implement - tap with two fingers, double tap with to fingers, long tap with two fingers and swipes with two fingers. But swipes works fine because they are already overwritten by default in TalkBack.


Solution

  • After looking more deeply on that issue and I still have it, it seems we can't track two pointers in Touch to Explore feature of TalkBack!

    If you checked my question and the answer of it, you'll see the event which is fired when you activate Touch to Explore feature of TalkBack and make a touch on a view is onHoverEvent.

    This event is just handle one pointer and you can track it using MotionEvent.ACTION_HOVER_ENTER, MotionEvent.ACTION_HOVER_MOVE, and MotionEvent.ACTION_HOVER_EXIT.

    There's no other pointer like ACTION_HOVER_POINTER_EXIT.

    I hope if someone has any solutions around to share with us.