List of usage examples for android.view MotionEvent ACTION_POINTER_INDEX_MASK
int ACTION_POINTER_INDEX_MASK
To view the source code for android.view MotionEvent ACTION_POINTER_INDEX_MASK.
Click Source Link
From source file:com.hb.hkm.slidinglayer.SlidLayer.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }//from ww w .j av a2s . c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_VALUE; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_VALUE) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == INVALID_VALUE) { mActivePointerId = INVALID_VALUE; 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); final boolean validHorizontalDrag = xDiff > mTouchSlop && xDiff > yDiff; final boolean validVerticalDrag = yDiff > mTouchSlop && yDiff > xDiff; if (validHorizontalDrag) { mLastX = x; } else if (validVerticalDrag) { mLastY = y; } if (validHorizontalDrag || validVerticalDrag) { mIsDragging = true; setDrawingCacheEnabled(true); } break; case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEventCompat.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHere(mInitialX, mInitialY)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }
From source file:it.mb.whatshare.Utils.java
/** * Returns a string that represents the symbolic name of the specified * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent * numeric constant such as "35" if unknown. By Google. * /*from w w w . j a v a 2 s.c o m*/ * @param action * The action. * @return The symbolic name of the specified action. */ public static String actionToString(int action) { switch (action) { case MotionEvent.ACTION_DOWN: return "ACTION_DOWN"; case MotionEvent.ACTION_UP: return "ACTION_UP"; case MotionEvent.ACTION_CANCEL: return "ACTION_CANCEL"; case MotionEvent.ACTION_OUTSIDE: return "ACTION_OUTSIDE"; case MotionEvent.ACTION_MOVE: return "ACTION_MOVE"; case MotionEvent.ACTION_HOVER_MOVE: return "ACTION_HOVER_MOVE"; case MotionEvent.ACTION_SCROLL: return "ACTION_SCROLL"; case MotionEvent.ACTION_HOVER_ENTER: return "ACTION_HOVER_ENTER"; case MotionEvent.ACTION_HOVER_EXIT: return "ACTION_HOVER_EXIT"; } int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: return "ACTION_POINTER_DOWN(" + index + ")"; case MotionEvent.ACTION_POINTER_UP: return "ACTION_POINTER_UP(" + index + ")"; default: return Integer.toString(action); } }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastTouchX = (int) ev.getX(newPointerIndex); mLastTouchY = (int) ev.getY(newPointerIndex); mMotionCorrection = 0;//from ww w .ja v a2 s .co m mActivePointerId = ev.getPointerId(newPointerIndex); } }
From source file:com.hippo.widget.BothScrollView.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = (int) ev.getY(newPointerIndex); mLastMotionY = (int) ev.getY(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear();//w ww.j ava 2 s. co m } } }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = ev.getX(newPointerIndex); mLastMotionX2 = ev.getX(newPointerIndex); mLastMotionY = ev.getY(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear();//from www. ja v a 2 s . c o m } } }
From source file:cc.flydev.launcher.Page.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = mDownMotionX = ev.getX(newPointerIndex); mLastMotionY = ev.getY(newPointerIndex); mLastMotionXRemainder = 0;//from w w w . j av a2s . c o m mActivePointerId = ev.getPointerId(newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }
From source file:com.wb.launcher3.Page.java
public boolean handleMotionEvent(MotionEvent ev) { if (getChildCount() <= 0) { return false; }//w ww. ja va 2 s .c o m acquireVelocityTrackerAndAddMovement(ev); switch (MotionEvent.ACTION_MASK & ev.getAction()) { case MotionEvent.ACTION_POINTER_DOWN: if (ev.getPointerCount() <= 2) { if (!this.mScroller.isFinished()) { this.mScroller.abortAnimation(); } int index = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; float px = ev.getX(index); mLastMotionX = px; mDownMotionX = px; mLastMotionY = ev.getY(index); mLastMotionXRemainder = 0.0F; mTotalMotionX = 0.0F; mActivePointerId = ev.getPointerId(index); mTouchState = TOUCH_STATE_SCROLLING; pageBeginMoving(); } break; case MotionEvent.ACTION_MOVE: if (mTouchState == TOUCH_STATE_SCROLLING) { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex >= 0) { float x = ev.getX(pointerIndex); float deltaX = mLastMotionX + mLastMotionXRemainder - x; mTotalMotionX += Math.abs(deltaX); if (Math.abs(deltaX) >= 1.0F) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (!mDeferScrollUpdate) { scrollBy((int) deltaX, 0); if (DEBUG) Log.d(TAG, "handleMotionEvent().Scrolling: " + deltaX); } else { invalidate(); } mLastMotionX = x; mLastMotionXRemainder = deltaX - (int) deltaX; } else { awakenScrollBars(); } } } else { determineScrollingStart(ev); } break; case MotionEvent.ACTION_POINTER_UP: if (ev.getPointerCount() > 2) { onOtherPointerUp(ev); break; } if (mTouchState == TOUCH_STATE_SCROLLING) { final int activePointerId = mActivePointerId; final int pointerIndex = ev.findPointerIndex(activePointerId); final float x = ev.getX(pointerIndex); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x); boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING && Math.abs(velocityX) > mFlingThresholdVelocity; boolean returnToOriginalPage = false; if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum(velocityX) != Math.signum(deltaX) && isFling) { returnToOriginalPage = true; } if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED) { m_moveNextDeltaX = deltaX; m_isSignificantMoveNext = (!returnToOriginalPage && (isSignificantMove || isFling)); } int finalPage; if (((isSignificantMove && deltaX > 0 && !isFling) || (isFling && velocityX > 0)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; snapToPageWithVelocity(finalPage, velocityX); } else if (((isSignificantMove && deltaX < 0 && !isFling) || (isFling && velocityX < 0)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; snapToPageWithVelocity(finalPage, velocityX); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_PREV_PAGE) { int nextPage = Math.max(0, mCurrentPage - 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) { int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else { snapToDestination(); onUnhandledTap(ev); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { snapToDestination(); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; } return true; }
From source file:com.wb.launcher3.Page.java
protected void onOtherPointerUp(MotionEvent ev) { int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { int lastIndex = ev.getPointerCount() - 0x1; final int newPointerIndex = pointerIndex == lastIndex ? (lastIndex - 0x1) : lastIndex; mLastMotionX = ev.getX(newPointerIndex); mLastMotionY = ev.getY(newPointerIndex); mLastMotionXRemainder = 0.0f;/*from w ww.j a v a 2 s . co m*/ mActivePointerId = ev.getPointerId(newPointerIndex); releaseVelocityTracker(); } }
From source file:com.appunite.list.AbsHorizontalListView.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mMotionX = (int) ev.getX(newPointerIndex); mMotionY = (int) ev.getY(newPointerIndex); mMotionCorrection = 0;// w w w . j a va 2 s.c om mActivePointerId = ev.getPointerId(newPointerIndex); } }