Java Code Examples for androidx.recyclerview.widget.RecyclerView#removeOnScrollListener()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#removeOnScrollListener() .
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: VerticalRecyclerViewListener.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 2
Source File: HorizontalRecyclerViewListener.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (newState == RecyclerView.SCROLL_STATE_IDLE) { // Renew the scroll position and its offset renewScrollPosition(recyclerView); recyclerView.removeOnScrollListener(this); Log.d(LOG_TAG, "Scroll listener has been removed to " + recyclerView.getId() + " at " + "onScrollStateChanged"); mIsMoved = false; // When a user scrolls horizontally, VerticalRecyclerView add vertical scroll // listener because of touching process.However, mVerticalRecyclerViewListener // doesn't know anything about it. So, it is necessary to remove the last touched // recyclerView which uses the mVerticalRecyclerViewListener. boolean isNeeded = mLastTouchedRecyclerView != mColumnHeaderRecyclerViews.get(0); mVerticalRecyclerViewListener.removeLastTouchedRecyclerViewScrollListener(isNeeded); } }
Example 3
Source File: DynamicScrollUtils.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Set edge effect or glow color for recycler view. * * @param recyclerView The recycler view to set the edge effect color. * @param color The edge effect color to be set. * @param scrollListener Scroll listener to set color on over scroll. */ public static void setEdgeEffectColor(@Nullable RecyclerView recyclerView, final @ColorInt int color, @Nullable RecyclerView.OnScrollListener scrollListener) { if (recyclerView == null) { return; } if (scrollListener == null) { scrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); setEdgeEffectColor(recyclerView, color); } }; recyclerView.removeOnScrollListener(scrollListener); recyclerView.addOnScrollListener(scrollListener); } setEdgeEffectColor(recyclerView, color); }
Example 4
Source File: HorizontalRecyclerViewListener.java From TableView with MIT License | 6 votes |
@Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (newState == RecyclerView.SCROLL_STATE_IDLE) { // Renew the scroll position and its offset renewScrollPosition(recyclerView); recyclerView.removeOnScrollListener(this); Log.d(LOG_TAG, "Scroll listener has been removed to " + recyclerView.getId() + " at " + "onScrollStateChanged"); mIsMoved = false; // When a user scrolls horizontally, VerticalRecyclerView add vertical scroll // listener because of touching process.However, mVerticalRecyclerViewListener // doesn't know anything about it. So, it is necessary to remove the last touched // recyclerView which uses the mVerticalRecyclerViewListener. boolean isNeeded = mLastTouchedRecyclerView != mColumnHeaderRecyclerView; mVerticalRecyclerViewListener.removeLastTouchedRecyclerViewScrollListener(isNeeded); } }
Example 5
Source File: VerticalRecyclerViewListener.java From TableView with MIT License | 6 votes |
@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: CircleIndicator2.java From CircleIndicator with Apache License 2.0 | 5 votes |
public void attachToRecyclerView(@NonNull RecyclerView recyclerView, @NonNull SnapHelper snapHelper) { mRecyclerView = recyclerView; mSnapHelper = snapHelper; mLastPosition = -1; createIndicators(); recyclerView.removeOnScrollListener(mInternalOnScrollListener); recyclerView.addOnScrollListener(mInternalOnScrollListener); }
Example 7
Source File: SinglePageItemRecyclerViewAdapter.java From materialistic with Apache License 2.0 | 5 votes |
@Override public void detach(Context context, RecyclerView recyclerView) { super.detach(context, recyclerView); recyclerView.removeOnScrollListener(mScrollListener); mColors.recycle(); mItemTouchHelper.attachToRecyclerView(null); }
Example 8
Source File: StoryRecyclerViewAdapter.java From materialistic with Apache License 2.0 | 5 votes |
private void toggleAutoMarkAsViewed(RecyclerView recyclerView) { if (Preferences.autoMarkAsViewed(recyclerView.getContext())) { recyclerView.addOnScrollListener(mAutoViewScrollListener); } else { recyclerView.removeOnScrollListener(mAutoViewScrollListener); } }
Example 9
Source File: OtherVersionsFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroyView() { final RecyclerView recyclerView = getRecyclerView(); if (recyclerView != null && endlessRecyclerOnScrollListener != null) { recyclerView.removeOnScrollListener(endlessRecyclerOnScrollListener); } endlessRecyclerOnScrollListener = null; header = null; collapsingToolbarLayout = null; super.onDestroyView(); }
Example 10
Source File: EpoxyVisibilityTracker.java From epoxy with Apache License 2.0 | 5 votes |
/** * Detach the tracker * * @param recyclerView The recycler view that the EpoxyController has its adapter added to. */ public void detach(@NonNull RecyclerView recyclerView) { recyclerView.removeOnScrollListener(this.listener); recyclerView.removeOnLayoutChangeListener(this.listener); recyclerView.removeOnChildAttachStateChangeListener(this.listener); setTracker(recyclerView, null); attachedRecyclerView = null; }
Example 11
Source File: SlimAdapter.java From SlimAdapter with MIT License | 5 votes |
@Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { if (moreLoader != null) { recyclerView.removeOnScrollListener(moreLoader); } super.onDetachedFromRecyclerView(recyclerView); }
Example 12
Source File: StickyViewBehavior.java From brickkit-android with Apache License 2.0 | 5 votes |
@Override protected boolean detach(RecyclerView recyclerView) { if (recyclerView != null) { recyclerView.removeOnScrollListener(this); clearStickyView(); } return true; }
Example 13
Source File: VerticalRecyclerViewListener.java From TableView with MIT License | 4 votes |
@Override public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull 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 scroll direction is not Vertical, then ignore and reset last RV touched if (!verticalDirection(e)) { mCurrentRVTouched = null; return false; } if (e.getAction() == MotionEvent.ACTION_DOWN) { mCurrentRVTouched = rv; if (rv.getScrollState() == RecyclerView.SCROLL_STATE_IDLE) { if (mLastTouchedRecyclerView != null && rv != mLastTouchedRecyclerView) { removeLastTouchedRecyclerViewScrollListener(false); } mYPosition = ((CellRecyclerView) rv).getScrolledY(); rv.addOnScrollListener(this); if (rv == mCellRecyclerView) { Log.d(LOG_TAG, "mCellRecyclerView scroll listener added"); } else if (rv == mRowHeaderRecyclerView) { Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener added"); } // Refresh the value; mIsMoved = false; } } 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 nScrollY = ((CellRecyclerView) rv).getScrolledY(); // TODO: Even if moved value is true and it may not scroll. This should be fixed. // TODO: The scenario is scroll lightly center RecyclerView vertically. // TODO: Below if condition may be changed later. // Is it just touched without scrolling then remove the listener if (mYPosition == nScrollY && !mIsMoved && rv.getScrollState() == RecyclerView .SCROLL_STATE_IDLE) { rv.removeOnScrollListener(this); if (rv == mCellRecyclerView) { Log.d(LOG_TAG, "mCellRecyclerView scroll listener removed from up "); } else if (rv == mRowHeaderRecyclerView) { Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener removed from up"); } } mLastTouchedRecyclerView = rv; } return false; }
Example 14
Source File: HorizontalRecyclerViewListener.java From TableView with MIT License | 4 votes |
@Override public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull 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 == mColumnHeaderRecyclerView) { mColumnHeaderRecyclerView.removeOnScrollListener(this); mColumnHeaderRecyclerView.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 15
Source File: AsyncAdapter.java From financisto with GNU General Public License v2.0 | 4 votes |
public void onStop(RecyclerView recyclerView) { recyclerView.removeOnScrollListener(onScrollListener); itemSource.close(); }
Example 16
Source File: RecyclerBinder.java From litho with Apache License 2.0 | 4 votes |
/** * Call from the owning {@link Component}'s onUnmount. This is where the adapter is removed from * the {@link RecyclerView}. * * @param view the {@link RecyclerView} being unmounted. */ @UiThread @Override public void unmount(RecyclerView view) { ThreadUtils.assertMainThread(); if (mIsSubAdapter) { throw new RuntimeException("Can't unmount a RecyclerView in sub adapter mode"); } final LayoutManager layoutManager = mLayoutInfo.getLayoutManager(); final View firstView = layoutManager.findViewByPosition(mCurrentFirstVisiblePosition); if (firstView != null) { final boolean reverseLayout = getReverseLayout(); if (mLayoutInfo.getScrollDirection() == HORIZONTAL) { mCurrentOffset = reverseLayout ? view.getWidth() - layoutManager.getPaddingRight() - layoutManager.getDecoratedRight(firstView) : layoutManager.getDecoratedLeft(firstView) - layoutManager.getPaddingLeft(); } else { mCurrentOffset = reverseLayout ? view.getHeight() - layoutManager.getPaddingBottom() - layoutManager.getDecoratedBottom(firstView) : layoutManager.getDecoratedTop(firstView) - layoutManager.getPaddingTop(); } } else { mCurrentOffset = 0; } view.removeOnScrollListener(mViewportManager.getScrollListener()); unregisterDrawListener(view); maybeDispatchDataRendered(); view.setAdapter(null); view.setLayoutManager(null); mViewportManager.removeViewportChangedListener(mViewportChangedListener); // We might have already unmounted this view when calling mount with a different view. In this // case we can just return here. if (mMountedView != view) { return; } mMountedView = null; if (mStickyHeaderController != null) { mStickyHeaderController.reset(); } mLayoutInfo.setRenderInfoCollection(null); }
Example 17
Source File: HorizontalRecyclerViewListener.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 18
Source File: EndlessRecyclerAdapter.java From GestureViews with Apache License 2.0 | 4 votes |
@Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { super.onDetachedFromRecyclerView(recyclerView); recyclerView.removeOnScrollListener(scrollListener); }
Example 19
Source File: VerticalRecyclerViewListener.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 scroll direction is not Vertical, then ignore and reset last RV touched if(!verticalDirection(e)) { mCurrentRVTouched = null; return false; } if (e.getAction() == MotionEvent.ACTION_DOWN) { mCurrentRVTouched = rv; if (rv.getScrollState() == RecyclerView.SCROLL_STATE_IDLE) { if (mLastTouchedRecyclerView != null && rv != mLastTouchedRecyclerView) { removeLastTouchedRecyclerViewScrollListener(false); } mYPosition = ((CellRecyclerView) rv).getScrolledY(); rv.addOnScrollListener(this); if (rv == mCellRecyclerView) { Log.d(LOG_TAG, "mCellRecyclerView scroll listener added"); } else if (rv == mRowHeaderRecyclerView) { Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener added"); } // Refresh the value; mIsMoved = false; } } 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 nScrollY = ((CellRecyclerView) rv).getScrolledY(); // TODO: Even if moved value is true and it may not scroll. This should be fixed. // TODO: The scenario is scroll lightly center RecyclerView vertically. // TODO: Below if condition may be changed later. // Is it just touched without scrolling then remove the listener if (mYPosition == nScrollY && !mIsMoved && rv.getScrollState() == RecyclerView .SCROLL_STATE_IDLE) { rv.removeOnScrollListener(this); if (rv == mCellRecyclerView) { Log.d(LOG_TAG, "mCellRecyclerView scroll listener removed from up "); } else if (rv == mRowHeaderRecyclerView) { Log.d(LOG_TAG, "mRowHeaderRecyclerView scroll listener removed from up"); } } mLastTouchedRecyclerView = rv; } return false; }