Java Code Examples for android.view.VelocityTracker#computeCurrentVelocity()
The following examples show how to use
android.view.VelocityTracker#computeCurrentVelocity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XBannerViewPager.java From XBanner with Apache License 2.0 | 6 votes |
private float getXVelocity() { float xVelocity = 0; Class viewpagerClass = ViewPager.class; try { Field velocityTrackerField = viewpagerClass.getDeclaredField("mVelocityTracker"); velocityTrackerField.setAccessible(true); VelocityTracker velocityTracker = (VelocityTracker) velocityTrackerField.get(this); Field activePointerIdField = viewpagerClass.getDeclaredField("mActivePointerId"); activePointerIdField.setAccessible(true); Field maximumVelocityField = viewpagerClass.getDeclaredField("mMaximumVelocity"); maximumVelocityField.setAccessible(true); int maximumVelocity = maximumVelocityField.getInt(this); velocityTracker.computeCurrentVelocity(1000, maximumVelocity); xVelocity = VelocityTrackerCompat.getXVelocity(velocityTracker, activePointerIdField.getInt(this)); } catch (Exception ignored) { } return xVelocity; }
Example 2
Source File: Utils.java From iMoney with Apache License 2.0 | 6 votes |
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev, VelocityTracker tracker) { // Check the dot product of current velocities. // If the pointer that left was opposing another velocity vector, clear. tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); final int upIndex = ev.getActionIndex(); final int id1 = ev.getPointerId(upIndex); final float x1 = tracker.getXVelocity(id1); final float y1 = tracker.getYVelocity(id1); for (int i = 0, count = ev.getPointerCount(); i < count; i++) { if (i == upIndex) continue; final int id2 = ev.getPointerId(i); final float x = x1 * tracker.getXVelocity(id2); final float y = y1 * tracker.getYVelocity(id2); final float dot = x + y; if (dot < 0) { tracker.clear(); break; } } }
Example 3
Source File: CustomViewPager.java From AsteroidOSSync with GNU General Public License v3.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } if (mAdapter != null) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor; final int totalDelta = (int) (mLastMotionX - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); } endDrag(); mFakeDragging = false; }
Example 4
Source File: VerticalViewPager.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int height = getClientHeight(); final int scrollY = getScrollY(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor; final int totalDelta = (int) (mLastMotionY - mInitialMotionY); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 5
Source File: BGAViewPager.java From KUtils-master with Apache License 2.0 | 6 votes |
private float getXVelocity() { float xVelocity = 0; Class viewpagerClass = ViewPager.class; try { Field velocityTrackerField = viewpagerClass.getDeclaredField("mVelocityTracker"); velocityTrackerField.setAccessible(true); VelocityTracker velocityTracker = (VelocityTracker) velocityTrackerField.get(this); Field activePointerIdField = viewpagerClass.getDeclaredField("mActivePointerId"); activePointerIdField.setAccessible(true); Field maximumVelocityField = viewpagerClass.getDeclaredField("mMaximumVelocity"); maximumVelocityField.setAccessible(true); int maximumVelocity = maximumVelocityField.getInt(this); velocityTracker.computeCurrentVelocity(1000, maximumVelocity); xVelocity = VelocityTrackerCompat.getXVelocity(velocityTracker, activePointerIdField.getInt(this)); } catch (Exception e) { } return xVelocity; }
Example 6
Source File: Utils.java From Ticket-Analysis with MIT License | 6 votes |
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev, VelocityTracker tracker) { // Check the dot product of current velocities. // If the pointer that left was opposing another velocity vector, clear. tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); final int upIndex = ev.getActionIndex(); final int id1 = ev.getPointerId(upIndex); final float x1 = tracker.getXVelocity(id1); final float y1 = tracker.getYVelocity(id1); for (int i = 0, count = ev.getPointerCount(); i < count; i++) { if (i == upIndex) continue; final int id2 = ev.getPointerId(i); final float x = x1 * tracker.getXVelocity(id2); final float y = y1 * tracker.getYVelocity(id2); final float dot = x + y; if (dot < 0) { tracker.clear(); break; } } }
Example 7
Source File: VerticalViewPager.java From ticdesign with Apache License 2.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int height = getClientHeight(); final int scrollY = getScrollY(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor; final int totalDelta = (int) (mLastMotionY - mInitialMotionY); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 8
Source File: ViewPagerCompact.java From RxZhihuDaily with MIT License | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor; final int totalDelta = (int) (mLastMotionX - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 9
Source File: SwipeHelper.java From StackOverView with MIT License | 6 votes |
private void endSwipe(VelocityTracker velocityTracker) { float maxVelocity = MAX_DISMISS_VELOCITY * mDensityScale; velocityTracker.computeCurrentVelocity(1000 /* px/sec */, maxVelocity); float velocity = getVelocity(velocityTracker); float perpendicularVelocity = getPerpendicularVelocity(velocityTracker); float escapeVelocity = SWIPE_ESCAPE_VELOCITY * mDensityScale; float translation = getTranslation(mCurrView); // Decide whether to dismiss the current view boolean childSwipedFarEnough = Math.abs(translation) > 0.6 * getSize(mCurrView); boolean childSwipedFastEnough = (Math.abs(velocity) > escapeVelocity) && (Math.abs(velocity) > Math.abs(perpendicularVelocity)) && (velocity > 0) == (translation > 0); boolean dismissChild = mCallback.canChildBeDismissed(mCurrView) && isValidSwipeDirection(translation) && (childSwipedFastEnough || childSwipedFarEnough); if (dismissChild) { // flingadingy dismissChild(mCurrView, childSwipedFastEnough ? velocity : 0f); } else { // snappity mCallback.onDragCancelled(mCurrView); snapChild(mCurrView, velocity); } }
Example 10
Source File: SwipeTouchHelper.java From StackCardsView with Apache License 2.0 | 6 votes |
private void onTouchRelease() { final StackCardsView.LayoutParams lp = (StackCardsView.LayoutParams) mTouchChild.getLayoutParams(); if (lp.fastDismissAllowed) { final VelocityTracker velocityTracker2 = mVelocityTracker; velocityTracker2.computeCurrentVelocity(1000, mMaxVelocity); float xv = velocityTracker2.getXVelocity(mActivePointerId); float yv = velocityTracker2.getYVelocity(mActivePointerId); if (doFastDisappear(xv, yv)) { resetTouch(); return; } } if (isDistanceAllowDismiss() && isDirectionAllowDismiss()) { doSlowDisappear(); } else { animateToInitPos(); } resetTouch(); mSwipeView.onCoverStatusChanged(isCoverIdle()); }
Example 11
Source File: ViewPager.java From RxJavaApp with Apache License 2.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor; final int totalDelta = (int) (mLastMotionX - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 12
Source File: VerticalViewPager.java From ankihelper with GNU General Public License v3.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int height = getClientHeight(); final int scrollY = getScrollY(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor; final int totalDelta = (int) (mLastMotionY - mInitialMotionY); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 13
Source File: SdkCenteredViewPager.java From Android-SDK-Demo with MIT License | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if ( !mFakeDragging ) { throw new IllegalStateException( "No fake drag in progress. Call beginFakeDrag first." ); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity( 1000, mMaximumVelocity ); int initialVelocity = (int) velocityTracker.getXVelocity( mActivePointerId ); mPopulatePending = true; final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = ( ( (float) scrollX / width ) - ii.offset ) / ii.widthFactor; final int totalDelta = (int) ( mLastMotionX - mInitialMotionX ); int nextPage = determineTargetPage( currentPage, pageOffset, initialVelocity, totalDelta ); setCurrentItemInternal( nextPage, true, true, initialVelocity ); endDrag(); mFakeDragging = false; }
Example 14
Source File: ViewPagerCompat.java From android-auto-scroll-viewpager with Apache License 2.0 | 6 votes |
/** * End a fake drag of the pager. * * @see #beginFakeDrag() * @see #fakeDragBy(float) */ public void endFakeDrag() { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( velocityTracker, mActivePointerId); mPopulatePending = true; final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor; final int totalDelta = (int) (mLastMotionX - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); endDrag(); mFakeDragging = false; }
Example 15
Source File: CardViewLayout.java From YCCardView with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { mVelocityTracker.addMovement(event); int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: // 此处说明底层没有子View愿意消费Touch事件 break; case MotionEvent.ACTION_MOVE: int currentX = (int) event.getX(); int dx = (int) (currentX - lastX); requireScrollChange(dx); lastX = currentX; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocity = (int) velocityTracker.getXVelocity(); recycleVelocityTracker(); onRelease(event.getX(), velocity); break; default: break; } return true; }
Example 16
Source File: ViewFlow.java From NewXmPluginSDK with Apache License 2.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getChildCount() == 0) return false; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); mHandler.removeMessages(CANCLE_MSG); final int action = ev.getAction(); final float x = ev.getX(); switch (action) { case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionX = x; mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; break; case MotionEvent.ACTION_MOVE: final int deltaX = (int) (mLastMotionX - x); boolean xMoved = Math.abs(deltaX) > mTouchSlop; if (xMoved) { // Scroll if the user moved far enough along the X axis mTouchState = TOUCH_STATE_SCROLLING; if (mViewInitializeListener != null) initializeView(deltaX); } if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event mLastMotionX = x; final int scrollX = getScrollX(); if (deltaX < 0) { if (scrollX > 0) { scrollBy(Math.max(-scrollX, deltaX), 0); } } else if (deltaX > 0) { final int availableToScroll = getChildAt( getChildCount() - 1).getRight() - getPaddingRight() - getHorizontalFadingEdgeLength() - scrollX - getWidth(); if (availableToScroll > 0) { scrollBy(Math.min(availableToScroll, deltaX), 0); } } return true; } break; case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(); if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) { // Fling hard enough to move left snapToScreen(mCurrentScreen - 1); } else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < getChildCount() - 1) { // Fling hard enough to move right snapToScreen(mCurrentScreen + 1); } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; } return false; }
Example 17
Source File: MultipleOrientationSlidingDrawer.java From NYU-BusTracker-Android with Apache License 2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (mLocked) { return true; } if (mTracking) { mVelocityTracker.addMovement(event); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_MOVE: moveHandle((int) (mVertical ? event.getY() : event.getX()) - mTouchDelta); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(mVelocityUnits); float yVelocity = velocityTracker.getYVelocity(); float xVelocity = velocityTracker.getXVelocity(); boolean negative; final boolean vertical = mVertical; if (vertical) { negative = yVelocity < 0; if (xVelocity < 0) { xVelocity = -xVelocity; } if (xVelocity > mMaximumMinorVelocity) { xVelocity = mMaximumMinorVelocity; } } else { negative = xVelocity < 0; if (yVelocity < 0) { yVelocity = -yVelocity; } if (yVelocity > mMaximumMinorVelocity) { yVelocity = mMaximumMinorVelocity; } } float velocity = (float) Math.hypot(xVelocity, yVelocity); if (negative) { velocity = -velocity; } final int top = mHandle.getTop(); final int left = mHandle.getLeft(); if (Math.abs(velocity) < mMaximumTapVelocity) { if (inThreshold(top, left)) { if (mAllowSingleTap) { playSoundEffect(SoundEffectConstants.CLICK); if (mExpanded) { //animateClose(vertical ? top : left); animateClose(getSide()); } else { animateOpen(getSide()); //animateOpen(vertical ? top : left); } } else { performFling(vertical ? top : left, velocity, false); } } else { performFling(vertical ? top : left, velocity, false); } } else { performFling(vertical ? top : left, velocity, false); } } break; } } return mTracking || mAnimating || super.onTouchEvent(event); }
Example 18
Source File: SlidingDrawer.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (mLocked) { return true; } if (mTracking) { mVelocityTracker.addMovement(event); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_MOVE: moveHandle((int) (event.getY())); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(mVelocityUnits); float yVelocity = velocityTracker.getYVelocity(); float xVelocity = velocityTracker.getXVelocity(); boolean negative; negative = yVelocity < 0; if (xVelocity < 0) { xVelocity = -xVelocity; } if (xVelocity > mMaximumMinorVelocity) { xVelocity = mMaximumMinorVelocity; } float velocity = (float) Math.hypot(xVelocity, yVelocity); if (negative) { velocity = -velocity; } final int top = mHandle.getTop(); if (Math.abs(velocity) < mMaximumTapVelocity) { if ((mExpanded && top < mTapThreshold + mTopOffset) || (!mExpanded && top > mBottomOffset + getBottom() - getTop() - mHandleHeight - mTapThreshold)) { if (mAllowSingleTap) { playSoundEffect(SoundEffectConstants.CLICK); if (mExpanded) { animateClose(top); } else { animateOpen(top); } } else { performFling(top, velocity, false); } } else { performFling(top, velocity, false); } } else { performFling(top, velocity, false); } } break; } } return mTracking || mAnimating || super.onTouchEvent(event); }
Example 19
Source File: JellyViewPager.java From Conquer with Apache License 2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (vTracker == null) { vTracker = VelocityTracker.obtain(); } vTracker.addMovement(event); float currentY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: downY = event.getY(); downX = event.getX(); if (!currentViewRect.contains((int) downX, (int) downY)) { return false; } break; case MotionEvent.ACTION_MOVE: distanceY = currentY - downY; if (Math.abs(distanceY) > mTouchSlop) { if (pageChangeListener != null) { pageChangeListener.onPageScrolled(currentItem, (int) Math.abs(distanceY) / getHeight(), (int) distanceY); pageChangeListener.onPageScrollStateChanged(SCROLL_STATE_DRAGGING); } tranSpring.setEndValue(distanceY); float degree = MAX_DEGREE * distanceY / mHeight; if (downX < mWidth / 2) { degree = -degree; } rotateSpring.setEndValue(degree); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (Math.abs(distanceY) > mTouchSlop) { if (pageChangeListener != null) { pageChangeListener.onPageScrollStateChanged(SCROLL_STATE_SETTLING); } final VelocityTracker tracker = vTracker; tracker.computeCurrentVelocity(UNIT); float velocityY = tracker.getYVelocity(); animOutIfNeeded(currentY - downY, velocityY); if (vTracker != null) { vTracker.recycle(); vTracker = null; } } break; } return true; }
Example 20
Source File: ViewPager.java From letv with Apache License 2.0 | 4 votes |
public boolean onTouchEvent(MotionEvent ev) { if (this.mFakeDragging) { return true; } if (ev.getAction() == 0 && ev.getEdgeFlags() != 0) { return false; } if (this.mAdapter == null || this.mAdapter.getCount() == 0) { return false; } if (this.mVelocityTracker == null) { this.mVelocityTracker = VelocityTracker.obtain(); } this.mVelocityTracker.addMovement(ev); boolean needsInvalidate = false; float x; switch (ev.getAction() & 255) { case 0: this.mScroller.abortAnimation(); this.mPopulatePending = false; populate(); x = ev.getX(); this.mInitialMotionX = x; this.mLastMotionX = x; x = ev.getY(); this.mInitialMotionY = x; this.mLastMotionY = x; this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; case 1: if (this.mIsBeingDragged) { VelocityTracker velocityTracker = this.mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, (float) this.mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, this.mActivePointerId); this.mPopulatePending = true; int width = getClientWidth(); int scrollX = getScrollX(); ItemInfo ii = infoForCurrentScrollPosition(); setCurrentItemInternal(determineTargetPage(ii.position, ((((float) scrollX) / ((float) width)) - ii.offset) / ii.widthFactor, initialVelocity, (int) (MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId)) - this.mInitialMotionX)), true, true, initialVelocity); needsInvalidate = resetTouch(); break; } break; case 2: if (!this.mIsBeingDragged) { int pointerIndex = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId); if (pointerIndex == -1) { needsInvalidate = resetTouch(); break; } float x2 = MotionEventCompat.getX(ev, pointerIndex); float xDiff = Math.abs(x2 - this.mLastMotionX); float y = MotionEventCompat.getY(ev, pointerIndex); float yDiff = Math.abs(y - this.mLastMotionY); if (xDiff > ((float) this.mTouchSlop) && xDiff > yDiff) { this.mIsBeingDragged = true; requestParentDisallowInterceptTouchEvent(true); if (x2 - this.mInitialMotionX > 0.0f) { x = this.mInitialMotionX + ((float) this.mTouchSlop); } else { x = this.mInitialMotionX - ((float) this.mTouchSlop); } this.mLastMotionX = x; this.mLastMotionY = y; setScrollState(1); setScrollingCacheEnabled(true); ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } } if (this.mIsBeingDragged) { needsInvalidate = false | performDrag(MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId))); break; } break; case 3: if (this.mIsBeingDragged) { scrollToItem(this.mCurItem, true, 0, false); needsInvalidate = resetTouch(); break; } break; case 5: int index = MotionEventCompat.getActionIndex(ev); this.mLastMotionX = MotionEventCompat.getX(ev, index); this.mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; case 6: onSecondaryPointerUp(ev); this.mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId)); break; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } return true; }