How can I maintain a one pointer gesture when explore-by-touch is enabled?

痞子三分冷 提交于 2019-11-29 02:43:10

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!