List of usage examples for android.support.v4.view MotionEventCompat getPointerId
public static int getPointerId(MotionEvent event, int pointerIndex)
From source file:ayushi.view.customview.ViewDragHelper.java
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); // Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it. if (mLastMotionX != null && mLastMotionY != null && mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) { mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; }//from w w w. ja va2s .c om } }
From source file:com.callba.phone.widget.refreshlayout.RefreshLayout.java
private boolean footerInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsFooterBeingDragged = false;/*from ww w .j a va 2 s . c o m*/ mFooterCurrPercentage = 0; 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; if (yDiff < -mTouchSlop) { mLastMotionY = y; mIsFooterBeingDragged = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsFooterBeingDragged = false; mFooterCurrPercentage = 0; mActivePointerId = INVALID_POINTER; break; } return mIsFooterBeingDragged; }
From source file:android.improving.utils.views.swipeback.ViewDragHelper.java
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x;// w w w . j ava 2 s . c o m mLastMotionY[pointerId] = y; } }
From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java
/** * On secondary pointer up./*from ww w. ja v a2 s .c om*/ * * @param ev the ev */ private void onSecondaryPointerUp(MotionEvent ev) { if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called"); 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(); } } }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
@Override public boolean onTouchEvent(final MotionEvent event) { final int pointerIndex = MotionEventCompat.getActionIndex(event); final int pointCnt = mWrap.getPointerCount(event); final int pointerId = MotionEventCompat.getPointerId(event, pointerIndex); if (pointCnt < MAX_POINT_CNT) { //if (pointerIndex <= MAX_POINT_CNT - 1){ {/* w w w . ja v a 2s. c om*/ for (int i = 0; i < pointCnt; i++) { int id = MotionEventCompat.getPointerId(event, i); if (id < MAX_POINT_CNT) { x_last[id] = x[id]; y_last[id] = y[id]; x[id] = mWrap.getX(event, i); y[id] = mWrap.getY(event, i); } } switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: case MotionEventCompat.ACTION_POINTER_DOWN: int button = -1; // Save the ID of this pointer if (mInputMode == INPUT_MODE_MOUSE) { } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) { int buttonState = mWrap.getButtonState(event); if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) { button = BTN_A; } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) { button = BTN_B; } DosBoxControl.nativeJoystick(0, 0, ACTION_DOWN, button); } else if (mInputMode == INPUT_MODE_REAL_MOUSE) { int buttonState = mWrap.getButtonState(event); if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) { button = BTN_A; } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) { button = BTN_B; } else if (buttonState == 0) { // handle trackpad presses as button clicks button = BTN_A; } DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_DOWN, button); } mButtonDown[pointerId] = button; break; case MotionEvent.ACTION_UP: case MotionEventCompat.ACTION_POINTER_UP: if (mInputMode == INPUT_MODE_MOUSE) { if (mLongClick) { // single tap long click release DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, mGestureSingleClick - GESTURE_LEFT_CLICK); mLongClick = false; Log.i("DosBoxTurbo", "SingleTap Long Click Release"); return true; } else if (mDoubleLong) { // double tap long click release try { Thread.sleep(CLICK_DELAY); } catch (InterruptedException e) { } DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureDoubleClick - GESTURE_LEFT_CLICK); Log.i("DosBoxTurbo", "DoubleTap Long Click Release"); mDoubleLong = false; //return true; } else if (pointCnt == 2) { // handle 2 finger tap gesture if (mLongPress) { if (!mTwoFingerAction) { // press button down Log.i("DosBoxTurbo", "2-Finger Long Click Down"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN, mGestureTwoFinger - GESTURE_LEFT_CLICK); mTwoFingerAction = true; } else { // already pressing button - release and press again Log.i("DosBoxTurbo", "2-Finger Long Click - AGAIN"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureTwoFinger - GESTURE_LEFT_CLICK); try { Thread.sleep(CLICK_DELAY); } catch (InterruptedException e) { } DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN, mGestureTwoFinger - GESTURE_LEFT_CLICK); } } else { Log.i("DosBoxTurbo", "2-Finger Long Click Down-UP"); mouseClick(mGestureTwoFinger - GESTURE_LEFT_CLICK); } return true; } else if ((pointCnt == 1) && mTwoFingerAction) { // release two finger gesture Log.i("DosBoxTurbo", "2-Finger Long Click Release"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureTwoFinger - GESTURE_LEFT_CLICK); mTwoFingerAction = false; //return true; } } else if (mInputMode == INPUT_MODE_REAL_MOUSE) { //Log.v("Mouse","BUTTON UP: " + (mButtonDown[pointerId])); DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, mButtonDown[pointerId]); if (mWrap.getButtonState(event) > 0) { return true; // capture button touches, pass screen touches through to gesture detetor } } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) { DosBoxControl.nativeJoystick(0, 0, ACTION_UP, (mButtonDown[pointerId])); if (mWrap.getButtonState(event) > 0) { return true; } } break; case MotionEvent.ACTION_MOVE: //isTouch[pointerId] = true; switch (mInputMode) { case INPUT_MODE_SCROLL: mScroll_x += (int) (x[pointerId] - x_last[pointerId]); mScroll_y += (int) (y[pointerId] - y_last[pointerId]); forceRedraw(); break; case INPUT_MODE_MOUSE: case INPUT_MODE_REAL_MOUSE: if (event.getEventTime() + EVENT_THRESHOLD_DECAY < SystemClock.uptimeMillis()) { Log.i("DosBoxTurbo", "eventtime: " + event.getEventTime() + " systemtime: " + SystemClock.uptimeMillis()); return true; // get rid of old events } int idx = (!virtButton[0]) ? 0 : 1; if (mAbsolute) { DosBoxControl.nativeMouseWarp(x[idx], y[idx], mRenderer.x, mRenderer.y, mRenderer.width, mRenderer.height); } else { DosBoxControl.nativeMouse((int) (x[idx] * mMouseSensitivityX), (int) (y[idx] * mMouseSensitivityY), (int) (x_last[idx] * mMouseSensitivityX), (int) (y_last[idx] * mMouseSensitivityY), ACTION_MOVE, -1); } if (mDebug) { Log.d("DosBoxTurbo", "mAbsolute=" + mAbsolute + " MotionEvent MOVE(" + pointerId + ")" + " x[idx]=" + x[idx] + " y[idx]" + y[idx] + " mRenderer.x=" + mRenderer.x + " mRenderer.y=" + mRenderer.y + " mRenderer.width=" + mRenderer.width + " mRenderer.height=" + mRenderer.height); } try { if (!mInputLowLatency) Thread.sleep(95); else Thread.sleep(65); } catch (InterruptedException e) { } break; default: } break; } } } try { Thread.sleep(15); } catch (InterruptedException e) { e.printStackTrace(); } //Thread.yield(); return gestureScanner.onTouchEvent(event); }
From source file:com.jtech.view.RefreshLayout.java
@Override @SuppressLint("ClickableViewAccessibility") public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;/*w w w. j ava 2s .co m*/ } 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 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, 0); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; mIsBeingDragged = false; finishSpinner(overscrollTop); mActivePointerId = INVALID_POINTER; return false; } } return true; }
From source file:com.JTechMod.custom.refreshlayout.RefreshLayout.java
@Override @SuppressLint("ClickableViewAccessibility") public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;//from w w w . ja va 2 s .c o m } 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 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, 0); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; mIsBeingDragged = false; finishSpinner(overscrollTop); mActivePointerId = INVALID_POINTER; return false; } } return true; }
From source file:com.bcgtgjyb.huanwen.meizi.view.widget.MySwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;/* w w w .java2 s . c o m*/ } 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: //guohuanwen // mActivePointerId = MotionEventCompat.getPointerId(ev, 0); // mIsBeingDragged = false; // break; //guohuanwen 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; }
From source file:com.jzh.stuapp.view.MyViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*/*from w ww .jav a2 s.c o m*/ * This method JUST determines whether we want to intercept the motion. * If we return true, onMotionEvent will be called and we do the actual * scrolling there. */ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { if (DEBUG) Log.v(TAG, "Intercept done!"); mIsBeingDragged = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsBeingDragged) { if (DEBUG) Log.v(TAG, "Intercept returning true!"); return true; } if (mIsUnableToDrag) { if (DEBUG) Log.v(TAG, "Intercept returning false!"); return false; } } switch (action) { case MotionEvent.ACTION_MOVE: { /* * mIsBeingDragged == false, otherwise the shortcut would have * caught it. Check whether the user has moved far enough from his * original down touch. */ /* * Locally do absolute value. mLastMotionY is set to the y value of * the down event. */ final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); 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); final int scrollX = getScrollX(); final boolean atEdge = (dx > 0 && scrollX == 0) || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (canScroll(this, false, (int) dx, (int) x, (int) y)) { mInitialMotionX = mLastMotionX = x; mLastMotionY = y; return false; } if (xDiff > mTouchSlop && xDiff > yDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); mLastMotionX = x; setScrollingCacheEnabled(true); } else { if (yDiff > mTouchSlop) { if (DEBUG) Log.v(TAG, "Starting unable to drag!"); mIsUnableToDrag = true; } } break; } case MotionEvent.ACTION_DOWN: { /* * Remember location of down touch. ACTION_DOWN always refers to * pointer index 0. */ mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); if (mScrollState == SCROLL_STATE_SETTLING) { mIsBeingDragged = true; mIsUnableToDrag = false; setScrollState(SCROLL_STATE_DRAGGING); } else { completeScroll(); mIsBeingDragged = false; mIsUnableToDrag = false; } if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + "mIsUnableToDrag=" + mIsUnableToDrag); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }
From source file:cn.com.zzwfang.view.directionalviewpager.DirectionalViewPager.java
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; if (mOrientation == HORIZONTAL) { mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); } else {/* w w w .jav a 2 s . c o m*/ mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex); } mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }