@Override
    public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
        if (child.getTop() == mMinOffset) {
            setStateInternal(STATE_EXPANDED);
            return;
        }
        if (mNestedScrollingChildRef == null || target != mNestedScrollingChildRef.get()
                || !mNestedScrolled) {
            return;
        }

        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        float xVel = mVelocityTracker.getXVelocity(mActivePointerId);
        float yVel = mVelocityTracker.getYVelocity(mActivePointerId);

        int top;
        int targetState;
        if (yVel < 0 && Math.abs(yVel) > mMinimumVelocity && Math.abs(yVel) > Math.abs(xVel)) {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        } else if (mHideable && shouldHide(child, yVel)) {
            top = mParentHeight;
            targetState = STATE_HIDDEN;
        } else if (yVel > 0 && Math.abs(yVel) > mMinimumVelocity && Math.abs(yVel) > Math.abs(xVel)) {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        } else {
            // not scrolling much, i.e. stationary
            int currentTop = child.getTop();
            if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
                top = mMinOffset;
                targetState = STATE_EXPANDED;
            } else {
                top = mMaxOffset;
                targetState = STATE_COLLAPSED;
            }
        }

        if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
            setStateInternal(STATE_SETTLING);
            ViewCompat.postOnAnimation(child, new SettleRunnable(child, targetState));
        } else {
            setStateInternal(targetState);
        }
        mNestedScrolled = false;
    }
Default constructor for inflating ViewPagerBottomSheetBehaviors from layout.

@param context The {@link Context}.
@param attrs   The {@link AttributeSet}.
vpbs/src/main/java/biz/laenger/android/vpbs/ViewPagerBottomSheetBehavior.java