private void onSecondaryPointerUp(MotionEvent ev) {
   int pointerIndex = MotionEventCompat.getActionIndex(ev);
   int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == this.mActivePointerId) {
     int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     this.mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
   }
 }
 private void onSecondaryPointerUp(MotionEvent ev) {
   final int pointerIndex = MotionEventCompat.getActionIndex(ev);
   final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == mActivePointerId) {
     // This was our active pointer going up. Choose a new
     // active pointer and adjust accordingly.
     final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
   }
 }
 private void onPointerUp(MotionEvent e) {
   final int actionIndex = MotionEventCompat.getActionIndex(e);
   if (MotionEventCompat.getPointerId(e, actionIndex) == mScrollPointerId) {
     // Pick a new pointer to pick up the slack.
     final int newIndex = actionIndex == 0 ? 1 : 0;
     mScrollPointerId = MotionEventCompat.getPointerId(e, newIndex);
     mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, newIndex) + 0.5f);
     mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, newIndex) + 0.5f);
   }
 }
 /**
  * On secondary pointer up.
  *
  * @param ev the ev
  */
 private void onSecondaryPointerUp(MotionEvent ev) {
   final int pointerIndex = MotionEventCompat.getActionIndex(ev);
   final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == mActivePointerId) {
     // This was our active pointer going up. Choose a new
     // active pointer and adjust accordingly.
     final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
     mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
     if (mVelocityTracker != null) {
       mVelocityTracker.clear();
     }
   }
 }
Beispiel #5
0
  private void onSecondaryPointerUp(MotionEvent var1) {
    int var2 = (var1.getAction() & '\uff00') >> 8;
    if (MotionEventCompat.getPointerId(var1, var2) == this.mActivePointerId) {
      byte var3;
      if (var2 == 0) {
        var3 = 1;
      } else {
        var3 = 0;
      }

      this.mLastMotionY = (int) MotionEventCompat.getY(var1, var3);
      this.mActivePointerId = MotionEventCompat.getPointerId(var1, var3);
      if (this.mVelocityTracker != null) {
        this.mVelocityTracker.clear();
      }
    }
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialDownY = getMotionEventY(ev, mActivePointerId);
        if (initialDownY == -1) {
          return false;
        }
        mInitialDownY = initialDownY;
        break;

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
          return false;
        }

        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
          return false;
        }
        final float yDiff = y - mInitialDownY;
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
          mInitialMotionY = mInitialDownY + mTouchSlop;
          mIsBeingDragged = true;
          mProgress.setAlpha(STARTING_PROGRESS_ALPHA);
        }
        break;

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return mIsBeingDragged;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
      return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL
        || action == MotionEvent.ACTION_UP
        || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
      endDrag();
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        determineDrag(ev);
        break;
      case MotionEvent.ACTION_DOWN:
        int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        if (mActivePointerId == INVALID_POINTER) {
          break;
        }

        mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
        mLastMotionY = MotionEventCompat.getY(ev, index);
        if (thisTouchAllowed(ev)) {
          mIsBeingDragged = false;
          mIsUnableToDrag = false;
          if (isMenuOpen()
              && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
            mQuickReturn = true;
          }
        } else {
          mIsUnableToDrag = true;
        }
        break;
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    if (!mIsBeingDragged) {
      if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
      }
      mVelocityTracker.addMovement(ev);
    }
    return mIsBeingDragged || mQuickReturn;
  }
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();

    int action = MotionEventCompat.getActionMasked(ev);

    if ((this.mReturningToStart) && (action == 0)) {
      this.mReturningToStart = false;
    }

    if ((!isEnabled()) || (this.mReturningToStart) || (canChildScrollUp()) || (this.mRefreshing)) {
      return false;
    }

    switch (action) {
      case 0:
        setTargetOffsetTopAndBottom(this.mOriginalOffsetTop - this.mCircleView.getTop(), true);
        this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        this.mIsBeingDragged = false;
        float initialDownY = getMotionEventY(ev, this.mActivePointerId);
        if (initialDownY == -1.0F) {
          return false;
        }
        this.mInitialDownY = initialDownY;
        break;
      case 2:
        if (this.mActivePointerId == -1) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
          return false;
        }

        float y = getMotionEventY(ev, this.mActivePointerId);
        if (y == -1.0F) {
          return false;
        }
        float yDiff = y - this.mInitialDownY;
        if ((yDiff > this.mTouchSlop) && (!this.mIsBeingDragged)) {
          this.mInitialMotionY = (this.mInitialDownY + this.mTouchSlop);
          this.mIsBeingDragged = true;
          this.mProgress.setAlpha(76);
        }
        break;
      case 6:
        onSecondaryPointerUp(ev);
        break;
      case 1:
      case 3:
        this.mIsBeingDragged = false;
        this.mActivePointerId = -1;
      case 4:
      case 5:
    }
    return this.mIsBeingDragged;
  }
  /** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {

    if (!isEnabled() || mNestedScrollInProgress) {
      return false;
    }
    if (!mEnableFresh && !mEnablePullLoad) {
      return false;
    }
    final int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(event, 0);
        mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId);
        mLastEventOffset = (int) mFirstTouchDownPointY;
        break;

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER_ID) {
          return false;
        }

        final float currentY = getMotionEventY(event, mActivePointerId);

        if (currentY == -1) {
          return false;
        }

        if (mFirstTouchDownPointY == -1) {
          mFirstTouchDownPointY = currentY;
        }
        if (mLastEventOffset == -1) mLastEventOffset = (int) currentY;

        final float yDiff = currentY - mFirstTouchDownPointY;

        // State is changed to drag if over slop
        if (Math.abs(yDiff) > ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
          return shouldIntercept((int) yDiff);
        }

        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }

    return false;
  }
 {
     velocitytracker = mVelocityTracker;
     k = MotionEventCompat.getPointerId(motionevent, 0);
     velocitytracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
     f = VelocityTrackerCompat.getYVelocity(velocitytracker, k);
     f1 = VelocityTrackerCompat.getXVelocity(velocitytracker, k);
     if (Math.abs(f) > (float)mMinimumFlingVelocity || Math.abs(f1) > (float)mMinimumFlingVelocity)
     {
         flag3 = mListener.mListener(mCurrentDownEvent, motionevent, f1, f);
     } else
     {
         flag3 = false;
     }
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!isEnabled() || canChildScrollUp() || mRefreshing) {
      return false;
    }

    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        setTargetOffsetTop(0, true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialMotionY = getMotionEventY(ev, mActivePointerId);
        if (initialMotionY == -1) {
          return false;
        }
        mInitialMotionY = initialMotionY;
        break;
      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
          return false;
        }
        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
          return false;
        }
        final float yDiff = y - mInitialMotionY;
        //                if (Math.abs(yDiff) > mTouchSlop && !mIsBeingDragged) {
        //                    mIsBeingDragged = true;
        //                    mMode = yDiff > 0 ? MODE_TOP : MODE_BOTTOM;
        //                }
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
          mIsBeingDragged = true;
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    return mIsBeingDragged;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
          }

          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
          if (mIsBeingDragged) {
            mProgress.showArrow(true);
            float originalDragPercent = overscrollTop / mTotalDragDistance;
            if (originalDragPercent < 0) {
              return false;
            }
            float dragPercent = Math.min(1f, Math.abs(originalDragPercent));
            float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3;
            float extraOS = Math.abs(overscrollTop) - mTotalDragDistance;
            float slingshotDist =
                mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop : mSpinnerFinalOffset;
            float tensionSlingshotPercent =
                Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
            float tensionPercent =
                (float) ((tensionSlingshotPercent / 4) - Math.pow((tensionSlingshotPercent / 4), 2))
                    * 2f;
            float extraMove = (slingshotDist) * tensionPercent * 2;

            int targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
              mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
              ViewCompat.setScaleX(mCircleView, 1f);
              ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
              if (mScale) {
                setAnimationProgress(overscrollTop / mTotalDragDistance);
              }
              if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                  && !isAnimationRunning(mAlphaStartAnimation)) {
                // Animate the alpha
                startProgressAlphaStartAnimation();
              }
              float strokeStart = adjustedPercent * .8f;
              mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
              mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
              if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                // Animate the alpha
                startProgressAlphaMaxAnimation();
              }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(rotation);
            setTargetOffsetTopAndBottom(
                targetY - mCurrentTargetOffsetTop, true /* requires update */);
          }
          break;
        }
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          if (mActivePointerId == INVALID_POINTER) {
            if (action == MotionEvent.ACTION_UP) {
              Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
            }
            return false;
          }
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
          mIsBeingDragged = false;
          if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
          } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            Animation.AnimationListener listener = null;
            if (!mScale) {
              listener =
                  new Animation.AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {}

                    @Override
                    public void onAnimationEnd(Animation animation) {
                      if (!mScale) {
                        startScaleDownAnimation(null);
                      }
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {}
                  };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
          }
          mActivePointerId = INVALID_POINTER;
          return false;
        }
    }

    return true;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {

    if (!mEnabled) return false;

    if (!mIsBeingDragged && !thisTouchAllowed(ev)) return false;

    //		if (!mIsBeingDragged && !mQuickReturn)
    //			return false;

    final int action = ev.getAction();

    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        completeScroll();

        // Remember where the motion event started
        int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        mLastMotionX = mInitialMotionX = ev.getX();
        break;
      case MotionEvent.ACTION_MOVE:
        if (!mIsBeingDragged) {
          determineDrag(ev);
          if (mIsUnableToDrag) return false;
        }
        if (mIsBeingDragged) {
          // Scroll to follow the motion event
          final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
          if (mActivePointerId == INVALID_POINTER) break;
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float deltaX = mLastMotionX - x;
          mLastMotionX = x;
          float oldScrollX = getScrollX();
          float scrollX = oldScrollX + deltaX;
          final float leftBound = getLeftBound();
          final float rightBound = getRightBound();
          if (scrollX < leftBound) {
            scrollX = leftBound;
          } else if (scrollX > rightBound) {
            scrollX = rightBound;
          }
          // Don't lose the rounded component
          mLastMotionX += scrollX - (int) scrollX;
          scrollTo((int) scrollX, getScrollY());
          pageScrolled((int) scrollX);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
          final VelocityTracker velocityTracker = mVelocityTracker;
          velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
          int initialVelocity =
              (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
          final int scrollX = getScrollX();
          final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth();
          final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
          if (mActivePointerId != INVALID_POINTER) {
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final int totalDelta = (int) (x - mInitialMotionX);
            int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta);
            setCurrentItemInternal(nextPage, true, true, initialVelocity);
          } else {
            setCurrentItemInternal(mCurItem, true, true, initialVelocity);
          }
          mActivePointerId = INVALID_POINTER;
          endDrag();
        } else if (mQuickReturn
            && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
          // close the menu
          setCurrentItem(1);
          endDrag();
        }
        break;
      case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged) {
          setCurrentItemInternal(mCurItem, true, true);
          mActivePointerId = INVALID_POINTER;
          endDrag();
        }
        break;
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int indexx = MotionEventCompat.getActionIndex(ev);
          mLastMotionX = MotionEventCompat.getX(ev, indexx);
          mActivePointerId = MotionEventCompat.getPointerId(ev, indexx);
          break;
        }
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        int pointerIndex = getPointerIndex(ev, mActivePointerId);
        if (mActivePointerId == INVALID_POINTER) break;
        mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
        break;
    }
    return true;
  }
  @Override
  public boolean onTouchEvent(@NonNull MotionEvent ev) {

    if (!mIsBeingDragged) {
      return super.onTouchEvent(ev);
    }

    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (pointerIndex < 0) {
            return false;
          }

          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float yDiff = y - mInitialMotionY;
          final float scrollTop = yDiff * DRAG_RATE;
          mCurrentDragPercent = scrollTop / mTotalDragDistance;
          if (mCurrentDragPercent < 0) {
            return false;
          }
          float boundedDragPercent = Math.min(1f, Math.abs(mCurrentDragPercent));
          float extraOS = Math.abs(scrollTop) - mTotalDragDistance;
          float slingshotDist = mTotalDragDistance;
          float tensionSlingshotPercent =
              Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
          float tensionPercent =
              (float) ((tensionSlingshotPercent / 4) - Math.pow((tensionSlingshotPercent / 4), 2))
                  * 2f;
          float extraMove = (slingshotDist) * tensionPercent / 2;
          int targetY = (int) ((slingshotDist * boundedDragPercent) + extraMove);

          mBaseRefreshView.setPercent(mCurrentDragPercent, true);
          setTargetOffsetTop(targetY - mCurrentOffsetTop, true);
          break;
        }
      case MotionEventCompat.ACTION_POINTER_DOWN:
        final int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          if (mActivePointerId == INVALID_POINTER) {
            return false;
          }
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float overScrollTop = (y - mInitialMotionY) * DRAG_RATE;
          mIsBeingDragged = false;
          if (overScrollTop > mTotalDragDistance) {
            setRefreshing(true, true);
          } else {
            mRefreshing = false;
            animateOffsetToStartPosition();
          }
          mActivePointerId = INVALID_POINTER;
          return false;
        }
    }

    return true;
  }
    public boolean onTouchEvent(MotionEvent motionevent)
    {
        float f;
        float f1;
        int i2;
        int j2 = motionevent.getAction();
        if (mVelocityTracker == null)
        {
            mVelocityTracker = VelocityTracker.obtain();
        }
        mVelocityTracker.addMovement(motionevent);
        boolean flag;
        int l;
        int k1;
        if ((j2 & 0xff) == 6)
        {
            flag = true;
        } else
        {
            flag = false;
        }
        if (flag)
        {
            l = MotionEventCompat.getActionIndex(motionevent);
        } else
        {
            l = -1;
        }
        i2 = MotionEventCompat.getPointerCount(motionevent);
        k1 = 0;
        f = 0.0F;
        float f2;
        for (f1 = 0.0F; k1 < i2; f1 = f2)
        {
            float f5 = f;
            f2 = f1;
            if (l != k1)
            {
                f2 = f1 + MotionEventCompat.getX(motionevent, k1);
                f5 = f + MotionEventCompat.getY(motionevent, k1);
            }
            k1++;
            f = f5;
        }

        int i;
        if (flag)
        {
            i = i2 - 1;
        } else
        {
            i = i2;
        }
        f1 /= i;
        f /= i;
        j2 & 0xff;
        JVM INSTR tableswitch 0 6: default 204
    //                   0 383
    //                   1 862
    //                   2 643
    //                   3 1136
    //                   4 204
    //                   5 213
    //                   6 239;
           goto _L1 _L2 _L3 _L4 _L5 _L1 _L6 _L7
_L1:
        return false;
_L6:
        mLastFocusX = f1;
        mDownFocusX = f1;
        mLastFocusY = f;
        mDownFocusY = f;
        cancelTaps();
        return false;
_L7:
        mLastFocusX = f1;
        mDownFocusX = f1;
        mLastFocusY = f;
        mDownFocusY = f;
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
        int i1 = MotionEventCompat.getActionIndex(motionevent);
        int j = MotionEventCompat.getPointerId(motionevent, i1);
        f = VelocityTrackerCompat.getXVelocity(mVelocityTracker, j);
        f1 = VelocityTrackerCompat.getYVelocity(mVelocityTracker, j);
        j = 0;
        while (j < i2) 
        {
            if (j != i1)
            {
                int l1 = MotionEventCompat.getPointerId(motionevent, j);
                float f3 = VelocityTrackerCompat.getXVelocity(mVelocityTracker, l1);
                if (VelocityTrackerCompat.getYVelocity(mVelocityTracker, l1) * f1 + f3 * f < 0.0F)
                {
                    mVelocityTracker.clear();
                    return false;
                }
            }
            j++;
        }
          goto _L8
Beispiel #16
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    // return or not?
    mScaleDetector.onTouchEvent(ev);
    mGestureDetector.onTouchEvent(ev);

    final int action = MotionEventCompat.getActionMasked(ev);
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          final int pointerIndex = MotionEventCompat.getActionIndex(ev);
          final float x = MotionEventCompat.getX(ev, pointerIndex);
          final float y = MotionEventCompat.getY(ev, pointerIndex);

          int index = getActiveIndexByXY(x, y);
          if (index >= 0) {
            mActiveIndex = index;
            mLastTouchX = x;
            mLastTouchY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
          }
          break;
        }

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId != INVALID_POINTER_ID) {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float x = MotionEventCompat.getX(ev, pointerIndex);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float dx = x - mLastTouchX;
          final float dy = y - mLastTouchY;

          Figure figure = mFigures.get(mActiveIndex);
          figure.x += dx;
          figure.y += dy;

          mLastTouchX = x;
          mLastTouchY = y;

          invalidate();
        }
        break;

      case MotionEvent.ACTION_UP:
        {
          if (mActiveIndex >= 0) {
            if (mUpdateFigureListener != null) {
              mUpdateFigureListener.onUpdate(mFigures.get(mActiveIndex));
            }
            mActiveIndex = -1;
          }
          mActivePointerId = INVALID_POINTER_ID;
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          mActivePointerId = INVALID_POINTER_ID;
          mActiveIndex = -1;
          break;
        }

      case MotionEvent.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);

        if (pointerId == mActivePointerId) {
          final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
          mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
          mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
          mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        break;
    }
    return true;
  }
Beispiel #17
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {

    if (!mEnabled) return false;

    //		if (!mIsBeingDragged && !thisTouchAllowed(ev))
    //			return false;

    if (!mIsBeingDragged && !mQuickReturn) return false;

    final int action = ev.getAction();

    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        completeScroll();

        // Remember where the motion event started
        mLastMotionX = mInitialMotionX = ev.getX();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
      case MotionEvent.ACTION_MOVE:
        if (!mIsBeingDragged) {
          if (mActivePointerId == INVALID_POINTER) break;
          final int pointerIndex = getPointerIndex(ev, mActivePointerId);
          final float x = MotionEventCompat.getX(ev, pointerIndex);
          final float dx = x - mLastMotionX;
          final float xDiff = Math.abs(dx);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float yDiff = Math.abs(y - mLastMotionY);
          if (DEBUG)
            Log.v(
                TAG,
                "onTouch moved to:("
                    + x
                    + ", "
                    + y
                    + "), diff:("
                    + xDiff
                    + ", "
                    + yDiff
                    + ")\nmIsBeingDragged:"
                    + mIsBeingDragged
                    + ", mLastMotionX:"
                    + mLastMotionX);
          if ((xDiff > mTouchSlop || (mQuickReturn && xDiff > mTouchSlop / 4))
              && xDiff > yDiff
              && thisSlideAllowed(dx)) {
            if (DEBUG) Log.v(TAG, "Starting drag! from onTouch");
            startDrag();
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
          } else {
            if (DEBUG) Log.v(TAG, "onTouch returning false");
            return false;
          }
        }
        if (mIsBeingDragged) {
          // Scroll to follow the motion event
          final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
          if (mActivePointerId == INVALID_POINTER) {
            break;
          }
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float deltaX = mLastMotionX - x;
          mLastMotionX = x;
          float oldScrollX = getScrollX();
          float scrollX = oldScrollX + deltaX;
          final float leftBound = getLeftBound();
          final float rightBound = getRightBound();
          if (scrollX < leftBound) {
            scrollX = leftBound;
          } else if (scrollX > rightBound) {
            scrollX = rightBound;
          }
          // Don't lose the rounded component
          mLastMotionX += scrollX - (int) scrollX;
          scrollTo((int) scrollX, getScrollY());
          pageScrolled((int) scrollX);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
          final VelocityTracker velocityTracker = mVelocityTracker;
          velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
          int initialVelocity =
              (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
          final int scrollX = getScrollX();
          //				final int widthWithMargin = getWidth();
          //				final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
          // TODO test this. should get better flinging behavior
          final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth();
          final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
          if (mActivePointerId != INVALID_POINTER) {
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final int totalDelta = (int) (x - mInitialMotionX);
            int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta);
            setCurrentItemInternal(nextPage, true, true, initialVelocity);
          } else {
            setCurrentItemInternal(mCurItem, true, true, initialVelocity);
          }
          mActivePointerId = INVALID_POINTER;
          endDrag();
        } else if (mQuickReturn
            && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
          // close the menu
          setCurrentItem(1);
          endDrag();
        }
        break;
      case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged) {
          setCurrentItemInternal(mCurItem, true, true);
          mActivePointerId = INVALID_POINTER;
          endDrag();
        }
        break;
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          final float x = MotionEventCompat.getX(ev, index);
          mLastMotionX = x;
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        int pointerIndex = this.getPointerIndex(ev, mActivePointerId);
        if (mActivePointerId == INVALID_POINTER) break;
        mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
        break;
    }
    return true;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent e) {

    final boolean canScrollHorizontally = false; // mLayout.canScrollHorizontally();
    final boolean canScrollVertically = true; // mLayout.canScrollVertically();

    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(e);

    final int action = MotionEventCompat.getActionMasked(e);
    final int actionIndex = MotionEventCompat.getActionIndex(e);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        if (mIgnoreMotionEventTillDown) {
          mIgnoreMotionEventTillDown = false;
        }
        mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f);
        mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f);

        if (mScrollState == SCROLL_STATE_SETTLING) {
          getParent().requestDisallowInterceptTouchEvent(true);
          setScrollState(SCROLL_STATE_DRAGGING);
        }

        // Clear the nested offsets
        mNestedOffsets[0] = mNestedOffsets[1] = 0;

        int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;
        if (canScrollHorizontally) {
          nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL;
        }
        if (canScrollVertically) {
          nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;
        }
        startNestedScroll(nestedScrollAxis);
        break;

      case MotionEventCompat.ACTION_POINTER_DOWN:
        mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex);
        mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
        mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
          if (index < 0) {
            Log.e(
                TAG,
                "Error processing scroll; pointer index for id "
                    + mScrollPointerId
                    + " not found. Did any MotionEvents get skipped?");
            return false;
          }

          final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
          final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
          if (mScrollState != SCROLL_STATE_DRAGGING) {
            final int dx = x - mInitialTouchX;
            final int dy = y - mInitialTouchY;
            boolean startScroll = false;
            if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) {
              mLastTouchX = mInitialTouchX + mTouchSlop * (dx < 0 ? -1 : 1);
              startScroll = true;
            }
            if (canScrollVertically && Math.abs(dy) > mTouchSlop) {
              mLastTouchY = mInitialTouchY + mTouchSlop * (dy < 0 ? -1 : 1);
              startScroll = true;
            }
            if (startScroll) {
              setScrollState(SCROLL_STATE_DRAGGING);
            }
          }
        }
        break;

      case MotionEventCompat.ACTION_POINTER_UP:
        {
          onPointerUp(e);
        }
        break;

      case MotionEvent.ACTION_UP:
        {
          mVelocityTracker.clear();
          stopNestedScroll();
        }
        break;

      case MotionEvent.ACTION_CANCEL:
        {
          cancelTouch();
        }
    }
    return mScrollState == SCROLL_STATE_DRAGGING;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mStartPoint = mInitialMotionY;

        // 这里用up/down记录子控件能否下拉,如果当前子控件不能上下滑动,但当手指按下并移动子控件时,控件就会变得可滑动
        // 后面的一些处理不能直接使用canChildScrollUp/canChildScrollDown
        // 但仍存在问题:当数据不满一屏且设置可以上拉模式后,多次快速上拉会激发上拉加载
        up = canChildScrollUp();
        down = canChildScrollDown();
        break;

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
          return false;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
          return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        //                final float yDiff = y - mInitialMotionY;
        final float yDiff = y - mStartPoint;
        // 若上个手势的方向和当前手势方向不一致,返回
        if ((mLastDirection == Mode.PULL_FROM_START && yDiff < 0)
            || (mLastDirection == Mode.PULL_FROM_END && yDiff > 0)) {
          return false;
        }
        // 下拉或上拉时,子控件本身能够滑动时,记录当前手指位置,当其滑动到尽头时,
        // mStartPoint作为下拉刷新或上拉加载的手势起点
        if ((canChildScrollUp() && yDiff > 0) || (canChildScrollDown() && yDiff < 0)) {
          mStartPoint = y;
        }

        // 下拉
        if (yDiff > mTouchSlop) {
          // 若当前子控件能向下滑动,或者上个手势为上拉,则返回
          if (canChildScrollUp() || mLastDirection == Mode.PULL_FROM_END) {
            mIsBeingDragged = false;
            return false;
          }
          if ((mMode == Mode.PULL_FROM_START) || (mMode == Mode.BOTH)) {
            mLastMotionY = y;
            mIsBeingDragged = true;
            mLastDirection = Mode.PULL_FROM_START;
          }
        }
        // 上拉
        else if (-yDiff > mTouchSlop) {
          // 若当前子控件能向上滑动,或者上个手势为下拉,则返回
          if (canChildScrollDown() || mLastDirection == Mode.PULL_FROM_START) {
            mIsBeingDragged = false;
            return false;
          }
          // 若子控件不能上下滑动,说明数据不足一屏,若不满屏不加载,返回
          if (!up && !down && !loadNoFull) {
            mIsBeingDragged = false;
            return false;
          }
          if ((mMode == Mode.PULL_FROM_END) || (mMode == Mode.BOTH)) {
            mLastMotionY = y;
            mIsBeingDragged = true;
            mLastDirection = Mode.PULL_FROM_END;
          }
        }
        break;

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        mLastDirection = Mode.DISABLED;
        break;
    }

    return mIsBeingDragged;
  }
  @Override
  public boolean onTouchEvent(MotionEvent e) {
    /*
    if (mLayoutFrozen || mIgnoreMotionEventTillDown) {
        return false;
    }
    if (dispatchOnItemTouch(e)) {
        cancelTouch();
        return true;
    }

    if (mLayout == null) {
        return false;
    }
    */

    final boolean canScrollHorizontally = false; // mLayout.canScrollHorizontally();
    final boolean canScrollVertically = true; // mLayout.canScrollVertically();

    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    boolean eventAddedToVelocityTracker = false;

    final MotionEvent vtev = MotionEvent.obtain(e);
    final int action = MotionEventCompat.getActionMasked(e);
    final int actionIndex = MotionEventCompat.getActionIndex(e);

    if (action == MotionEvent.ACTION_DOWN) {
      mNestedOffsets[0] = mNestedOffsets[1] = 0;
    }
    vtev.offsetLocation(mNestedOffsets[0], mNestedOffsets[1]);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
          mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f);
          mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f);

          int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;
          if (canScrollHorizontally) {
            nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL;
          }
          if (canScrollVertically) {
            nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;
          }
          startNestedScroll(nestedScrollAxis);
        }
        break;

      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex);
          mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
          mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
        }
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
          if (index < 0) {
            Log.e(
                TAG,
                "Error processing scroll; pointer index for id "
                    + mScrollPointerId
                    + " not found. Did any MotionEvents get skipped?");
            return false;
          }

          final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
          final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
          int dx = mLastTouchX - x;
          int dy = mLastTouchY - y;

          if (dispatchNestedPreScroll(dx, dy, mScrollConsumed, mScrollOffset)) {
            dx -= mScrollConsumed[0];
            dy -= mScrollConsumed[1];
            vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
            // Updated the nested offsets
            mNestedOffsets[0] += mScrollOffset[0];
            mNestedOffsets[1] += mScrollOffset[1];
          }

          if (mScrollState != SCROLL_STATE_DRAGGING) {
            boolean startScroll = false;
            if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) {
              if (dx > 0) {
                dx -= mTouchSlop;
              } else {
                dx += mTouchSlop;
              }
              startScroll = true;
            }
            if (canScrollVertically && Math.abs(dy) > mTouchSlop) {
              if (dy > 0) {
                dy -= mTouchSlop;
              } else {
                dy += mTouchSlop;
              }
              startScroll = true;
            }
            if (startScroll) {
              setScrollState(SCROLL_STATE_DRAGGING);
            }
          }

          if (mScrollState == SCROLL_STATE_DRAGGING) {
            mLastTouchX = x - mScrollOffset[0];
            mLastTouchY = y - mScrollOffset[1];

            if (scrollByInternal(
                canScrollHorizontally ? dx : 0, canScrollVertically ? dy : 0, vtev)) {
              getParent().requestDisallowInterceptTouchEvent(true);
            }
          }
        }
        break;

      case MotionEventCompat.ACTION_POINTER_UP:
        {
          onPointerUp(e);
        }
        break;

      case MotionEvent.ACTION_UP:
        {
          mVelocityTracker.addMovement(vtev);
          eventAddedToVelocityTracker = true;
          mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity);
          final float xvel =
              canScrollHorizontally
                  ? -VelocityTrackerCompat.getXVelocity(mVelocityTracker, mScrollPointerId)
                  : 0;
          final float yvel =
              canScrollVertically
                  ? -VelocityTrackerCompat.getYVelocity(mVelocityTracker, mScrollPointerId)
                  : 0;
          if (!((xvel != 0 || yvel != 0) && fling((int) xvel, (int) yvel))) {
            setScrollState(SCROLL_STATE_IDLE);
          }
          resetTouch();
        }
        break;

      case MotionEvent.ACTION_CANCEL:
        {
          cancelTouch();
        }
        break;
    }

    if (!eventAddedToVelocityTracker) {
      mVelocityTracker.addMovement(vtev);
    }
    vtev.recycle();

    return true;
  }
Beispiel #21
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {

    if (!mIsFlippingEnabled) {
      return false;
    }

    if (mPageCount < 1) {
      return false;
    }

    if (!mIsFlipping && !mLastTouchAllowed) {
      return false;
    }

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP
        || action == MotionEvent.ACTION_CANCEL
        || action == MotionEvent.ACTION_OUTSIDE) {
      mLastTouchAllowed = false;
    } else {
      mLastTouchAllowed = true;
    }

    trackVelocity(ev);

    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:

        // start flipping immediately if interrupting some sort of animation
        if (endScroll() || endPeak()) {
          mIsFlipping = true;
        }

        // Remember where the motion event started
        mLastX = ev.getX();
        mLastY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
      case MotionEvent.ACTION_MOVE:
        if (!mIsFlipping) {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (pointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
          }
          final float x = MotionEventCompat.getX(ev, pointerIndex);
          final float xDiff = Math.abs(x - mLastX);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float yDiff = Math.abs(y - mLastY);
          if ((mIsFlippingVertically && yDiff > mTouchSlop && yDiff > xDiff)
              || (!mIsFlippingVertically && xDiff > mTouchSlop && xDiff > yDiff)) {
            mIsFlipping = true;
            mLastX = x;
            mLastY = y;
          }
        }
        if (mIsFlipping) {
          // Scroll to follow the motion event
          final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (activePointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
          }
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float deltaX = mLastX - x;
          final float y = MotionEventCompat.getY(ev, activePointerIndex);
          final float deltaY = mLastY - y;
          mLastX = x;
          mLastY = y;

          float deltaFlipDistance = 0;
          if (mIsFlippingVertically) {
            deltaFlipDistance = deltaY;
          } else {
            deltaFlipDistance = deltaX;
          }

          deltaFlipDistance /=
              ((isFlippingVertically() ? getHeight() : getWidth()) / FLIP_DISTANCE_PER_PAGE);
          setFlipDistance(mFlipDistance + deltaFlipDistance);

          final int minFlipDistance = 0;
          final int maxFlipDistance = (mPageCount - 1) * FLIP_DISTANCE_PER_PAGE;
          final boolean isOverFlipping =
              mFlipDistance < minFlipDistance || mFlipDistance > maxFlipDistance;
          if (isOverFlipping) {
            mIsOverFlipping = true;
            setFlipDistance(
                mOverFlipper.calculate(mFlipDistance, minFlipDistance, maxFlipDistance));
            if (mOnOverFlipListener != null) {
              float overFlip = mOverFlipper.getTotalOverFlip();
              mOnOverFlipListener.onOverFlip(
                  this, mOverFlipMode, overFlip < 0, Math.abs(overFlip), FLIP_DISTANCE_PER_PAGE);
            }
          } else if (mIsOverFlipping) {
            mIsOverFlipping = false;
            if (mOnOverFlipListener != null) {
              // TODO in the future should only notify flip distance 0
              // on the correct edge (previous/next)
              mOnOverFlipListener.onOverFlip(this, mOverFlipMode, false, 0, FLIP_DISTANCE_PER_PAGE);
              mOnOverFlipListener.onOverFlip(this, mOverFlipMode, true, 0, FLIP_DISTANCE_PER_PAGE);
            }
          }
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mIsFlipping) {
          final VelocityTracker velocityTracker = mVelocityTracker;
          velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);

          int velocity = 0;
          if (isFlippingVertically()) {
            velocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
          } else {
            velocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
          }
          smoothFlipTo(getNextPage(velocity));

          mActivePointerId = INVALID_POINTER;
          endFlip();

          mOverFlipper.overFlipEnded();
        }
        break;
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          final float x = MotionEventCompat.getX(ev, index);
          final float y = MotionEventCompat.getY(ev, index);
          mLastX = x;
          mLastY = y;
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, index);
        final float y = MotionEventCompat.getY(ev, index);
        mLastX = x;
        mLastY = y;
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
      mLastTouchAllowed = false;
    }
    return true;
  }
 public boolean onTouchEvent(MotionEvent paramMotionEvent)
 {
   if (super.onTouchEvent(paramMotionEvent)) {}
   label322:
   do
   {
     int i1;
     do
     {
       int i5;
       float f1;
       float f2;
       do
       {
         float f4;
         do
         {
           float f3;
           do
           {
             return true;
             if ((this.e == null) || (this.e.getAdapter().getCount() == 0)) {
               return false;
             }
             i1 = 0xFF & paramMotionEvent.getAction();
             switch (i1)
             {
             case 4: 
             default: 
               return true;
             case 0: 
               this.p = MotionEventCompat.getPointerId(paramMotionEvent, 0);
               this.o = paramMotionEvent.getX();
               return true;
             case 2: 
               f3 = MotionEventCompat.getX(paramMotionEvent, MotionEventCompat.findPointerIndex(paramMotionEvent, this.p));
               f4 = f3 - this.o;
               if ((!this.q) && (Math.abs(f4) > this.n)) {
                 this.q = true;
               }
               break;
             }
           } while (!this.q);
           this.o = f3;
         } while ((!this.e.isFakeDragging()) && (!this.e.beginFakeDrag()));
         this.e.fakeDragBy(f4);
         return true;
         if (this.q) {
           break label322;
         }
         i5 = this.e.getAdapter().getCount();
         int i6 = getWidth();
         f1 = i6 / 2.0F;
         f2 = i6 / 6.0F;
         if ((this.g <= 0) || (paramMotionEvent.getX() >= f1 - f2)) {
           break;
         }
       } while (i1 == 3);
       this.e.setCurrentItem(-1 + this.g);
       return true;
       if ((this.g >= i5 - 1) || (paramMotionEvent.getX() <= f2 + f1)) {
         break;
       }
     } while (i1 == 3);
     this.e.setCurrentItem(1 + this.g);
     return true;
     this.q = false;
     this.p = -1;
   } while (!this.e.isFakeDragging());
   this.e.endFakeDrag();
   return true;
   int i4 = MotionEventCompat.getActionIndex(paramMotionEvent);
   this.o = MotionEventCompat.getX(paramMotionEvent, i4);
   this.p = MotionEventCompat.getPointerId(paramMotionEvent, i4);
   return true;
   int i2 = MotionEventCompat.getActionIndex(paramMotionEvent);
   if (MotionEventCompat.getPointerId(paramMotionEvent, i2) == this.p)
   {
     int i3 = 0;
     if (i2 == 0) {
       i3 = 1;
     }
     this.p = MotionEventCompat.getPointerId(paramMotionEvent, i3);
   }
   this.o = MotionEventCompat.getX(paramMotionEvent, MotionEventCompat.findPointerIndex(paramMotionEvent, this.p));
   return true;
 }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mStartPoint = mInitialMotionY;

        up = canChildScrollUp();
        down = canChildScrollDown();
        break;

      case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
          return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        //                final float yDiff = y - mInitialMotionY;
        final float yDiff = y - mStartPoint;

        if ((mLastDirection == Mode.PULL_FROM_START && yDiff < 0)
            || (mLastDirection == Mode.PULL_FROM_END && yDiff > 0)) {
          return true;
        }

        if (!mIsBeingDragged && (yDiff > 0 && mLastDirection == Mode.PULL_FROM_START)
            || (yDiff < 0 && mLastDirection == Mode.PULL_FROM_END)) {
          mIsBeingDragged = true;
        }

        if (mIsBeingDragged) {
          // User velocity passed min velocity; trigger a refresh
          if (yDiff > mDistanceToTriggerSync) {
            // User movement passed distance; trigger a refresh
            if (mLastDirection == Mode.PULL_FROM_END) {
              return true;
            }
            if ((mMode == Mode.PULL_FROM_START) || (mMode == Mode.BOTH)) {
              mLastDirection = Mode.PULL_FROM_START;
              startRefresh();
            }
          } else if (-yDiff > mDistanceToTriggerSync) {
            if ((!up && !down && !loadNoFull) || mLastDirection == Mode.PULL_FROM_START) {
              return true;
            }
            if ((mMode == Mode.PULL_FROM_END) || (mMode == Mode.BOTH)) {
              mLastDirection = Mode.PULL_FROM_END;
              startLoad();
            }
          } else {
            if (!up && !down && yDiff < 0 && !loadNoFull) {
              return true;
            }
            // Just track the user's movement
            // 根据手指移动距离设置进度条显示的百分比
            setTriggerPercentage(
                mAccelerateInterpolator.getInterpolation(Math.abs(yDiff) / mDistanceToTriggerSync));
            updateContentOffsetTop((int) yDiff);
            if (mTarget.getTop() == getPaddingTop()) {
              // If the user puts the view back at the top, we
              // don't need to. This shouldn't be considered
              // cancelling the gesture as the user can restart from the top.
              removeCallbacks(mCancel);
              mLastDirection = Mode.DISABLED;
            } else {
              mDirection = (yDiff > 0 ? 1 : -1);
              updatePositionTimeout();
            }
          }
          mLastMotionY = y;
        }
        break;

      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          mLastMotionY = MotionEventCompat.getY(ev, index);
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        mLastDirection = Mode.DISABLED;
        return false;
    }

    return true;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
          }

          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
          if (mIsBeingDragged) {
            if (overscrollTop > 0) {
              moveSpinner(overscrollTop);
            } else {
              return false;
            }
          }
          break;
        }
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          if (mActivePointerId == INVALID_POINTER) {
            if (action == MotionEvent.ACTION_UP) {
              Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
            }
            return false;
          }
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
          mIsBeingDragged = false;
          finishSpinner(overscrollTop);
          mActivePointerId = INVALID_POINTER;
          return false;
        }
    }

    return true;
  }
  public boolean onTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);

    if ((this.mReturningToStart) && (action == 0)) {
      this.mReturningToStart = false;
    }

    if ((!isEnabled()) || (this.mReturningToStart) || (canChildScrollUp())) {
      return false;
    }

    switch (action) {
      case 0:
        this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        this.mIsBeingDragged = false;
        break;
      case 2:
        int pointerIndex = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId);
        if (pointerIndex < 0) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
          return false;
        }

        float y = MotionEventCompat.getY(ev, pointerIndex);
        float overscrollTop = (y - this.mInitialMotionY) * 0.5F;
        if (this.mIsBeingDragged) {
          this.mProgress.showArrow(true);
          float originalDragPercent = overscrollTop / this.mTotalDragDistance;
          if (originalDragPercent < 0.0F) {
            return false;
          }
          float dragPercent = Math.min(1.0F, Math.abs(originalDragPercent));
          float adjustedPercent = (float) Math.max(dragPercent - 0.4D, 0.0D) * 5.0F / 3.0F;
          float extraOS = Math.abs(overscrollTop) - this.mTotalDragDistance;
          float slingshotDist =
              this.mUsingCustomStart
                  ? this.mSpinnerFinalOffset - this.mOriginalOffsetTop
                  : this.mSpinnerFinalOffset;

          float tensionSlingshotPercent =
              Math.max(0.0F, Math.min(extraOS, slingshotDist * 2.0F) / slingshotDist);

          float tensionPercent =
              (float)
                      (tensionSlingshotPercent / 4.0F
                          - Math.pow(tensionSlingshotPercent / 4.0F, 2.0D))
                  * 2.0F;

          float extraMove = slingshotDist * tensionPercent * 2.0F;

          int targetY = this.mOriginalOffsetTop + (int) (slingshotDist * dragPercent + extraMove);

          if (this.mCircleView.getVisibility() != 0) {
            this.mCircleView.setVisibility(0);
          }
          if (!this.mScale) {
            ViewCompat.setScaleX(this.mCircleView, 1.0F);
            ViewCompat.setScaleY(this.mCircleView, 1.0F);
          }
          if (overscrollTop < this.mTotalDragDistance) {
            if (this.mScale) {
              setAnimationProgress(overscrollTop / this.mTotalDragDistance);
            }
            if ((this.mProgress.getAlpha() > 76)
                && (!isAnimationRunning(this.mAlphaStartAnimation))) {
              startProgressAlphaStartAnimation();
            }
            float strokeStart = adjustedPercent * 0.8F;
            this.mProgress.setStartEndTrim(0.0F, Math.min(0.8F, strokeStart));
            this.mProgress.setArrowScale(Math.min(1.0F, adjustedPercent));
          } else if ((this.mProgress.getAlpha() < 255)
              && (!isAnimationRunning(this.mAlphaMaxAnimation))) {
            startProgressAlphaMaxAnimation();
          }

          float rotation = (-0.25F + 0.4F * adjustedPercent + tensionPercent * 2.0F) * 0.5F;
          this.mProgress.setProgressRotation(rotation);
          setTargetOffsetTopAndBottom(targetY - this.mCurrentTargetOffsetTop, true);
        }
        break;
      case 5:
        int index = MotionEventCompat.getActionIndex(ev);
        this.mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
      case 6:
        onSecondaryPointerUp(ev);
        break;
      case 1:
      case 3:
        if (this.mActivePointerId == -1) {
          if (action == 1) {
            Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
          }
          return false;
        }
        int pointerIndex_1 = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId);
        float y_1 = MotionEventCompat.getY(ev, pointerIndex_1);
        float overscrollTop_1 = (y_1 - this.mInitialMotionY) * 0.5F;
        this.mIsBeingDragged = false;
        if (overscrollTop_1 > this.mTotalDragDistance) {
          setRefreshing(true, true);
        } else {
          this.mRefreshing = false;
          this.mProgress.setStartEndTrim(0.0F, 0.0F);
          Animation.AnimationListener listener = null;
          if (!this.mScale)
            listener =
                new Animation.AnimationListener() {
                  public void onAnimationStart(Animation animation) {}

                  public void onAnimationEnd(Animation animation) {
                    if (!MySwipeRefreshLayout.this.mScale)
                      MySwipeRefreshLayout.this.startScaleDownAnimation(null);
                  }

                  public void onAnimationRepeat(Animation animation) {}
                };
          animateOffsetToStartPosition(this.mCurrentTargetOffsetTop, listener);
          this.mProgress.showArrow(false);
        }
        this.mActivePointerId = -1;
        return false;
      case 4:
    }

    return true;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled
        || !mIsDragging
            && !mLastTouchAllowed
            && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
      return false;
    }

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP
        || action == MotionEvent.ACTION_CANCEL
        || action == MotionEvent.ACTION_OUTSIDE) {
      mLastTouchAllowed = false;
    } else {
      mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
      case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
          final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (pointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
          }
          final float x = MotionEventCompat.getX(ev, pointerIndex);
          final float xDiff = Math.abs(x - mLastX);
          final float y = MotionEventCompat.getY(ev, pointerIndex);
          final float yDiff = Math.abs(y - mLastY);
          if (xDiff > mTouchSlop && xDiff > yDiff) {
            mIsDragging = true;
            mLastX = x;
            setDrawingCacheEnabled(true);
          } else if (yDiff > mTouchSlop && yDiff > xDiff) {
            mIsDragging = true;
            mLastY = y;
            setDrawingCacheEnabled(true);
          }
        }
        if (mIsDragging) {
          // Scroll to follow the motion event
          final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          if (activePointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
          }
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float y = MotionEventCompat.getY(ev, activePointerIndex);
          final float deltaX = mLastX - x;
          final float deltaY = mLastY - y;
          mLastX = x;
          mLastY = y;
          final float oldScrollX = getScrollX();
          final float oldScrollY = getScrollY();
          float scrollX = oldScrollX + deltaX;
          float scrollY = oldScrollY + deltaY;

          // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
          final float leftBound, rightBound;
          final float bottomBound, topBound;
          switch (mScreenSide) {
            case STICK_TO_LEFT:
              topBound = bottomBound = rightBound = 0;
              leftBound = getWidth(); // How far left we can scroll
              break;
            case STICK_TO_MIDDLE:
              topBound = getHeight();
              bottomBound = -getHeight();
              leftBound = getWidth();
              rightBound = -getWidth();
              break;
            case STICK_TO_RIGHT:
              rightBound = -getWidth();
              topBound = bottomBound = leftBound = 0;
              break;
            case STICK_TO_TOP:
              topBound = getHeight();
              bottomBound = rightBound = leftBound = 0;
              break;
            case STICK_TO_BOTTOM:
              topBound = rightBound = leftBound = 0;
              bottomBound = -getHeight();
              break;
            default:
              topBound = bottomBound = rightBound = leftBound = 0;
              break;
          }
          if (scrollX > leftBound) {
            scrollX = leftBound;
          } else if (scrollX < rightBound) {
            scrollX = rightBound;
          }
          if (scrollY > topBound) {
            scrollY = topBound;
          } else if (scrollY < bottomBound) {
            scrollY = bottomBound;
          }

          // Keep the precision
          mLastX += scrollX - (int) scrollX;
          mLastY += scrollY - (int) scrollY;
          scrollTo((int) scrollX, (int) scrollY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mIsDragging) {
          final VelocityTracker velocityTracker = mVelocityTracker;
          velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
          final int initialVelocityX =
              (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
          final int initialVelocityY =
              (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
          final int scrollX = getScrollX();
          final int scrollY = getScrollY();
          final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float y = MotionEventCompat.getY(ev, activePointerIndex);
          final int totalDeltaX = (int) (x - mInitialX);
          final int totalDeltaY = (int) (y - mInitialY);

          boolean nextStateOpened =
              determineNextStateOpened(
                  mIsOpen,
                  scrollX,
                  scrollY,
                  initialVelocityX,
                  initialVelocityY,
                  totalDeltaX,
                  totalDeltaY);
          switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

          mActivePointerId = INVALID_POINTER;
          endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
          closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
          openLayer(true);
        }
        break;
      case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
          switchLayer(mIsOpen, true, true);
          mActivePointerId = INVALID_POINTER;
          endDrag();
        }
        break;
      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          mLastX = MotionEventCompat.getX(ev, index);
          mLastY = MotionEventCompat.getY(ev, index);
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX =
            MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY =
            MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
      mLastTouchAllowed = false;
    }
    return true;
  }
  @Override
  public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) return true;
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) return false;

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float deltaX = x - mLastMotionX;

          if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
              mIsDragging = true;
            }
          }

          if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
              mViewPager.fakeDragBy(deltaX);
            }
          }

          break;
        }

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
          final int count = mViewPager.getAdapter().getCount();
          final int width = getWidth();
          final float halfWidth = width / 2f;
          final float sixthWidth = width / 6f;
          final float leftThird = halfWidth - sixthWidth;
          final float rightThird = halfWidth + sixthWidth;
          final float eventX = ev.getX();

          if (eventX < leftThird) {
            if (mCurrentPage > 0) {
              if (action != MotionEvent.ACTION_CANCEL) {
                mViewPager.setCurrentItem(mCurrentPage - 1);
              }
              return true;
            }
          } else if (eventX > rightThird) {
            if (mCurrentPage < count - 1) {
              if (action != MotionEvent.ACTION_CANCEL) {
                mViewPager.setCurrentItem(mCurrentPage + 1);
              }
              return true;
            }
          } else {
            // Middle third
            if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) {
              mCenterItemClickListener.onCenterItemClick(mCurrentPage);
            }
          }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging()) {
          mViewPager.endFakeDrag();
        }
        break;

      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          mLastMotionX = MotionEventCompat.getX(ev, index);
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }

      case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
          final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
          mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX =
            MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
  }
 public boolean onTouchEvent(MotionEvent paramMotionEvent) {
   int i1 = 0;
   if (super.onTouchEvent(paramMotionEvent)) {}
   label317:
   do {
     do {
       float f1;
       float f2;
       do {
         do {
           do {
             return true;
             if ((f == null) || (f.getAdapter().getCount() == 0)) {
               return false;
             }
             i2 = paramMotionEvent.getAction() & 0xFF;
             switch (i2) {
               case 4:
               default:
                 return true;
               case 0:
                 a = MotionEventCompat.getPointerId(paramMotionEvent, 0);
                 p = paramMotionEvent.getX();
                 return true;
               case 2:
                 f1 =
                     MotionEventCompat.getX(
                         paramMotionEvent,
                         MotionEventCompat.findPointerIndex(paramMotionEvent, a));
                 f2 = f1 - p;
                 if ((!q) && (Math.abs(f2) > o)) {
                   q = true;
                 }
                 break;
             }
           } while (!q);
           p = f1;
         } while ((!f.isFakeDragging()) && (!f.beginFakeDrag()));
         f.fakeDragBy(f2);
         return true;
         if (q) {
           break label317;
         }
         i1 = f.getAdapter().getCount();
         int i3 = getWidth();
         f1 = i3 / 2.0F;
         f2 = i3 / 6.0F;
         if ((h <= 0) || (paramMotionEvent.getX() >= f1 - f2)) {
           break;
         }
       } while (i2 == 3);
       f.setCurrentItem(h - 1);
       return true;
       if ((h >= i1 - 1) || (paramMotionEvent.getX() <= f2 + f1)) {
         break;
       }
     } while (i2 == 3);
     f.setCurrentItem(h + 1);
     return true;
     q = false;
     a = -1;
   } while (!f.isFakeDragging());
   f.endFakeDrag();
   return true;
   i1 = MotionEventCompat.getActionIndex(paramMotionEvent);
   p = MotionEventCompat.getX(paramMotionEvent, i1);
   a = MotionEventCompat.getPointerId(paramMotionEvent, i1);
   return true;
   int i2 = MotionEventCompat.getActionIndex(paramMotionEvent);
   if (MotionEventCompat.getPointerId(paramMotionEvent, i2) == a) {
     if (i2 == 0) {
       i1 = 1;
     }
     a = MotionEventCompat.getPointerId(paramMotionEvent, i1);
   }
   p =
       MotionEventCompat.getX(
           paramMotionEvent, MotionEventCompat.findPointerIndex(paramMotionEvent, a));
   return true;
 }
  public boolean onTouchEvent(android.view.MotionEvent ev) {
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
      return false;
    }

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

      case MotionEvent.ACTION_MOVE:
        {
          final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
          final float x = MotionEventCompat.getX(ev, activePointerIndex);
          final float deltaX = x - mLastMotionX;

          if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
              mIsDragging = true;
            }
          }

          if (mIsDragging) {
            if (!mViewPager.isFakeDragging()) {
              mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;

            mViewPager.fakeDragBy(deltaX);
          }

          break;
        }

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
          final int count = mViewPager.getAdapter().getCount();
          final int width = getWidth();
          final float halfWidth = width / 2f;
          final float sixthWidth = width / 6f;

          if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
            mViewPager.setCurrentItem(mCurrentPage - 1);
            return true;
          } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
            mViewPager.setCurrentItem(mCurrentPage + 1);
            return true;
          }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag();
        break;

      case MotionEventCompat.ACTION_POINTER_DOWN:
        {
          final int index = MotionEventCompat.getActionIndex(ev);
          final float x = MotionEventCompat.getX(ev, index);
          mLastMotionX = x;
          mActivePointerId = MotionEventCompat.getPointerId(ev, index);
          break;
        }

      case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
          final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
          mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX =
            MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
  };
Beispiel #30
0
  @Override
  public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    Log.d(TAG, "onInterceptTouchEvent: " + e.getAction());

    int action = MotionEventCompat.getActionMasked(e);
    int x = (int) e.getX();
    int y = (int) e.getY();

    // 如果RecyclerView滚动状态不是空闲targetView不是空
    if (rv.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
      if (mTargetView != null) {
        // 隐藏已经打开
        smoothHorizontalExpandOrCollapse(DEFAULT_DURATION / 2);
        mTargetView = null;
      }

      return false;
    }

    // 如果正在运行动画 ,直接拦截什么都不做
    if (mExpandAndCollapseAnim != null && mExpandAndCollapseAnim.isRunning()) {
      return true;
    }

    boolean needIntercept = false;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mLastX = (int) e.getX();
        mLastY = (int) e.getY();

        /*
         * 如果之前有一个已经打开的项目,当此次点击事件没有发生在右侧的菜单中则返回TRUE,
         * 如果点击的是右侧菜单那么返回FALSE这样做的原因是因为菜单需要响应Onclick
         * */
        if (mTargetView != null) {
          return !inView(x, y);
        }

        // 查找需要显示菜单的view;
        mTargetView = mCallback.findTargetView(x, y);

        break;
      case MotionEvent.ACTION_MOVE:
        int deltaX = (x - mLastX);
        int deltaY = (y - mLastY);

        if (Math.abs(deltaY) > Math.abs(deltaX)) return false;

        // 如果移动距离达到要求,则拦截
        needIntercept = mIsDragging = mTargetView != null && Math.abs(deltaX) >= mTouchSlop;
        break;

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        /*
         * 走这是因为没有发生过拦截事件
         * */
        if (isExpanded()) {

          if (inView(x, y)) {
            // 如果走这那行这个ACTION_UP的事件会发生在右侧的菜单中
            Log.d(TAG, "click item");
          } else {
            // 拦截事件,防止targetView执行onClick事件
            needIntercept = true;
          }

          // 折叠菜单
          smoothHorizontalExpandOrCollapse(DEFAULT_DURATION / 2);
        }

        mTargetView = null;
        break;
    }

    return needIntercept;
  }