/**
   * Handles Touch event
   *
   * @param event the motion event
   * @return
   */
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        lastTouchedPosition = getMotionEventPosition(event);
        scroller.forceFinished(true);
        clearMessages();
        listener.onTouch();
        break;

      case MotionEvent.ACTION_UP:
        if (scroller.isFinished()) listener.onTouchUp();
        break;

      case MotionEvent.ACTION_MOVE:
        // perform scrolling
        int distance = (int) (getMotionEventPosition(event) - lastTouchedPosition);
        if (distance != 0) {
          startScrolling();
          listener.onScroll(distance);
          lastTouchedPosition = getMotionEventPosition(event);
        }
        break;
    }

    if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
      justify();
    }

    return true;
  }
        public void handleMessage(Message msg) {
          scroller.computeScrollOffset();
          int currPosition = getCurrentScrollerPosition();
          int delta = lastScrollPosition - currPosition;
          lastScrollPosition = currPosition;
          if (delta != 0) {
            listener.onScroll(delta);
          }

          // scrolling is not finished when it comes to final Y
          // so, finish it manually
          if (Math.abs(currPosition - getFinalScrollerPosition()) < MIN_DELTA_FOR_SCROLLING) {
            // currPosition = getFinalScrollerPosition();
            scroller.forceFinished(true);
          }
          if (!scroller.isFinished()) {
            animationHandler.sendEmptyMessage(msg.what);
          } else if (msg.what == MESSAGE_SCROLL) {
            justify();
          } else {
            finishScrolling();
          }
        }
 /** Finishes scrolling */
 protected void finishScrolling() {
   if (isScrollingPerformed) {
     listener.onFinished();
     isScrollingPerformed = false;
   }
 }
 /** Starts scrolling */
 private void startScrolling() {
   if (!isScrollingPerformed) {
     isScrollingPerformed = true;
     listener.onStarted();
   }
 }
 /** Justifies spinnerwheel */
 private void justify() {
   listener.onJustify();
   setNextMessage(MESSAGE_JUSTIFY);
 }