List of usage examples for android.view MotionEvent getEdgeFlags
public final int getEdgeFlags()
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;/*from w ww . ja v a 2 s.co m*/ xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;/*ww w. j a va 2 s . c o m*/ xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException { JSONObject jObj = new JSONObject(); jObj.put("downTime", e.getDownTime()); jObj.put("eventTime", e.getEventTime()); jObj.put("action", e.getAction()); jObj.put("pointerCount", e.getPointerCount()); jObj.put("metaState", e.getMetaState()); jObj.put("buttonState", e.getButtonState()); jObj.put("xPrecision", e.getXPrecision()); jObj.put("yPrecision", e.getYPrecision()); jObj.put("deviceId", e.getDeviceId()); jObj.put("edgeFlags", e.getEdgeFlags()); jObj.put("source", e.getSource()); jObj.put("flags", e.getFlags()); for (int i = 0; i < e.getPointerCount(); i++) { PointerProperties prop = new PointerProperties(); e.getPointerProperties(i, prop); PointerCoords coords = new PointerCoords(); e.getPointerCoords(i, coords);/*from w ww. ja v a 2s . c om*/ JSONObject pointer = JObjFromPointer(prop, coords); jObj.accumulate("pointers", pointer); } return jObj; }
From source file:Main.java
public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) { MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent); MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1]; pointerProperties[0] = new MotionEvent.PointerProperties(); MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1]; pointerCoords[0] = new MotionEvent.PointerCoords(); pointerCoords[0].x = ev.getX();/*from www .j av a 2s .com*/ pointerCoords[0].y = ev.getY(); return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties, pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(), ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags()); }
From source file:com.taobao.weex.ui.view.listview.BaseBounceView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mGestureDetector != null) { mGestureDetector.onTouchEvent(ev); }//from w ww . ja v a 2 s.co m switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { if (ev.getEdgeFlags() != 0) { return false; } mLastMotionX = ev.getRawX(); mLastMotionY = ev.getRawY(); mScrollValue = -getPaddingTop(); return mIsBeingDragged; } case MotionEvent.ACTION_MOVE: { if (mIsBeingDragged) { float y = ev.getRawY(); startPull(y); return true; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { if (mIsBeingDragged) { this.mScrollValue = -getPaddingTop(); mIsBeingDragged = false; onTouchActionUp(); if (mMaxPadding > 0) { /** * 1.listview?paddingTop?0????0deltaY?paddingTop < 0 * 2.listview??PADDING????PADDINGdeltaY(-PADDING - getPaddingTop()) > 0 * bug: * listview item?2?listview??pull * fix * listview?? */ if (getPaddingTop() > 0/*|| getPaddingTop() < -mMaxPadding*/) { mScrollValue = getPaddingTop() > 0 ? 0 : -mMaxPadding; backToInitPos(getPaddingTop(), getPaddingTop() > 0 ? -getPaddingTop() : (-mMaxPadding - getPaddingTop())); } } else { backToInitPos(getScrollY(), -getScrollY()); } mMode = null; return true; } break; } } return false; }
From source file:com.xyczero.customswipelistview.CustomSwipeListView.java
@Override public boolean onTouchEvent(MotionEvent ev) { // Just response single finger action. final int action = ev.getAction() & MotionEvent.ACTION_MASK; final int x = (int) ev.getX(); if (action == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { ev.setAction(MotionEvent.ACTION_CANCEL); return super.onTouchEvent(ev); }/*from w w w .jav a2 s.c o m*/ if (mSelectedPosition != INVALID_POSITION) { addVelocityTrackerMotionEvent(ev); switch (action) { case MotionEvent.ACTION_DOWN: Log.d(TAG, "onTouchEvent:ACTION_DOWN"); // If there is a itemswipeview and then don't click it // by the next down action,it will first return to original // state and cancel to response the following actions. if (isItemSwipeViewVisible) { if (!isClickItemSwipeView) { mLastItemSwipeView.setVisibility(GONE); mLastItemMainView.scrollTo(0, 0); } isItemSwipeViewVisible = false; ev.setAction(MotionEvent.ACTION_CANCEL); return super.onTouchEvent(ev); } break; case MotionEvent.ACTION_MOVE: Log.d(TAG, "onTouchEvent:ACTION_MOVE"); mVelocityTracker.getYVelocity(); // determine whether the swipe action. if (Math.abs(getScrollXVelocity()) > mMinimumVelocity || (Math.abs(ev.getX() - mDownMotionX) > mTouchSlop && Math.abs(ev.getY() - mDownMotionY) < mTouchSlop)) { isSwiping = true; } if (isSwiping) { int deltaX = (int) mDownMotionX - x; if (deltaX > 0 && mEnableSwipeItemLeft || deltaX < 0 && mEnableSwipeItemRight) { mDownMotionX = x; mCurItemMainView.scrollBy(deltaX, 0); } // if super.onTouchEvent() that been called there,it might // lead to the specified item out of focus due to the // function might call itemClick function in the sliding. return true; } break; case MotionEvent.ACTION_UP: Log.d(TAG, "onTouchEvent:ACTION_UP"); if (isSwiping) { mLastItemMainView = mCurItemMainView; mLastItemSwipeView = mCurItemSwipeView; final int velocityX = getScrollXVelocity(); if (velocityX > mMinimumVelocity) { scrollByTouchSwipeMode(TOUCH_SWIPE_RIGHT, -mScreenWidth); } else if (velocityX < -mMinimumVelocity) { scrollByTouchSwipeMode(TOUCH_SWIPE_LEFT, getItemSwipeViewWidth(mLastItemSwipeView)); } else { scrollByTouchSwipeMode(TOUCH_SWIPE_AUTO, Integer.MIN_VALUE); } recycleVelocityTracker(); // TODO:To be optimized for not calling computeScroll // function. if (mScroller.isFinished()) { isSwiping = false; } // prevent to trigger OnItemClick by transverse sliding // distance too slow or too small OnItemClick events when in // swipe mode. ev.setAction(MotionEvent.ACTION_CANCEL); return super.onTouchEvent(ev); } break; default: break; } } return super.onTouchEvent(ev); }
From source file:com.coco.slidinguppanel.SlidingUpPanel.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (getState() == STATE_OPENED) { // disable touch handle when in opened state. return false; }//from w w w .ja va 2 s . com final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our descendants. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { onTouchDown(ev, false); DEBUG_LOG("Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + " mIsUnableToDrag=" + mIsUnableToDrag); break; } case MotionEvent.ACTION_MOVE: { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER || mIsUnableToDrag) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); final float xDiff = Math.abs(x - mInitialMotionX); final float yDiff = Math.abs(y - mInitialMotionY); DEBUG_LOG("Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff); onTouchMove(x, y, xDiff, yDiff, false); break; } case MotionEvent.ACTION_UP: { if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float y = MotionEventCompat.getY(ev, pointerIndex); final int totalDelta = (int) (y - mInitialMotionY); boolean toOpen = determineToOpen(initialVelocity, totalDelta); startFling(toOpen, initialVelocity); endDrag(); } DEBUG_LOG("Touch up!!!"); break; } case MotionEvent.ACTION_CANCEL: { if (mIsBeingDragged) { startFling(isOpen(), 0); endDrag(); } DEBUG_LOG("Touch cancel!!!"); break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); mLastMotionX = x; mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex); break; } case MotionEvent.ACTION_POINTER_UP: onTouchPointerUp(ev); break; } return true; }
From source file:jp.shuri.yamanetoshi.verticalviewpager.VerticalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong // to one of our // descendants. return false; }/*from w w w. j av a2 s . c o m*/ if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); 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 mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (yDiff > mTouchSlop && yDiff > xDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; mLastMotionY = y; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float y = MotionEventCompat.getY(ev, activePointerIndex); final float deltaY = mLastMotionY - y; mLastMotionY = y; float scrollY = getScrollY() + deltaY; final int height = getHeight(); final float topBound = Math.max(0, (mCurItem - 1) * height); final float bottomBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * height; if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); if (mOnPageChangeListener != null) { final int position = (int) scrollY / height; final int positionOffsetPixels = (int) scrollY % height; final float positionOffset = (float) positionOffsetPixels / height; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); mPopulatePending = true; if ((Math.abs(initialVelocity) > mMinimumVelocity) || Math.abs(mInitialMotionY - mLastMotionY) >= (getHeight() / 3)) { if (mLastMotionY > mInitialMotionY) { setCurrentItemInternal(mCurItem - 1, true, true); } else { setCurrentItemInternal(mCurItem + 1, true, true); } } else { setCurrentItemInternal(mCurItem, true, true); } mActivePointerId = INVALID_POINTER; 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 y = MotionEventCompat.getY(ev, index); mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.viettel.image.zoom.ZoomViewPaper.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong // to one of our // descendants. return false; }//from w w w . ja v a 2 s. c o m if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); 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) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); if (DEBUG) VTLog.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (xDiff > mTouchSlop && xDiff > yDiff) { if (DEBUG) VTLog.v(TAG, "Starting drag!"); mIsBeingDragged = true; mLastMotionX = x; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = mLastMotionX - x; mLastMotionX = x; float scrollX = getScrollX() + deltaX; final int width = getWidth(); final float leftBound = Math.max(0, (mCurItem - 1) * width); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * width; 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()); if (mOnPageChangeListener != null) { final int position = (int) scrollX / width; final int positionOffsetPixels = (int) scrollX % width; final float positionOffset = (float) positionOffsetPixels / width; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); mPopulatePending = true; if ((Math.abs(initialVelocity) > mMinimumVelocity) || Math.abs(mInitialMotionX - mLastMotionX) >= (getWidth() / 3)) { if (mLastMotionX > mInitialMotionX) { setCurrentItemInternal(mCurItem - 1, true, true); } else { setCurrentItemInternal(mCurItem + 1, true, true); } } else { setCurrentItemInternal(mCurItem, true, true); } mActivePointerId = INVALID_POINTER; 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); mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.coleman.demo.view.page.DirectionalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong // to one of our // descendants. return false; }/*from w w w .j av a 2 s. c o m*/ if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); 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 if (mOrientation == HORIZONTAL) { mLastMotionX = mInitialMotion = ev.getX(); } else { mLastMotionY = mInitialMotion = ev.getY(); } mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float yDiff = Math.abs(y - mLastMotionY); float primaryDiff; float secondaryDiff; if (mOrientation == HORIZONTAL) { primaryDiff = xDiff; secondaryDiff = yDiff; } else { primaryDiff = yDiff; secondaryDiff = xDiff; } if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (primaryDiff > mTouchSlop && primaryDiff > secondaryDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; if (mOrientation == HORIZONTAL) { mLastMotionX = x; } else { mLastMotionY = y; } setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float y = MotionEventCompat.getY(ev, activePointerIndex); int size; float scroll; if (mOrientation == HORIZONTAL) { size = getWidth(); scroll = getScrollX() + (mLastMotionX - x); mLastMotionX = x; } else { size = getHeight(); scroll = getScrollY() + (mLastMotionY - y); mLastMotionY = y; } final float lowerBound = Math.max(0, (mCurItem - 1) * size); final float upperBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * size; if (scroll < lowerBound) { scroll = lowerBound; } else if (scroll > upperBound) { scroll = upperBound; } if (mOrientation == HORIZONTAL) { // Don't lose the rounded component mLastMotionX += scroll - (int) scroll; scrollTo((int) scroll, getScrollY()); } else { // Don't lose the rounded component mLastMotionY += scroll - (int) scroll; scrollTo(getScrollX(), (int) scroll); } if (mOnPageChangeListener != null) { final int position = (int) scroll / size; final int positionOffsetPixels = (int) scroll % size; final float positionOffset = (float) positionOffsetPixels / size; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity; float lastMotion; int sizeOverThree; if (mOrientation == HORIZONTAL) { initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); lastMotion = mLastMotionX; sizeOverThree = getWidth() / 3; } else { initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); lastMotion = mLastMotionY; sizeOverThree = getHeight() / 3; } mPopulatePending = true; if ((Math.abs(initialVelocity) > mMinimumVelocity) || Math.abs(mInitialMotion - lastMotion) >= sizeOverThree) { if (lastMotion > mInitialMotion) { setCurrentItemInternal(mCurItem - 1, true, true); } else { setCurrentItemInternal(mCurItem + 1, true, true); } } else { setCurrentItemInternal(mCurItem, true, true); } mActivePointerId = INVALID_POINTER; 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); if (mOrientation == HORIZONTAL) { mLastMotionX = MotionEventCompat.getX(ev, index); } else { mLastMotionY = MotionEventCompat.getY(ev, index); } mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (mOrientation == HORIZONTAL) { mLastMotionX = MotionEventCompat.getX(ev, index); } else { mLastMotionY = MotionEventCompat.getY(ev, index); } break; } return true; }