androidx.recyclerview.widget.RecyclerView#SCROLL_STATE_IDLE源码实例Demo

下面列出了androidx.recyclerview.widget.RecyclerView#SCROLL_STATE_IDLE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void onScrollStateChanged(int state) {
    if (mCurrentScrollState == RecyclerView.SCROLL_STATE_IDLE && mCurrentScrollState != state) {
        mScrollStateListener.onScrollStart();
    }

    if (state == RecyclerView.SCROLL_STATE_IDLE) {
        //Scroll is not finished until current view is centered
        boolean isScrollEnded = onScrollEnd();
        if (isScrollEnded) {
            mScrollStateListener.onScrollEnd();
        } else {
            //Scroll continues and we don't want to set mCurrentScrollState to STATE_IDLE,
            //because this will then trigger .mScrollStateListener.onScrollStart()
            return;
        }
    } else if (state == RecyclerView.SCROLL_STATE_DRAGGING) {
        onDragStart();
    }
    mCurrentScrollState = state;
}
 
源代码2 项目: SlimAdapter   文件: SlimMoreLoader.java
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    switch (newState) {
        case RecyclerView.SCROLL_STATE_IDLE:
            int last = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
            if (NO_POSITION == last) {
                break;
            }
            if (slimAdapter.getItem(last) == this && !loading) {
                loadMore();
            }
            break;
        default:
            break;
    }
}
 
@Override
public void onScrollStateChanged(int state) {
    super.onScrollStateChanged(state);
    switch (state) {
        case RecyclerView.SCROLL_STATE_DRAGGING:
            //当手指按下时,停止当前正在播放的动画
            cancelAnimator();
            break;
        case RecyclerView.SCROLL_STATE_IDLE:
            //当列表滚动停止后,判断一下自动选中是否打开
            if (isAutoSelect) {
                //找到离目标落点最近的item索引
                smoothScrollToPosition(findShouldSelectPosition());
            }
            break;
        default:
            break;
    }
}
 
源代码4 项目: TableView   文件: VerticalRecyclerViewListener.java
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        recyclerView.removeOnScrollListener(this);
        mIsMoved = false;
        mCurrentRVTouched = null;
        if (recyclerView == mCellRecyclerView) {
            Log.d(LOG_TAG, "mCellRecyclerView scroll listener removed from " +
                    "onScrollStateChanged");
        } else if (recyclerView == mRowHeaderRecyclerView) {
            Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener removed from " +
                    "onScrollStateChanged");
        }
    }
}
 
protected void longPressAction(MotionEvent e) {
    // Consume the action for the time when the recyclerView is scrolling.
    if (mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
        return;
    }

    // Get interacted view from x,y coordinate.
    View child = mRecyclerView.findChildViewUnder(e.getX(), e.getY());

    if (child != null && getTableViewListener() != null) {
        // Find the view holder
        RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(child);

        // Call ITableView listener for long click
        getTableViewListener().onRowHeaderLongPressed(holder, holder.getAdapterPosition());
    }
}
 
protected void longPressAction(MotionEvent e) {
    // Consume the action for the time when the recyclerView is scrolling.
    if (mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
        return;
    }

    // Get interacted view from x,y coordinate.
    View child = mRecyclerView.findChildViewUnder(e.getX(), e.getY());

    if (child != null && getTableViewListener() != null) {
        // Find the view holder
        RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(child);

        // Call ITableView listener for long click
        getTableViewListener().onColumnHeaderLongPressed(holder, holder.getAdapterPosition());
    }
}
 
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        recyclerView.removeOnScrollListener(this);
        mIsMoved = false;
        mCurrentRVTouched = null;
        if (recyclerView == mCellRecyclerView) {
            Log.d(LOG_TAG, "mCellRecyclerView scroll listener removed from " +
                    "onScrollStateChanged");
        } else if (recyclerView == mRowHeaderRecyclerView) {
            Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener removed from " +
                    "onScrollStateChanged");
        }
    }
}
 
源代码8 项目: sketch   文件: ScrollingPauseLoadManager.java
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (AppConfig.INSTANCE.getBoolean(recyclerView.getContext(), AppConfig.Key.SCROLLING_PAUSE_LOAD) && recyclerView.getAdapter() != null) {
        if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
            sketch.getConfiguration().setPauseLoadEnabled(true);
        } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
            if (sketch.getConfiguration().isPauseLoadEnabled()) {
                sketch.getConfiguration().setPauseLoadEnabled(false);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    }

    if (recyclerScrollListener != null) {
        recyclerScrollListener.onScrollStateChanged(recyclerView, newState);
    }
}
 
源代码9 项目: TableView   文件: ColumnLayoutManager.java
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State
        state) {
    if (mColumnHeaderRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE &&
            mCellRowRecyclerView.isScrollOthers()) {
        // Every CellRowRecyclerViews should be scrolled after the ColumnHeaderRecyclerView.
        // Because it is the main compared one to make each columns fit.
        mColumnHeaderRecyclerView.scrollBy(dx, 0);
    }
    // It is important to determine the next attached view to fit all columns
    mLastDx = dx;

    // Set the right initialPrefetch size to improve performance
    this.setInitialPrefetchItemCount(2);

    return super.scrollHorizontallyBy(dx, recycler, state);
}
 
源代码10 项目: NewFastFrame   文件: OnLoadMoreScrollListener.java
@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);
    }
}
 
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State
        state) {
    if (mColumnHeaderRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE &&
            mCellRowRecyclerView.isScrollOthers()) {
        // Every CellRowRecyclerViews should be scrolled after the ColumnHeaderRecyclerView.
        // Because it is the main compared one to make each columns fit.
        //mColumnHeaderRecyclerView.scrollBy(dx, 0);
    }
    // It is important to determine the next attached view to fit all columns
    mLastDx = dx;

    // Set the right initialPrefetch size to improve performance
    this.setInitialPrefetchItemCount(2);

    return super.scrollHorizontallyBy(dx, recycler, state);
}
 
源代码12 项目: CardSlideView   文件: GalleryLayoutManager.java
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    state = newState;
    if (state == RecyclerView.SCROLL_STATE_DRAGGING) {
        isDrag = true;
    }
    if (state == RecyclerView.SCROLL_STATE_IDLE) {
        isDrag = false;
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager == null) {
            return;
        }
        if (mSnapHelper == null) {
            return;
        }
        View snap = mSnapHelper.findSnapView(layoutManager);
        if (snap == null) {
            return;
        }
        int selectedPosition = layoutManager.getPosition(snap);
        if (mOnPageChangeListener != null && selectedPosition != mCurItem) {
            mCurItem = selectedPosition;
            mOnPageChangeListener.onPageSelected(mCurItem);
        }
    }
}
 
源代码13 项目: videoplay   文件: PagerLayoutManager.java
@Override
public void onScrollStateChanged(int state) {
    if (state == RecyclerView.SCROLL_STATE_IDLE) {
        View view = mPagerSnapHelper.findSnapView(this);
        if (view != null && mOnPageChangeListener != null) {
            int position = getPosition(view);
            if (currentPostion != position) {
                currentPostion = position;
                mOnPageChangeListener.onPageSelected(currentPostion, view);
            }
        }
    }
    super.onScrollStateChanged(state);
}
 
源代码14 项目: AppOpsX   文件: ScrollTopHelper.java
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  super.onScrollStateChanged(recyclerView, newState);

  if (newState == RecyclerView.SCROLL_STATE_IDLE) {
    trackHeader();
  }
}
 
源代码15 项目: DKVideoPlayer   文件: ViewPagerLayoutManager.java
@Override
public void onScrollStateChanged(int state) {
    if (state == RecyclerView.SCROLL_STATE_IDLE) {
        View viewIdle = mPagerSnapHelper.findSnapView(ViewPagerLayoutManager.this);
        int positionIdle = getPosition(viewIdle);
        if (mOnViewPagerListener != null && getChildCount() == 1) {
            mOnViewPagerListener.onPageSelected(positionIdle, positionIdle == getItemCount() - 1);
        }
    }
}
 
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        unlockBinding();
    }
}
 
源代码17 项目: FlexibleAdapter   文件: StickyHeaderHelper.java
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    displayWithAnimation = mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE;
    updateOrClearHeader(false);
}
 
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

    // Prevent multitouch, once we start to listen with a RV,
    // we ignore any other RV until the touch is released (UP)
    if (mCurrentRVTouched != null && rv != mCurrentRVTouched) {
        return true;
    }

    if (e.getAction() == MotionEvent.ACTION_DOWN) {
        mCurrentRVTouched = rv;
        if (rv.getScrollState() == RecyclerView.SCROLL_STATE_IDLE) {

            if (mLastTouchedRecyclerView != null && rv != mLastTouchedRecyclerView) {
                if (mLastTouchedRecyclerView == mColumnHeaderRecyclerViews) {
                    mColumnHeaderRecyclerViews.get(0).removeOnScrollListener(this);
                    mColumnHeaderRecyclerViews.get(0).stopScroll();
                    Log.d(LOG_TAG, "Scroll listener  has been removed to " +
                            "mColumnHeaderRecyclerView at last touch control");
                } else {
                    int lastTouchedIndex = getIndex(mLastTouchedRecyclerView);

                    // Control whether the last touched recyclerView is still attached or not
                    if (lastTouchedIndex >= 0 && lastTouchedIndex < mCellLayoutManager
                            .getChildCount()) {
                        // Control the scroll listener is already removed. For instance; if user
                        // scroll the parent recyclerView vertically, at that time,
                        // ACTION_CANCEL
                        // will be triggered that removes the scroll listener of the last
                        // touched
                        // recyclerView.
                        if (!((CellRecyclerView) mLastTouchedRecyclerView)
                                .isHorizontalScrollListenerRemoved()) {
                            // Remove scroll listener of the last touched recyclerView
                            // Because user touched another recyclerView before the last one get
                            // SCROLL_STATE_IDLE state that removes the scroll listener
                            ((RecyclerView) mCellLayoutManager.getChildAt(lastTouchedIndex))
                                    .removeOnScrollListener(this);

                            Log.d(LOG_TAG, "Scroll listener  has been removed to " +
                                    mLastTouchedRecyclerView.getId() + " CellRecyclerView " +
                                    "at last touch control");

                            // the last one scroll must be stopped to be sync with others
                            ((RecyclerView) mCellLayoutManager.getChildAt(lastTouchedIndex))
                                    .stopScroll();
                        }
                    }
                }
            }

            mXPosition = ((CellRecyclerView) rv).getScrolledX();
            rv.addOnScrollListener(this);
            Log.d(LOG_TAG, "Scroll listener  has been added to " + rv.getId() + " at action "
                    + "down");
        }
    } else if (e.getAction() == MotionEvent.ACTION_MOVE) {
        mCurrentRVTouched = rv;
        // Why does it matter ?
        // user scroll any recyclerView like brushing, at that time, ACTION_UP will be
        // triggered
        // before scrolling. So, we need to store whether it moved or not.
        mIsMoved = true;
    } else if (e.getAction() == MotionEvent.ACTION_UP) {
        mCurrentRVTouched = null;
        int nScrollX = ((CellRecyclerView) rv).getScrolledX();
        // Is it just touched without scrolling then remove the listener
        if (mXPosition == nScrollX && !mIsMoved) {
            rv.removeOnScrollListener(this);
            Log.d(LOG_TAG, "Scroll listener  has been removed to " + rv.getId() + " at " +
                    "action" + " up");
        }

        mLastTouchedRecyclerView = rv;

    } else if (e.getAction() == MotionEvent.ACTION_CANCEL) {
        // ACTION_CANCEL action will be triggered if users try to scroll vertically
        // For this situation, it doesn't matter whether the x position is changed or not
        // Beside this, even if moved action will be triggered, scroll listener won't
        // triggered on cancel action. So, we need to change state of the mIsMoved value as
        // well.

        // Renew the scroll position and its offset
        renewScrollPosition(rv);

        rv.removeOnScrollListener(this);
        Log.d(LOG_TAG, "Scroll listener  has been removed to " + rv.getId() + " at action " +
                "cancel");

        mIsMoved = false;

        mLastTouchedRecyclerView = rv;

        mCurrentRVTouched = null;
    }

    return false;
}
 
源代码19 项目: EhViewer   文件: SearchBarMover.java
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState){
    if (newState == RecyclerView.SCROLL_STATE_IDLE && mHelper.isValidView(recyclerView)) {
        returnSearchBarPosition();
    }
}
 
源代码20 项目: DragListView   文件: ListSwipeHelper.java
private boolean canStartSwipe(MotionEvent e1, MotionEvent e2) {
    return !(e1 == null || e2 == null || mSwipeView == null || mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE
            || mSwipeView.getSupportedSwipeDirection() == ListSwipeItem.SwipeDirection.NONE);
}