Java Code Examples for android.view.ViewGroup#dispatchTouchEvent()

The following examples show how to use android.view.ViewGroup#dispatchTouchEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverlayPanelEventFilter.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}
 
Example 2
Source File: OverlayPanelEventFilter.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}
 
Example 3
Source File: OverlayPanelEventFilter.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Propagates the given {@link MotionEvent} to the {@link ContentViewCore}.
 * @param e The {@link MotionEvent} to be propagated.
 */
protected void propagateEventToContentViewCore(MotionEvent e) {
    MotionEvent event = e;
    int action = event.getActionMasked();
    boolean isSyntheticEvent = false;
    if (mGestureOrientation == GestureOrientation.HORIZONTAL && !mPanel.isMaximized()) {
        // Ignores multitouch events to prevent the Content View from scrolling.
        if (action == MotionEvent.ACTION_POINTER_UP
                || action == MotionEvent.ACTION_POINTER_DOWN) {
            return;
        }

        // NOTE(pedrosimonetti): Lock horizontal motion, ignoring all vertical changes,
        // when the Panel is not maximized. This is to prevent the Content View
        // from scrolling when side swiping on the expanded Panel. Also, note that the
        // method {@link OverlayPanelEventFilter#lockEventHorizontallty} will always
        // return an event with a single pointer, which is necessary to prevent
        // the app from crashing when the motion involves multiple pointers.
        // See: crbug.com/486901
        event = MotionEvent.obtain(
                e.getDownTime(),
                e.getEventTime(),
                // NOTE(pedrosimonetti): Use getActionMasked() to make sure we're not
                // send any pointer information to the event, given that getAction()
                // may have the pointer Id associated to it.
                e.getActionMasked(),
                e.getX(),
                mInitialEventY,
                e.getMetaState());

        isSyntheticEvent = true;
    }

    final float contentViewOffsetXPx = mPanel.getContentX() / mPxToDp;
    final float contentViewOffsetYPx = mPanel.getContentY() / mPxToDp;

    // Adjust the offset to be relative to the Content View.
    event.offsetLocation(-contentViewOffsetXPx, -contentViewOffsetYPx);

    // Get the container view to propagate the event to.
    ContentViewCore cvc = mPanel.getContentViewCore();
    ViewGroup containerView = cvc == null ? null : cvc.getContainerView();

    boolean wasEventCanceled = false;
    if (mWasActionDownEventSynthetic && action == MotionEvent.ACTION_UP) {
        float deltaX = event.getX() - mSyntheticActionDownX;
        float deltaY = event.getY() - mSyntheticActionDownY;
        // NOTE(pedrosimonetti): If the ACTION_DOWN event was synthetic and the distance
        // between it and the ACTION_UP event was short, then we should synthesize an
        // ACTION_CANCEL event to prevent a Tap gesture from being triggered on the
        // Content View. See crbug.com/408654
        if (!isDistanceGreaterThanTouchSlop(deltaX, deltaY)) {
            event.setAction(MotionEvent.ACTION_CANCEL);
            if (containerView != null) containerView.dispatchTouchEvent(event);
            wasEventCanceled = true;
        }
    } else if (action == MotionEvent.ACTION_DOWN) {
        mPanel.onTouchSearchContentViewAck();
    }

    if (!wasEventCanceled && containerView != null) containerView.dispatchTouchEvent(event);

    // Synthetic events should be recycled.
    if (isSyntheticEvent) event.recycle();
}