Java Code Examples for androidx.coordinatorlayout.widget.CoordinatorLayout#isPointInChildBounds()

The following examples show how to use androidx.coordinatorlayout.widget.CoordinatorLayout#isPointInChildBounds() . 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: BaseTransientBottomBar.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public void onInterceptTouchEvent(
    @NonNull CoordinatorLayout parent, @NonNull View child, @NonNull MotionEvent event) {
  switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
      // We want to make sure that we disable any Snackbar timeouts if the user is
      // currently touching the Snackbar. We restore the timeout when complete
      if (parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY())) {
        SnackbarManager.getInstance().pauseTimeout(managerCallback);
      }
      break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
      SnackbarManager.getInstance().restoreTimeoutIfPaused(managerCallback);
      break;
    default:
      break;
  }
}
 
Example 2
Source File: SwipeDismissBehavior.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(
    @NonNull CoordinatorLayout parent, @NonNull V child, @NonNull MotionEvent event) {
  boolean dispatchEventToHelper = interceptingEvents;

  switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
      interceptingEvents =
          parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY());
      dispatchEventToHelper = interceptingEvents;
      break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
      // Reset the ignore flag for next times
      interceptingEvents = false;
      break;
  }

  if (dispatchEventToHelper) {
    ensureViewDragHelper(parent);
    return viewDragHelper.shouldInterceptTouchEvent(event);
  }
  return false;
}
 
Example 3
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, SnackbarLayout child,
                                     MotionEvent event) {


    if (parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY())) {
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                SnackbarManager.getInstance()
                        .cancelTimeout(mManagerCallback);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                SnackbarManager.getInstance()
                        .restoreTimeout(mManagerCallback);
                break;
        }
    }

    return super.onInterceptTouchEvent(parent, child, event);
}
 
Example 4
Source File: BottomSheetBehavior.java    From bottomsheetrecycler with Apache License 2.0 5 votes vote down vote up
private boolean isPointInsideChildScrollView(CoordinatorLayout parent, int x, int y) {
    if (mNestedScrollingChildRefList == null) {
        return false;
    }

    for (View child : mNestedScrollingChildRefList) {
        if (child != null && parent.isPointInChildBounds(child, x, y)) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: BottomSheetBehavior.java    From bottomsheetrecycler with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        ignoreEvents = true;
        return false;
    }
    int action = event.getActionMasked();
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }
    velocityTracker.addMovement(event);
    switch (action) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            touchingScrollingChild = false;
            activePointerId = MotionEvent.INVALID_POINTER_ID;
            // Reset the ignore flag
            if (ignoreEvents) {
                ignoreEvents = false;
                return false;
            }
            break;
        case MotionEvent.ACTION_DOWN:
            int initialX = (int) event.getX();
            initialY = (int) event.getY();
            // Only intercept nested scrolling events here if the view not being moved by the
            // ViewDragHelper.
            if (mNestedScrollingChildRefList != null) {
                for (View childView : mNestedScrollingChildRefList) {
                    if (childView != null && parent.isPointInChildBounds(childView, initialX, initialY)) {
                        activePointerId = event.getPointerId(event.getActionIndex());
                        touchingScrollingChild = true;
                    }
                }
            }
            ignoreEvents =
                    activePointerId == MotionEvent.INVALID_POINTER_ID
                            && !parent.isPointInChildBounds(child, initialX, initialY);
            break;
        default: // fall out
    }
    if (!ignoreEvents
            && viewDragHelper != null
            && viewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    //View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
    return action == MotionEvent.ACTION_MOVE
            && !ignoreEvents
            && state != STATE_DRAGGING
            && !isPointInsideChildScrollView(parent, (int) event.getX(), (int) event.getY())
            && viewDragHelper != null
            && Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
}