Java Code Examples for androidx.core.view.ViewCompat#NestedScrollType

The following examples show how to use androidx.core.view.ViewCompat#NestedScrollType . 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: BottomSheetBehaviorGoogleMapsLike.java    From CustomBottomSheetBehavior with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll( CoordinatorLayout coordinatorLayout, V child,
                                    View directTargetChild, View target, int nestedScrollAxes,
                                    @ViewCompat.NestedScrollType int type) {
    mNestedScrolled = false;
    return ( nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL ) != 0;
}
 
Example 2
Source File: NestedScrollAppBarLayout.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull AppBarLayout child,
                           @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed,
                           int dyUnconsumed, @ViewCompat.NestedScrollType int type, @NonNull int[] consumed) {
    super.onNestedScroll(
            coordinatorLayout, child, target,
            dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed);
    bindAppBar(child);
    if (appBarLayout.nestedScrollingListener != null) {
        appBarLayout.nestedScrollingListener.onNestedScrolling();
    }
}
 
Example 3
Source File: BottomNavigationBehavior.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
@Override
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomNavigationView child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, @ViewCompat.NestedScrollType int type) {
    if (dy < 0) {
        showBottomNavigationView(child);
    } else if (dy > 0) {
        hideBottomNavigationView(child);
    }
}
 
Example 4
Source File: FloatingActionsMenuBehavior.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionsMenu child, @NonNull View directTargetChild, @NonNull View target, int nestedScrollAxes, @ViewCompat.NestedScrollType int type) {
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
 
Example 5
Source File: BottomSheetBehaviorGoogleMapsLike.java    From CustomBottomSheetBehavior with Apache License 2.0 4 votes vote down vote up
@Override
public void onNestedPreScroll( CoordinatorLayout coordinatorLayout, V child, View target,
                               int dx, int dy, int[] consumed,
                               @ViewCompat.NestedScrollType int type) {
    View scrollingChild = mNestedScrollingChildRef.get();
    if ( target != scrollingChild ) {
        return;
    }

    mScrollVelocityTracker.recordScroll( dy );

    int currentTop = child.getTop();
    int newTop     = currentTop - dy;

    // Force stop at the anchor - do not go from collapsed to expanded in one scroll
    if (
            ( mLastStableState == STATE_COLLAPSED  &&  newTop < mAnchorPoint )  ||
                    ( mLastStableState == STATE_EXPANDED   &&  newTop > mAnchorPoint )
            ) {
        consumed[1] = dy;
        ViewCompat.offsetTopAndBottom( child, mAnchorPoint - currentTop );
        dispatchOnSlide( child.getTop() );
        mNestedScrolled = true;
        return;
    }

    if ( dy > 0 ) { // Upward
        if ( newTop < mMinOffset ) {
            consumed[1] = currentTop - mMinOffset;
            ViewCompat.offsetTopAndBottom( child, -consumed[1] );
            setStateInternal( STATE_EXPANDED );
        } else {
            consumed[1] = dy;
            ViewCompat.offsetTopAndBottom( child, -dy );
            setStateInternal( STATE_DRAGGING );
        }
    } else if (dy < 0) { // Downward
        if (!ViewCompat.canScrollVertically(target, -1)) {
            if (newTop <= mMaxOffset || mHideable) {
                // Restrict STATE_COLLAPSED if restrictedState is set
                if(mCollapsible==true || (mCollapsible==false && (mAnchorPoint - newTop)>=0)) {
                    consumed[1] = dy;
                    ViewCompat.offsetTopAndBottom(child, -dy);
                    setStateInternal(STATE_DRAGGING);
                }
            } else {
                consumed[1] = currentTop - mMaxOffset;
                ViewCompat.offsetTopAndBottom(child, -consumed[1]);
                setStateInternal(STATE_COLLAPSED);
            }
        }
    }
    dispatchOnSlide(child.getTop());
    mNestedScrolled = true;
}
 
Example 6
Source File: BottomSheetBehaviorGoogleMapsLike.java    From CustomBottomSheetBehavior with Apache License 2.0 4 votes vote down vote up
@Override
public void onStopNestedScroll( CoordinatorLayout coordinatorLayout, V child, View target,
                                @ViewCompat.NestedScrollType int type) {
    if ( child.getTop() == mMinOffset ) {
        setStateInternal( STATE_EXPANDED );
        mLastStableState = STATE_EXPANDED;
        return;
    }
    if ( target != mNestedScrollingChildRef.get()  ||  ! mNestedScrolled ) {
        return;
    }
    int top;
    int targetState;

    // Are we flinging up?
    float scrollVelocity = mScrollVelocityTracker.getScrollVelocity();
    if ( scrollVelocity > mMinimumVelocity) {
        if ( mLastStableState == STATE_COLLAPSED ) {
            // Fling from collapsed to anchor
            top = mAnchorPoint;
            targetState = STATE_ANCHOR_POINT;
        }
        else
        if ( mLastStableState == STATE_ANCHOR_POINT ) {
            // Fling from anchor to expanded
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        }
        else {
            // We are already expanded
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        }
    }
    else
        // Are we flinging down?
        if ( scrollVelocity < -mMinimumVelocity ) {
            if ( mLastStableState == STATE_EXPANDED ) {
                // Fling to from expanded to anchor
                top = mAnchorPoint;
                targetState = STATE_ANCHOR_POINT;
            }
            else if(mCollapsible==true) {
                if (mLastStableState == STATE_ANCHOR_POINT) {
                    // Fling from anchor to collapsed
                    top = mMaxOffset;
                    targetState = STATE_COLLAPSED;
                } else {
                    // We are already collapsed
                    top = mMaxOffset;
                    targetState = STATE_COLLAPSED;
                }
            } else {
                top = mAnchorPoint;
                targetState = STATE_ANCHOR_POINT;
            }
        }
        // Not flinging, just settle to the nearest state
        else {
            // Collapse?
            int currentTop = child.getTop();
            if ( currentTop > mAnchorPoint * 1.25 && mCollapsible==true) { // Multiply by 1.25 to account for parallax. The currentTop needs to be pulled down 50% of the anchor point before collapsing.
                top = mMaxOffset;
                targetState = STATE_COLLAPSED;
            }
            // Expand?
            else
            if ( currentTop < mAnchorPoint * 0.5 ) {
                top = mMinOffset;
                targetState = STATE_EXPANDED;
            }
            // Snap back to the anchor
            else {
                top = mAnchorPoint;
                targetState = STATE_ANCHOR_POINT;
            }
        }

    mLastStableState = targetState;
    if ( mViewDragHelper.smoothSlideViewTo( child, child.getLeft(), top ) ) {
        setStateInternal( STATE_SETTLING );
        ViewCompat.postOnAnimation( child, new SettleRunnable( child, targetState ) );
    } else {
        setStateInternal( targetState );
    }
    mNestedScrolled = false;
}
 
Example 7
Source File: BottomNavigationBehavior.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomNavigationView child, @NonNull View directTargetChild, @NonNull View target, int nestedScrollAxes, @ViewCompat.NestedScrollType int type) {
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}