@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled() || getViewAdapter() == null) { return true; } switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: if (!mIsScrollingPerformed) { int distance = (int) getMotionEventPosition(event) - getBaseDimension() / 2; if (distance > 0) { distance += getItemDimension() / 2; } else { distance -= getItemDimension() / 2; } int items = distance / getItemDimension(); if (items != 0 && isValidItemIndex(mCurrentItemIdx + items)) { notifyClickListenersAboutClick(mCurrentItemIdx + items); } } break; } return mScroller.onTouchEvent(event); }
/** * Set the the specified scrolling interpolator * * @param interpolator the interpolator */ public void setInterpolator(Interpolator interpolator) { mScroller.setInterpolator(interpolator); }
/** * Scroll the spinnerwheel * * @param itemsToScroll items to scroll * @param time scrolling duration */ public void scroll(int itemsToScroll, int time) { int distance = itemsToScroll * getItemDimension() - mScrollingOffset; onScrollTouched(); // we have to emulate touch when scrolling spinnerwheel programmatically to // light up stuff mScroller.scroll(distance, time); }
/** Stops scrolling */ public void stopScrolling() { mScroller.stopScrolling(); }