Example usage for android.support.v4.view ViewCompat canScrollVertically

List of usage examples for android.support.v4.view ViewCompat canScrollVertically

Introduction

In this page you can find the example usage for android.support.v4.view ViewCompat canScrollVertically.

Prototype

public static boolean canScrollVertically(View v, int direction) 

Source Link

Document

Check if this view can be scrolled vertically in a certain direction.

Usage

From source file:com.mobimvp.cliques.ui.fragment.ShotsFragment.java

public boolean canCollectionViewScrollUp() {
    return ViewCompat.canScrollVertically(mListView, -1);
}

From source file:com.sonaive.v2ex.ui.FeedsFragment.java

public boolean canRecyclerViewScrollUp() {
    return ViewCompat.canScrollVertically(mRecyclerView, -1);
}

From source file:de.mrapp.android.bottomsheet.view.DraggableView.java

/**
 * Returns, whether a touch event at a specific position targets a view, which can be scrolled
 * up./*from  ww  w  . j  a  v a  2 s.c o m*/
 *
 * @param x
 *         The horizontal position of the touch event in pixels as a {@link Float} value
 * @param y
 *         The vertical position of the touch event in pixels as a {@link Float} value
 * @param viewGroup
 *         The view group, which should be used to search for scrollable child views, as an
 *         instance of the class {@link ViewGroup}. The view group may not be null
 * @return True, if the touch event targets a view, which can be scrolled up, false otherwise
 */
private boolean isScrollUpEvent(final float x, final float y, @NonNull final ViewGroup viewGroup) {
    int location[] = new int[2];
    viewGroup.getLocationOnScreen(location);

    if (x >= location[0] && x <= location[0] + viewGroup.getWidth() && y >= location[1]
            && y <= location[1] + viewGroup.getHeight()) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View view = viewGroup.getChildAt(i);

            if (ViewCompat.canScrollVertically(view, -1)) {
                return true;
            } else if (view instanceof ViewGroup) {
                return isScrollUpEvent(x, y, (ViewGroup) view);
            }
        }
    }

    return false;
}

From source file:com.example.yourproject.SwipeRefreshRoboListFragment.java

/**
 * Utility method to check whether a {@link ListView} can scroll up from
 * it's current position./*from   w w w  .j  a va2  s  . c  om*/
 * Handles platform version differences, providing backwards compatible
 * functionality where
 * needed.
 */
private static boolean canListViewScrollUp(ListView listView) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine
        // this
        return ViewCompat.canScrollVertically(listView, -1);
    } else {
        // Pre-ICS we need to manually check the first visible item and the
        // child view's top
        // value
        return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0
                || listView.getChildAt(0).getTop() < listView.getPaddingTop());
    }
}

From source file:cc.solart.turbo.TurboRecyclerView.java

/**
 * @return Whether it is possible for the child view of this layout to
 * scroll up. Override this if the child view is a custom view.
 *///from  w w w.j av a2 s. c o  m
private boolean canScrollEnd() {
    return ViewCompat.canScrollVertically(this, 1) || ViewCompat.canScrollHorizontally(this, 1);
}

From source file:com.google.samples.apps.iosched.ui.SessionsFragment.java

public boolean canCollectionViewScrollUp() {
    return ViewCompat.canScrollVertically(mCollectionView, -1);
}

From source file:cn.bingoogolapple.refreshlayout.util.BGARefreshScrollingUtil.java

public static boolean isRecyclerViewToBottom(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null || manager.getItemCount() == 0) {
            return false;
        }/*w w w  .j a v  a2s  .c om*/

        if (manager instanceof LinearLayoutManager) {
            // ?item?
            View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
            if (lastVisibleChild != null
                    && lastVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                if (android.os.Build.VERSION.SDK_INT < 14) {
                    return !(ViewCompat.canScrollVertically(recyclerView, 1) || recyclerView.getScrollY() < 0);
                } else {
                    return !ViewCompat.canScrollVertically(recyclerView, 1);
                }
            }

            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
                BGAStickyNavLayout stickyNavLayout = getStickyNavLayout(recyclerView);
                if (stickyNavLayout != null) {
                    // ?BGAStickyNavLayoutfindLastCompletelyVisibleItemPosition
                    View lastCompletelyVisibleChild = layoutManager
                            .getChildAt(layoutManager.findLastCompletelyVisibleItemPosition());
                    if (lastCompletelyVisibleChild == null) {
                        return true;
                    } else {
                        // 0x1y
                        int[] location = new int[2];
                        lastCompletelyVisibleChild.getLocationOnScreen(location);
                        int lastChildBottomOnScreen = location[1]
                                + lastCompletelyVisibleChild.getMeasuredHeight();
                        stickyNavLayout.getLocationOnScreen(location);
                        int stickyNavLayoutBottomOnScreen = location[1] + stickyNavLayout.getMeasuredHeight();
                        return lastChildBottomOnScreen <= stickyNavLayoutBottomOnScreen;
                    }
                } else {
                    return true;
                }
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;

            int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
            int lastPosition = layoutManager.getItemCount() - 1;
            for (int position : out) {
                if (position == lastPosition) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.ouyangzn.view.DragLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean helpResult = mDragHelper.shouldInterceptTouchEvent(ev);
    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN:
        mDownX = ev.getX();/*from w ww.  jav  a  2s  . co  m*/
        mDownY = ev.getY();
        break;
    }
    if (isHorizontalScrollView(mDraggedView)) {
        boolean intercept = false;
        switch (MotionEventCompat.getActionMasked(ev)) {
        case MotionEvent.ACTION_MOVE:
            if (mDirection == DIRECTION_TOP || mDirection == DIRECTION_BOTTOM) {
                // ?--->support-v4DrawerLayout??
                intercept = mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL, ev.getPointerId(0));
            } else {
                // ?
                if (ev.getX() - mDownX > 0) {
                    // view????,
                    if (mDirection == DIRECTION_LEFE && mDraggedView.getRight() == mRemainDistance) {
                        intercept = true;
                    } else if (mDirection == DIRECTION_RIGHT) {
                        // view????view??
                        intercept = !ViewCompat.canScrollHorizontally(mDraggedView, -1);
                    }
                }
                // 
                else {
                    // view?????,
                    if (mDirection == DIRECTION_RIGHT
                            && (mLayoutWidth - mDraggedView.getLeft()) == mRemainDistance) {
                        intercept = true;
                    } else if (mDirection == DIRECTION_LEFE) {
                        // view???view??
                        intercept = !ViewCompat.canScrollHorizontally(mDraggedView, 1);
                    }
                }
            }
            // ???view
            if (intercept)
                mDragHelper.captureChildView(mDraggedView, ev.getPointerId(0));
            break;
        }
        return helpResult || intercept;
    }
    if (isVerticalScrollView(mDraggedView)) {
        boolean intercept = false;
        switch (MotionEventCompat.getActionMasked(ev)) {
        case MotionEvent.ACTION_MOVE:
            if (mDirection == DIRECTION_LEFE || mDirection == DIRECTION_RIGHT) {
                // ?--->support-v4DrawerLayout??
                intercept = mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_HORIZONTAL, ev.getPointerId(0));
            } else {
                // 
                if (ev.getY() - mDownY > 0) {
                    if (mDirection == DIRECTION_TOP && mDraggedView.getBottom() == mRemainDistance) {
                        intercept = true;
                    } else if (mDirection == DIRECTION_BOTTOM) {
                        intercept = !ViewCompat.canScrollVertically(mDraggedView, -1);
                    }
                }
                // 
                else {
                    // view????
                    if (mDirection == DIRECTION_BOTTOM
                            && (mLayoutHeight - mDraggedView.getBottom()) == mRemainDistance) {
                        intercept = true;
                    } else if (mDirection == DIRECTION_TOP) {
                        // view???view??
                        intercept = !ViewCompat.canScrollVertically(mDraggedView, 1);
                    }
                }
            }
            break;
        }
        Log.d(TAG, "----------onInterceptTouchEvent.return = " + (helpResult || intercept));
        // ???view
        if (intercept)
            mDragHelper.captureChildView(mDraggedView, ev.getPointerId(0));
        return helpResult || intercept;
    }
    return helpResult;
}

From source file:cn.zy.ef.refresh.utils.ScrollingUtil.java

public static boolean isRecyclerViewToBottom(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null || manager.getItemCount() == 0) {
            return false;
        }/*from  www.  j a  v a 2s  .  c  o m*/

        if (manager instanceof LinearLayoutManager) {
            // ?item?
            View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
            if (lastVisibleChild != null
                    && lastVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                if (Build.VERSION.SDK_INT < 14) {
                    return !(ViewCompat.canScrollVertically(recyclerView, 1) || recyclerView.getScrollY() < 0);
                } else {
                    return !ViewCompat.canScrollVertically(recyclerView, 1);
                }
            }

            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
                return true;
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;

            int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
            int lastPosition = layoutManager.getItemCount() - 1;
            for (int position : out) {
                if (position == lastPosition) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.example.administrator.cookman.ui.component.twinklingrefreshlayout.utils.ScrollingUtil.java

public static boolean isRecyclerViewToBottom(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null || manager.getItemCount() == 0) {
            return false;
        }//from   w  w  w .j  av a 2s  .  co m

        if (manager instanceof LinearLayoutManager) {
            // ?item?
            View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
            if (lastVisibleChild != null
                    && lastVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                if (android.os.Build.VERSION.SDK_INT < 14) {
                    return !(ViewCompat.canScrollVertically(recyclerView, 1) || recyclerView.getScrollY() < 0);
                } else {
                    return !ViewCompat.canScrollVertically(recyclerView, 1);
                }
            }

            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
                return true;
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;

            int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
            int lastPosition = layoutManager.getItemCount() - 1;
            for (int position : out) {
                if (position == lastPosition) {
                    return true;
                }
            }
        }
    }
    return false;
}