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
- D/MainActivity: onTouch: Pointer Down 2
- D/MainActivity: onTouch: Pointer Down 3
- D/MainActivity: onTouch: Pointer Up 3
- 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.