@Override public boolean onScroll(MotionEvent e1,MotionEvent e2,float distanceX,float distanceY){
  int touchSlop=0;
  float factor;
  if (mOrientation == Orientation.VERTICAL) {
    factor=Math.abs((float)(mTranslation) / (float)(that.getHeight()));
    if (e2.getY() - mParentPositionY <= that.getHeight() && e2.getY() - mParentPositionY >= 0) {
      if ((e2.getY() - mParentPositionY) > that.getHeight() * getAnchorFactor()) {
        mTranslation-=(int)distanceY;
        touchSlop=distanceY < 0 ? -mTouchSlop : mTouchSlop;
      }
 else {
        mTranslation+=(int)distanceY;
        touchSlop=distanceY < 0 ? mTouchSlop : -mTouchSlop;
      }
      mTranslation=mDidNotStartScroll ? mTranslation + touchSlop : mTranslation;
      if (mTranslation < -that.getHeight()) {
        mTranslation=-that.getHeight();
      }
    }
  }
 else {
    factor=Math.abs(((float)mTranslation) / ((float)that.getWidth()));
    if (e2.getRawX() > that.getWidth() * getAnchorFactor()) {
      mTranslation-=(int)distanceX;
      touchSlop=distanceX < 0 ? -mTouchSlop : mTouchSlop;
    }
 else {
      mTranslation+=(int)distanceX;
      touchSlop=distanceX < 0 ? mTouchSlop : -mTouchSlop;
    }
    mTranslation=mDidNotStartScroll ? mTranslation + touchSlop : mTranslation;
    if (mTranslation < -that.getWidth()) {
      mTranslation=-that.getWidth();
    }
  }
  mDidNotStartScroll=false;
  if (mTranslation > 0) {
    mTranslation=0;
  }
  that.setFoldFactor(factor);
  return true;
}

@ Override public boolean onScroll ( MotionEvent e1 , MotionEvent e2 , float distanceX , float distanceY ) { int touchSlop = 0 ; float factor ; if ( mOrientation == Orientation . VERTICAL ) { factor = Math . abs ( ( float ) ( mTranslation ) / ( float ) ( that . getHeight ( ) ) ) ; if ( e2 . getY ( ) - mParentPositionY <= that . getHeight ( ) && e2 . getY ( ) - mParentPositionY >= 0 ) { if ( ( e2 . getY ( ) - mParentPositionY ) > that . getHeight ( ) * getAnchorFactor ( ) ) { mTranslation -= ( int ) distanceY ; touchSlop = distanceY < 0 ? - mTouchSlop : mTouchSlop ; } else { mTranslation += ( int ) distanceY ; touchSlop = distanceY < 0 ? mTouchSlop : - mTouchSlop ; } mTranslation = mDidNotStartScroll ? mTranslation + touchSlop : mTranslation ; if ( mTranslation < - that . getHeight ( ) ) { mTranslation = - that . getHeight ( ) ; } } } else { factor = Math . abs ( ( ( float ) mTranslation ) / ( ( float ) that . getWidth ( ) ) ) ; if ( e2 . getRawX ( ) > that . getWidth ( ) * getAnchorFactor ( ) ) { mTranslation -= ( int ) distanceX ; touchSlop = distanceX < 0 ? - mTouchSlop : mTouchSlop ; } else { mTranslation += ( int ) distanceX ; touchSlop = distanceX < 0 ? mTouchSlop : - mTouchSlop ; } mTranslation = mDidNotStartScroll ? mTranslation + touchSlop : mTranslation ; if ( mTranslation < - that . getWidth ( ) ) { mTranslation = - that . getWidth ( ) ; } } mDidNotStartScroll = false ; if ( mTranslation > 0 ) { mTranslation = 0 ; } that . setFoldFactor ( factor ) ; return true ; }
all the logic here is used to determine by what factor the paper view should be folded in response to the user ' s touch events . the logic here uses vertical scrolling to fold a vertically oriented view and horizontal scrolling to fold a horizontally oriented fold . depending on where the anchor point of the fold is , movements towards or away from the anchor point will either fold or unfold the paper respectively . the translation logic here also accounts for the touch slop when a new user touch begins , but before a scroll event is first invoked .
