Skip to content Skip to sidebar Skip to footer

How Can I Maintain A One Pointer Gesture When Explore-by-touch Is Enabled?

I have a custom view that captures the user's signature (John Hancock). I want our application to be as accessible as possible, so I'm taking special care to ensure to optimize our

Solution 1:

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);
    }

    returnfalse;
}

Post a Comment for "How Can I Maintain A One Pointer Gesture When Explore-by-touch Is Enabled?"