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

The following examples show how to use androidx.core.view.ViewCompat#TYPE_TOUCH . 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: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 6 votes vote down vote up
@Override
public void onStopNestedScroll(@NonNull View target, int type) {
    if (sDebug) {
        Log.d(TAG, String.format("onStopNestedScroll() type: %d", type));
    }
    mNestedScrollingParentHelper.onStopNestedScroll(target, type);
    if (mLastNestedType == type) {
        mNestedScrolling = false;
    }
    mNestedTouchScrolling = false;
    mIsInterceptTouchEventInOnceTouch = isNeedInterceptTouchEvent();
    mIsLastOverScrollCanNotAbort = isCanNotAbortOverScrolling();
    // Dispatch up our nested parent
    getScrollingChildHelper().stopNestedScroll(type);
    if (!isAutoRefresh() && type == ViewCompat.TYPE_TOUCH) {
        mIndicatorSetter.onFingerUp();
        onFingerUp();
    }
    onNestedScrollChanged(true);
}
 
Example 2
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStopNestedScroll(
    CoordinatorLayout coordinatorLayout, @NonNull T abl, View target, int type) {
  // onStartNestedScroll for a fling will happen before onStopNestedScroll for the scroll. This
  // isn't necessarily guaranteed yet, but it should be in the future. We use this to our
  // advantage to check if a fling (ViewCompat.TYPE_NON_TOUCH) will start after the touch scroll
  // (ViewCompat.TYPE_TOUCH) ends
  if (lastStartedType == ViewCompat.TYPE_TOUCH || type == ViewCompat.TYPE_NON_TOUCH) {
    // If we haven't been flung, or a fling is ending
    snapToChildIfNeeded(coordinatorLayout, abl);
    if (abl.isLiftOnScroll()) {
      abl.setLiftedState(abl.shouldLift(target));
    }
  }

  // Keep a reference to the previous nested scrolling child
  lastNestedScrollingChildRef = new WeakReference<>(target);
}
 
Example 3
Source File: NestedScrollAppBarLayout.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child,
                                   View directTargetChild, View target, int nestedScrollAxes, int type) {
    if (super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type)
            && type == ViewCompat.TYPE_TOUCH) {
        bindAppBar(child);
        if (appBarLayout.nestedScrollingListener != null) {
            appBarLayout.nestedScrollingListener.onStartNestedScroll();
        }
        appBarLayout.stopScrollAnimator();
        appBarLayout.setStartY(child.getY());
        return true;
    } else {
        return false;
    }
}
 
Example 4
Source File: FabScrollBehavior.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
                                   @NonNull FloatingActionButton child,
                                   @NonNull View directTargetChild,
                                   @NonNull View target, int axes, int type) {
    // Ensure we react to vertical scrolling
    return type == ViewCompat.TYPE_TOUCH && axes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
 
Example 5
Source File: FabScrollBehavior.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout,
                                   @NonNull FloatingActionButton child,
                                   @NonNull View directTargetChild,
                                   @NonNull View target, int axes, int type) {
    // Ensure we react to vertical scrolling
    return type == ViewCompat.TYPE_TOUCH && axes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
 
Example 6
Source File: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
public void onNestedScrollAccepted(
        @NonNull View child, @NonNull View target, int axes, int type) {
    if (sDebug) {
        Log.d(TAG, String.format("onNestedScrollAccepted(): axes: %d, type: %d", axes, type));
    }
    // Reset the counter of how much leftover scroll needs to be consumed.
    mNestedScrollingParentHelper.onNestedScrollAccepted(child, target, axes, type);
    // Dispatch up to the nested parent
    startNestedScroll(axes & getNestedScrollAxes(), type);
    mNestedTouchScrolling = type == ViewCompat.TYPE_TOUCH;
    mLastNestedType = type;
    mNestedScrolling = true;
}
 
Example 7
Source File: SwipeSwitchLayout.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int axes, int type) {
    return (axes & ViewCompat.SCROLL_AXIS_HORIZONTAL) != 0
            && switchListener != null
            && type == ViewCompat.TYPE_TOUCH
            && isEnabled();
}
 
Example 8
Source File: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 4 votes vote down vote up
@Override
public void onNestedPreScroll(
        @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
    final boolean isVerticalOrientation = isVerticalOrientation();
    if (type == ViewCompat.TYPE_TOUCH) {
        if (tryToFilterTouchEvent(null)) {
            if (isVerticalOrientation) {
                consumed[1] = dy;
            } else {
                consumed[0] = dx;
            }
        } else {
            mScrollChecker.stop();
            final int distance = isVerticalOrientation ? dy : dx;
            if (distance > 0
                    && !isDisabledRefresh()
                    && !(isEnabledPinRefreshViewWhileLoading() && isRefreshing())
                    && !isNotYetInEdgeCannotMoveHeader()) {
                if (!mIndicator.isAlreadyHere(IIndicator.START_POS) && isMovingHeader()) {
                    mIndicatorSetter.onFingerMove(
                            mIndicator.getLastMovePoint()[0] - dx,
                            mIndicator.getLastMovePoint()[1] - dy);
                    moveHeaderPos(mIndicator.getOffset());
                    if (isVerticalOrientation) {
                        consumed[1] = dy;
                    } else {
                        consumed[0] = dx;
                    }
                } else {
                    if (isVerticalOrientation) {
                        mIndicatorSetter.onFingerMove(
                                mIndicator.getLastMovePoint()[0] - dx,
                                mIndicator.getLastMovePoint()[1]);
                    } else {
                        mIndicatorSetter.onFingerMove(
                                mIndicator.getLastMovePoint()[0],
                                mIndicator.getLastMovePoint()[1] - dy);
                    }
                }
            } else if (distance < 0
                    && !isDisabledLoadMore()
                    && !(isEnabledPinRefreshViewWhileLoading() && isLoadingMore())
                    && !isNotYetInEdgeCannotMoveFooter()) {
                if (!mIndicator.isAlreadyHere(IIndicator.START_POS) && isMovingFooter()) {
                    mIndicatorSetter.onFingerMove(
                            mIndicator.getLastMovePoint()[0] - dx,
                            mIndicator.getLastMovePoint()[1] - dy);
                    moveFooterPos(mIndicator.getOffset());
                    if (isVerticalOrientation) {
                        consumed[1] = dy;
                    } else {
                        consumed[0] = dx;
                    }
                } else {
                    if (isVerticalOrientation) {
                        mIndicatorSetter.onFingerMove(
                                mIndicator.getLastMovePoint()[0] - dx,
                                mIndicator.getLastMovePoint()[1]);
                    } else {
                        mIndicatorSetter.onFingerMove(
                                mIndicator.getLastMovePoint()[0],
                                mIndicator.getLastMovePoint()[1] - dy);
                    }
                }
            }
        }
        tryToResetMovingStatus();
    }
    // Now let our nested parent consume the leftovers
    final int[] parentConsumed = mParentScrollConsumed;
    parentConsumed[0] = 0;
    parentConsumed[1] = 0;
    if (dispatchNestedPreScroll(
            dx - consumed[0], dy - consumed[1], parentConsumed, null, type)) {
        consumed[0] += parentConsumed[0];
        consumed[1] += parentConsumed[1];
    } else if (type == ViewCompat.TYPE_NON_TOUCH) {
        if (!isMovingContent() && !isEnabledPinContentView()) {
            if (isVerticalOrientation) {
                parentConsumed[1] = dy;
            } else {
                parentConsumed[0] = dx;
            }
            consumed[0] += parentConsumed[0];
            consumed[1] += parentConsumed[1];
        }
    }
    if (sDebug) {
        Log.d(
                TAG,
                String.format(
                        "onNestedPreScroll(): dx: %d, dy: %d, consumed: %s, type: %d",
                        dx, dy, Arrays.toString(consumed), type));
    }
}
 
Example 9
Source File: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 4 votes vote down vote up
@Override
public void onNestedScroll(
        @NonNull View target,
        int dxConsumed,
        int dyConsumed,
        int dxUnconsumed,
        int dyUnconsumed,
        int type,
        @NonNull int[] consumed) {
    // Dispatch up to the nested parent first
    dispatchNestedScroll(
            dxConsumed,
            dyConsumed,
            dxUnconsumed,
            dyUnconsumed,
            mParentOffsetInWindow,
            type,
            consumed);
    if (sDebug) {
        Log.d(
                TAG,
                String.format(
                        "onNestedScroll(): dxConsumed: %d, dyConsumed: %d, dxUnconsumed: %d"
                                + " dyUnconsumed: %d, type: %d, consumed: %s",
                        dxConsumed,
                        dyConsumed,
                        dxUnconsumed,
                        dyUnconsumed,
                        type,
                        Arrays.toString(consumed)));
    }
    final boolean isVerticalOrientation = isVerticalOrientation();
    if (isVerticalOrientation) {
        if (dyUnconsumed == 0 || consumed[1] == dyUnconsumed) {
            onNestedScrollChanged(true);
            return;
        }
    } else {
        if (dxUnconsumed == 0 || consumed[0] == dxUnconsumed) {
            onNestedScrollChanged(true);
            return;
        }
    }
    if (type == ViewCompat.TYPE_TOUCH) {
        if (tryToFilterTouchEvent(null)) {
            return;
        }
        final int dx = dxUnconsumed + mParentOffsetInWindow[0] - consumed[0];
        final int dy = dyUnconsumed + mParentOffsetInWindow[1] - consumed[1];
        final int distance = isVerticalOrientation ? dy : dx;
        if (distance < 0
                && !isDisabledRefresh()
                && !isNotYetInEdgeCannotMoveHeader()
                && !(isEnabledPinRefreshViewWhileLoading() && isRefreshing())) {
            mIndicatorSetter.onFingerMove(
                    mIndicator.getLastMovePoint()[0] - dx,
                    mIndicator.getLastMovePoint()[1] - dy);
            moveHeaderPos(mIndicator.getOffset());
            if (isVerticalOrientation) {
                consumed[1] += dy;
            } else {
                consumed[0] += dx;
            }
        } else if (distance > 0
                && !isDisabledLoadMore()
                && !isNotYetInEdgeCannotMoveFooter()
                && !(isDisabledLoadMoreWhenContentNotFull()
                        && !isNotYetInEdgeCannotMoveHeader()
                        && mIndicator.isAlreadyHere(IIndicator.START_POS))
                && !(isEnabledPinRefreshViewWhileLoading() && isLoadingMore())) {
            mIndicatorSetter.onFingerMove(
                    mIndicator.getLastMovePoint()[0] - dx,
                    mIndicator.getLastMovePoint()[1] - dy);
            moveFooterPos(mIndicator.getOffset());
            if (isVerticalOrientation) {
                consumed[1] += dy;
            } else {
                consumed[0] += dx;
            }
        }
        tryToResetMovingStatus();
    }
    if (dxConsumed != 0 || dyConsumed != 0 || consumed[0] != 0 || consumed[1] != 0) {
        onNestedScrollChanged(true);
    }
}
 
Example 10
Source File: SwipeBackCoordinatorLayout.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes, int type) {
    super.onStartNestedScroll(child, target, nestedScrollAxes, type);
    isVerticalDragged = (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
    return type == ViewCompat.TYPE_TOUCH;
}
 
Example 11
Source File: SwipeSwitchLayout.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int axes, int type) {
    return (axes & ViewCompat.SCROLL_AXIS_HORIZONTAL) != 0
            && type == ViewCompat.TYPE_TOUCH
            && isEnabled();
}