Java Code Examples for androidx.recyclerview.widget.RecyclerView#canScrollVertically()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#canScrollVertically() . 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: BaseAdapter.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {

    if (mScrollingListener == null) {
        return;
    }

    if (newState == RecyclerView.SCROLL_STATE_IDLE) {

        if (!recyclerView.canScrollVertically(1)) {
            //是否能向下滚动,false 表示已经滚动到底部
            mScrollingListener.onScrollDown(recyclerView);
        } else if (!recyclerView.canScrollVertically(-1)) {
            //是否能向上滚动,false 表示已经滚动到顶部
            mScrollingListener.onScrollTop(recyclerView);
        }

    } else if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
        //正在滚动中
        mScrollingListener.onScrolling(recyclerView);
    }
}
 
Example 2
Source File: SimpleScrollListener.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    onScroll();

    if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
        onEnd();
        resetScrollDistance();
    } else {
        if (mScrolledDistance < -HIDE_THRESHOLD) {
            onScrollUp();
            resetScrollDistance();
        }
    }

    if ((dy < 0)) {
        mScrolledDistance += dy;
    }
}
 
Example 3
Source File: SimpleScrollListener.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    onScroll();

    if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
        onEnd();
        resetScrollDistance();
    } else {
        if (mScrolledDistance < -HIDE_THRESHOLD) {
            onScrollUp();
            resetScrollDistance();
        }
    }

    if ((dy < 0)) {
        mScrolledDistance += dy;
    }
}
 
Example 4
Source File: PagerLoadablePresenter.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<Photo> loadMore(PagerViewModel<Photo> viewModel, int currentCount,
                                   PagerView pagerView, RecyclerView recyclerView,
                                   PagerManageView pagerManageView, int pagerIndex) {
    if (pagerManageView != null && pagerManageView.canLoadMore(pagerIndex)) {
        pagerManageView.onLoad(pagerIndex);
    }
    if (!recyclerView.canScrollVertically(1)
            && pagerManageView != null && pagerManageView.isLoading(pagerIndex)) {
        pagerView.setSwipeLoading(true);
    }

    if (currentCount >= viewModel.getListSize()) {
        return new ArrayList<>();
    }

    return subList(viewModel, currentCount, viewModel.getListSize());
}
 
Example 5
Source File: DragSortAdapter.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void handleDragScroll(RecyclerView rv, DragInfo dragInfo) {
    if (rv.getLayoutManager().canScrollHorizontally()) {
        if (rv.canScrollHorizontally(-1) && dragInfo.shouldScrollLeft()) {
            rv.scrollBy(-SCROLL_AMOUNT, 0);
            dragManager.clearNextMove();
        } else if (rv.canScrollHorizontally(1) && dragInfo.shouldScrollRight(rv.getWidth())) {
            rv.scrollBy(SCROLL_AMOUNT, 0);
            dragManager.clearNextMove();
        }
    } else if (rv.getLayoutManager().canScrollVertically()) {
        if (rv.canScrollVertically(-1) && dragInfo.shouldScrollUp()) {
            rv.scrollBy(0, -SCROLL_AMOUNT);
            dragManager.clearNextMove();
        } else if (rv.canScrollVertically(1) && dragInfo.shouldScrollDown(rv.getHeight())) {
            rv.scrollBy(0, SCROLL_AMOUNT);
            dragManager.clearNextMove();
        }
    }
}
 
Example 6
Source File: ConversationListFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
  if (recyclerView.canScrollVertically(-1)) {
    if (toolbarShadow.getVisibility() != View.VISIBLE) {
      ViewUtil.fadeIn(toolbarShadow, 250);
    }
  } else {
    if (toolbarShadow.getVisibility() != View.GONE) {
      ViewUtil.fadeOut(toolbarShadow, 250);
    }
  }
}
 
Example 7
Source File: PlayingQueueController.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@OnTouch(R.id.recycler_view)
boolean onTouchRecyclerView(RecyclerView view, MotionEvent event) {
    boolean isRecyclerViewOnTop = !view.canScrollVertically(-1);
    float currentY = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.d(TAG, "onTouchRecyclerView: down");
        //    Toast.makeText(getContext(),"Down",Toast.LENGTH_SHORT).show();
            mFirstTouchEvent = true;
            view.onTouchEvent(event);
            if(isRecyclerViewOnTop) mLayerController.streamOnTouchEvent(mRoot,event);
            break;
        case MotionEvent.ACTION_UP:
            Log.d(TAG, "onTouchRecyclerView: up");
            mFirstTouchEvent = false;
            mPreviousY = 0;
            if(mInStreamEvent) {
                mInStreamEvent = false;
                mLayerController.streamOnTouchEvent(mRoot, event);
            }
             view.onTouchEvent(event);
            break;
        default:
            Log.d(TAG, "onTouchRecyclerView: "+event.getAction());
            if(mPreviousY<currentY&&isRecyclerViewOnTop) mInStreamEvent = true;
            if(mInStreamEvent) mLayerController.streamOnTouchEvent(mRoot,event);
            else view.onTouchEvent(event);
            mFirstTouchEvent = false;
    }
    mPreviousY = currentY;
    return true;
}
 
Example 8
Source File: ViewUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Launches an app based on RecyclerView scroll state.
 *
 * @param activity     The activity for context reference.
 * @param recyclerView The RecyclerView itself.
 * @param adapter      A FlexibleAdapter with App items.
 */
public static void keyboardLaunchApp(Activity activity, RecyclerView recyclerView, FlexibleAdapter<App> adapter) {
    if (recyclerView.canScrollVertically(RecyclerView.FOCUS_UP)) {
        AppUtils.launchApp(activity, Utils.requireNonNull(
                adapter.getItem(0)));
    } else if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
        AppUtils.launchApp(activity, Utils.requireNonNull(
                adapter.getItem(adapter.getItemCount() - 1)));
    }
}
 
Example 9
Source File: ViewUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Launches an app based on RecyclerView scroll state.
 *
 * @param activity     The activity for context reference.
 * @param recyclerView The RecyclerView itself.
 * @param adapter      A FlexibleAdapter with App items.
 */
public static void keyboardLaunchApp(Activity activity, RecyclerView recyclerView, FlexibleAdapter<App> adapter) {
    if (recyclerView.canScrollVertically(RecyclerView.FOCUS_UP)) {
        AppUtils.launchApp(activity, Utils.requireNonNull(
                adapter.getItem(0)));
    } else if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
        AppUtils.launchApp(activity, Utils.requireNonNull(
                adapter.getItem(adapter.getItemCount() - 1)));
    }
}
 
Example 10
Source File: PagerScrollablePresenter.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void onScrolled(BothWaySwipeRefreshLayout refreshLayout,
                              RecyclerView recyclerView, int realItemCount,
                              @Nullable PagerManageView pagerManageView, int index, int dy) {
    if (recyclerView.getLayoutManager() == null) {
        return;
    }
    int[] lastVisibleItems = null;
    if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        lastVisibleItems = ((StaggeredGridLayoutManager) recyclerView.getLayoutManager())
                .findLastVisibleItemPositions(null);
    } else if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        lastVisibleItems = new int[] {((GridLayoutManager) recyclerView.getLayoutManager())
                .findLastVisibleItemPosition()};
    } else if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        lastVisibleItems = new int[] {((LinearLayoutManager) recyclerView.getLayoutManager())
                .findLastVisibleItemPosition()};
    }
    if (lastVisibleItems == null || lastVisibleItems.length == 0) {
        return;
    }

    if (pagerManageView != null && pagerManageView.canLoadMore(index)
            && lastVisibleItems[lastVisibleItems.length - 1] >= realItemCount - ListPager.DEFAULT_PER_PAGE
            && realItemCount > 0
            && dy > 0) {
        pagerManageView.onLoad(index);
    }
    if (!recyclerView.canScrollVertically(1)
            && pagerManageView != null && pagerManageView.isLoading(index)) {
        refreshLayout.setLoading(true);
    }
}
 
Example 11
Source File: DialogRootView.java    From AndroidMaterialDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Returns, whether a specific recylcer view is scrolled to the bottom, or not.
 *
 * @param recyclerView The recycler view as an instance of the class {@link RecyclerView}. The
 *                     recycler view may not be null
 * @return True, if the given recycler view is scrolled to the bottom, false otherwise
 */
private boolean isRecyclerViewScrolledToBottom(@NonNull final RecyclerView recyclerView) {
    return !recyclerView.canScrollVertically(1);
}
 
Example 12
Source File: DialogRootView.java    From AndroidMaterialDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Returns, whether a specific recylcer view is scrolled to the top, or not.
 *
 * @param recyclerView The recycler view as an instance of the class {@link RecyclerView}. The
 *                     recycler view may not be null
 * @return True, if the given recycler view is scrolled to the top, false otherwise
 */
private boolean isRecyclerViewScrolledToTop(@NonNull final RecyclerView recyclerView) {
    return !recyclerView.canScrollVertically(-1);
}