diff --git a/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/AbsRecyclerViewFastScroller.java b/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/AbsRecyclerViewFastScroller.java index 5b88dfc..9ce7b7b 100644 --- a/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/AbsRecyclerViewFastScroller.java +++ b/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/AbsRecyclerViewFastScroller.java @@ -79,8 +79,6 @@ public AbsRecyclerViewFastScroller(Context context, AttributeSet attrs, int defS } finally { attributes.recycle(); } - - setOnTouchListener(new FastScrollerTouchListener(this)); } private void applyCustomAttributesToView(View view, Drawable drawable, int color) { @@ -91,6 +89,31 @@ private void applyCustomAttributesToView(View view, Drawable drawable, int color } } + @Override + public boolean onTouchEvent(MotionEvent event) { + SectionIndicator sectionIndicator = this.getSectionIndicator(); + showOrHideIndicator(sectionIndicator, event); + + float scrollProgress = this.getScrollProgress(event); + this.scrollTo(scrollProgress, true); + this.moveHandleToPosition(scrollProgress); + return true; + } + + private void showOrHideIndicator(@Nullable SectionIndicator sectionIndicator, MotionEvent event) { + if (sectionIndicator == null) { + return; + } + + switch (event.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + sectionIndicator.animateAlpha(1f); + return; + case MotionEvent.ACTION_UP: + sectionIndicator.animateAlpha(0f); + } + } + /** * Provides the ability to programmatically set the color of the fast scroller's handle * @param color for the handle to be diff --git a/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/FastScrollerTouchListener.java b/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/FastScrollerTouchListener.java deleted file mode 100644 index a4bc5db..0000000 --- a/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/FastScrollerTouchListener.java +++ /dev/null @@ -1,49 +0,0 @@ -package xyz.danoz.recyclerviewfastscroller; - -import xyz.danoz.recyclerviewfastscroller.sectionindicator.SectionIndicator; - -import android.support.annotation.Nullable; -import android.view.MotionEvent; -import android.view.View; -import android.view.View.OnTouchListener; - -/** - * Touch listener that will move a {@link AbsRecyclerViewFastScroller}'s handle to a specified offset along the scroll bar - */ -class FastScrollerTouchListener implements OnTouchListener { - - private final AbsRecyclerViewFastScroller mFastScroller; - - /** - * @param fastScroller {@link xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller} for this listener to scroll - */ - public FastScrollerTouchListener(AbsRecyclerViewFastScroller fastScroller) { - mFastScroller = fastScroller; - } - - @Override - public boolean onTouch(View v, MotionEvent event) { - SectionIndicator sectionIndicator = mFastScroller.getSectionIndicator(); - showOrHideIndicator(sectionIndicator, event); - - float scrollProgress = mFastScroller.getScrollProgress(event); - mFastScroller.scrollTo(scrollProgress, true); - mFastScroller.moveHandleToPosition(scrollProgress); - return true; - } - - private void showOrHideIndicator(@Nullable SectionIndicator sectionIndicator, MotionEvent event) { - if (sectionIndicator == null) { - return; - } - - switch (event.getActionMasked()) { - case MotionEvent.ACTION_DOWN: - sectionIndicator.animateAlpha(1f); - return; - case MotionEvent.ACTION_UP: - sectionIndicator.animateAlpha(0f); - } - } - -}