示例#1
0
  @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);
  }
示例#2
0
 /**
  * Set the the specified scrolling interpolator
  *
  * @param interpolator the interpolator
  */
 public void setInterpolator(Interpolator interpolator) {
   mScroller.setInterpolator(interpolator);
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /** Stops scrolling */
 public void stopScrolling() {
   mScroller.stopScrolling();
 }