Java Code Examples for androidx.recyclerview.widget.RecyclerView#SCROLL_STATE_IDLE

The following examples show how to use androidx.recyclerview.widget.RecyclerView#SCROLL_STATE_IDLE . 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: ColumnLayoutManager.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example 2
Source File: ViewPagerLayoutManager.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
@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;
}
 
Example 3
Source File: SlimMoreLoader.java    From SlimAdapter with MIT License 6 votes vote down vote up
@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;
    }
}
 
Example 4
Source File: FocusLayoutManager.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 5
Source File: VerticalRecyclerViewListener.java    From TableView with MIT License 6 votes vote down vote up
@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");
        }
    }
}
 
Example 6
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 7
Source File: RowHeaderRecyclerViewItemClickListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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());
    }
}
 
Example 8
Source File: ColumnHeaderRecyclerViewItemClickListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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());
    }
}
 
Example 9
Source File: ColumnLayoutManager.java    From TableView with MIT License 6 votes vote down vote up
@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);
}
 
Example 10
Source File: VerticalRecyclerViewListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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");
        }
    }
}
 
Example 11
Source File: ScrollingPauseLoadManager.java    From sketch with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 12
Source File: ScrollTopHelper.java    From AppOpsX with MIT License 5 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  super.onScrollStateChanged(recyclerView, newState);

  if (newState == RecyclerView.SCROLL_STATE_IDLE) {
    trackHeader();
  }
}
 
Example 13
Source File: ViewPagerLayoutManager.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 14
Source File: PagerLayoutManager.java    From videoplay with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: GalleryLayoutManager.java    From CardSlideView with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 16
Source File: HorizontalRecyclerViewListener.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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;
}
 
Example 17
Source File: SinglePageItemRecyclerViewAdapter.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        unlockBinding();
    }
}
 
Example 18
Source File: StickyHeaderHelper.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    displayWithAnimation = mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE;
    updateOrClearHeader(false);
}
 
Example 19
Source File: SearchBarMover.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState){
    if (newState == RecyclerView.SCROLL_STATE_IDLE && mHelper.isValidView(recyclerView)) {
        returnSearchBarPosition();
    }
}
 
Example 20
Source File: ListSwipeHelper.java    From DragListView with Apache License 2.0 4 votes vote down vote up
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);
}