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

The following examples show how to use androidx.recyclerview.widget.RecyclerView#computeVerticalScrollRange() . 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: FixedHideBottomViewOnScrollBehavior.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    boolean callSuper = true;
    if (target instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) target;
        int estimatedHeight = recyclerView.computeVerticalScrollRange();
        int totalSpace = child.getHeight() + target.getHeight();
        if (estimatedHeight <= totalSpace) {
            callSuper = false;
        }
    }
    if (callSuper) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
                dxUnconsumed, dyUnconsumed);
    }
}
 
Example 2
Source File: OnLoadMoreScrollListener.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int result = 1;
    if (recyclerView instanceof SuperRecyclerView) {
        SuperRecyclerView superRecyclerView = (SuperRecyclerView) recyclerView;
        result += superRecyclerView.getHeaderContainer().getChildCount();
    }
    int visibleItemCount = layoutManager.getChildCount();
    boolean flag = recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange();
    boolean triggerCondition = visibleItemCount > result
            && newState == RecyclerView.SCROLL_STATE_IDLE
            && canTriggerLoadMore(recyclerView) && flag;
    if (triggerCondition) {
        onLoadMore(recyclerView);
    }
}
 
Example 3
Source File: ScrollController.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView rv, int dx, int dy) {
  final int scrollRange = rv.computeVerticalScrollRange();
  final int scrollExtent = rv.computeVerticalScrollExtent();

  scrollOffsetRange = scrollRange - scrollExtent;
  handleOffsetRange =
      scrollExtent - dpToPixel(rv.getContext(), 2 * HANDLE_VERTICAL_MARGIN + HANDLE_SIZE_DP);

  scrollOffset = rv.computeVerticalScrollOffset();

  if (userControlling) {
    return;
  }

  final float scale = ((float) scrollOffset) / scrollOffsetRange;
  handleOffset = (int) (handleOffsetRange * scale);
  handleOffsetDV.set((float) handleOffset);
}
 
Example 4
Source File: FastScroll.java    From RecyclerExt with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
    int verticalRange = recyclerView.computeVerticalScrollRange();

    //Makes sure the FastScroll is correctly hidden on shorter lists
    if (hideOnShortLists && (verticalRange < calculatedMinDisplayHeight || calculatedMinDisplayHeight == 0)) {
        updateHandleVisibility(false);
        return;
    }

    //Makes sure the handle is shown when scrolling
    updateHandleVisibility(true);
    delayHandler.removeCallbacks(handleHideRunnable);

    if (handle.isSelected()) {
        return;
    }

    hideHandleDelayed();

    float ratio = (float)recyclerView.computeVerticalScrollOffset() / (float) (verticalRange - recyclerView.computeVerticalScrollExtent());
    float halfHandleHeight = (handle.getHeight() / 2);
    setBubbleAndHandlePosition((height - handle.getHeight()) * ratio + halfHandleHeight);
}
 
Example 5
Source File: RecyclerViewFastScroller.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
  if (handle.isSelected()) return;
  final int   offset      = recyclerView.computeVerticalScrollOffset();
  final int   range       = recyclerView.computeVerticalScrollRange();
  final int   extent      = recyclerView.computeVerticalScrollExtent();
  final int   offsetRange = Math.max(range - extent, 1);
  setBubbleAndHandlePosition((float) Util.clamp(offset, 0, offsetRange) / offsetRange);
}
 
Example 6
Source File: FastScroller.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private float getScrollProportion(RecyclerView recyclerView) {
    if (recyclerView == null) {
        return 0;
    }
    final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    final float rangeDiff = verticalScrollRange - mViewHeight;
    float proportion = (float) verticalScrollOffset / (rangeDiff > 0 ? rangeDiff : 1f);
    return mViewHeight * proportion;
}
 
Example 7
Source File: FastScroller.java    From call_manage with MIT License 5 votes vote down vote up
public void updateContainerAndScrollBarPosition(RecyclerView recyclerView) {
    if (!scrollBar.isSelected()) {
        int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
        int verticalScrollRange = recyclerView.computeVerticalScrollRange();
        float proportion = (float) verticalScrollOffset / ((float) verticalScrollRange - getHeight());
        setContainerAndScrollBarPosition(getHeight() * proportion);
    }
}
 
Example 8
Source File: FastScroller.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
private float getScrollProportion(RecyclerView recyclerView) {
    if (recyclerView == null) {
        return 0;
    }
    final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    final float rangeDiff = verticalScrollRange - mViewHeight;
    float proportion = (float) verticalScrollOffset / (rangeDiff > 0 ? rangeDiff : 1f);
    return mViewHeight * proportion;
}
 
Example 9
Source File: Pix.java    From PixImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (recyclerView.isEnabled()) {
        switch (newState) {
            case RecyclerView.SCROLL_STATE_DRAGGING:
                handler.removeCallbacks(mScrollbarHider);
                if (mScrollbar.getVisibility() != View.VISIBLE) {
                    Utility.cancelAnimation(mScrollbarAnimator);
                    if (!Utility.isViewVisible(mScrollbar) && (recyclerView.computeVerticalScrollRange()
                            - mViewHeight > 0)) {

                        mScrollbarAnimator = Utility.showScrollbar(mScrollbar, Pix.this);
                    }
                }
                break;
            case RecyclerView.SCROLL_STATE_IDLE:
                if (mHideScrollbar && !mHandleView.isSelected()) {
                    handler.postDelayed(mScrollbarHider, sScrollbarHideDelay);
                }
                break;
            default:
                break;
        }
    }
}
 
Example 10
Source File: Pix.java    From PixImagePicker with Apache License 2.0 5 votes vote down vote up
private float getScrollProportion(RecyclerView recyclerView) {
    final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    final float rangeDiff = verticalScrollRange - mViewHeight;
    float proportion = (float) verticalScrollOffset / (rangeDiff > 0 ? rangeDiff : 1f);
    return mViewHeight * proportion;
}
 
Example 11
Source File: FastScroller.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private float getScrollProportion(RecyclerView recyclerView) {
    if (recyclerView == null) {
        return 0;
    }

    final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    final float rangeDiff = verticalScrollRange - viewHeight;
    float proportion = (float) verticalScrollOffset / (rangeDiff > 0 ? rangeDiff : 1f);
    return viewHeight * proportion;
}
 
Example 12
Source File: RecyclerViewFastScroller.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
  if (handle.isSelected()) return;
  final int   offset      = recyclerView.computeVerticalScrollOffset();
  final int   range       = recyclerView.computeVerticalScrollRange();
  final int   extent      = recyclerView.computeVerticalScrollExtent();
  final int   offsetRange = Math.max(range - extent, 1);
  setBubbleAndHandlePosition((float) Util.clamp(offset, 0, offsetRange) / offsetRange);
}
 
Example 13
Source File: BothDirectionsScrollLayoutManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
/**
 * 计算垂直滚动范围
 *
 * @return 滚动范围
 */
protected int computeVerticalScrollRange() {
    if (getOrientation() == RecyclerView.VERTICAL) {
        final RecyclerView view = getRecyclerView();
        return view == null ? 0 : view.computeVerticalScrollRange();
    }
    return getChildMaxHeight(mChildMaxHeight) + mTopDecorationMaxWidthOfChildMaxHeight +
            mBottomDecorationMaxWidthOfChildMaxHeight;
}
 
Example 14
Source File: InfiniteScrollListener.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isSlideToBottom(RecyclerView recyclerView) {
    return recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset()
            >= recyclerView.computeVerticalScrollRange();
}