问题
I have a Input Service and View in it. I need to override some gestures for ExplorationByTouch: e.g.: I want to turn off the double click. Here's a part of code, where I want to do that. Any idea how?
@Override
public boolean onTouchEvent(MotionEvent e) {
final int action = e.getAction();
switch (getActionMasked(action)) {
case MotionEvent.ACTION_DOWN: { // Processing the first touch
// Index of the first pointer always equals to 0
final int firstIndex = 0;
final int identifier = e.getPointerId(firstIndex);
setPressed(true);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
Log.d("Pressed", "Press first finger");
final Stroke firstStroke = Stroke.newInstance("first");
strokes.put(identifier, firstStroke);
firstStroke.append(Point.valueOf(e.getX(), e.getY()));
anotherHandScheme.onFingerTouch();
mainHandScheme.onFingerTouch();
break;
}
case MotionEvent.ACTION_POINTER_DOWN: { // Processing of the second touch
final int index = getActionIndex(action);
final int identifier = e.getPointerId(index);
// We ignore the third and the following touches
if (identifier > 1)
break;
setPressed(true);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
final Stroke secondStroke = Stroke.newInstance("second");
strokes.put(identifier, secondStroke);
secondStroke.append(Point.valueOf(e.getX(index), e.getY(index)));
anotherHandScheme.onFingerTouch();
mainHandScheme.onFingerTouch();
break;
}
case MotionEvent.ACTION_MOVE: {
final Set<Integer> identifiers = strokes.keySet();
for (Integer id : identifiers) {
final int index = e.findPointerIndex(id);
final Point newPoint = Point.valueOf(e.getX(index), e.getY(index));
if (!newPoint.equals(strokes.get(id).lastPoint()))
strokes.get(id).append(newPoint);
}
anotherHandScheme.onFingerMove();
mainHandScheme.onFingerMove();
break;
}
case MotionEvent.ACTION_POINTER_UP: { // Processing of the second touch
final int index = getActionIndex(action);
strokes.remove(e.getPointerId(index));
anotherHandScheme.onFingerGone();
mainHandScheme.onFingerGone();
setPressed(false);
break;
}
case MotionEvent.ACTION_UP:
// All fingers leave the screen surface
strokes.clear();
anotherHandScheme.onFingerGone();
mainHandScheme.onFingerGone();
setPressed(false);
break;
}
return true;
}
来源:https://stackoverflow.com/questions/27933475/override-talkback-gestures