When Explore by Touch is turned on, single-finger touch events are converted into hover events. You can watch these events by adding an OnHoverListener to your view or overriding View.onHoverEvent.
Once you're intercepting these events, you can usually just pass them to your normal touch handling code and map from hover actions to touch actions (as below).
@Override
public boolean onHoverEvent(MotionEvent event) {
if (mAccessibilityManager.isTouchExplorationEnabled()) {
return onTouchEvent(event);
} else {
return super.onHoverEvent(event);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_HOVER_ENTER:
return handleDown(event);
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_HOVER_MOVE:
return handleMove(event);
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_HOVER_EXIT:
return handleUp(event);
}
return false;
}