android.view.MotionEvent#INVALID_POINTER_ID源码实例Demo

下面列出了android.view.MotionEvent#INVALID_POINTER_ID 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private int findIndex(int pointerId) {
    for (int i = 0; i < mDownPointers; i++) {
        if (mDownPointerId[i] == pointerId) {
            return i;
        }
    }
    if (mDownPointers == MAX_TRACKED_POINTERS || pointerId == MotionEvent.INVALID_POINTER_ID) {
        return UNTRACKED_POINTER;
    }
    mDownPointerId[mDownPointers++] = pointerId;
    return mDownPointers - 1;
}
 
源代码2 项目: android_9.0.0_r45   文件: ForwardingListener.java
@Override
public void onViewDetachedFromWindow(View v) {
    mForwarding = false;
    mActivePointerId = MotionEvent.INVALID_POINTER_ID;

    if (mDisallowIntercept != null) {
        mSrc.removeCallbacks(mDisallowIntercept);
    }
}
 
/**
 * Resets the component to the initial state.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void reset() {
  mGestureInProgress = false;
  mCount = 0;
  for (int i = 0; i < MAX_POINTERS; i++) {
    mId[i] = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ?
            -1 : MotionEvent.INVALID_POINTER_ID;
  }
}
 
/**
 * Resets the component to the initial state.
 */
public void reset() {
    mGestureInProgress = false;
    mPointerCount = 0;
    for (int i = 0; i < MAX_POINTERS; i++) {
        mId[i] = MotionEvent.INVALID_POINTER_ID;
    }
}
 
private void updatePointersOnTap(MotionEvent event) {
    mPointerCount = 0;
    for (int i = 0; i < MAX_POINTERS; i++) {
        int index = getPressedPointerIndex(event, i);
        if (index == -1) {
            mId[i] = MotionEvent.INVALID_POINTER_ID;
        } else {
            mId[i] = event.getPointerId(index);
            mCurrentX[i] = mStartX[i] = event.getX(index);
            mCurrentY[i] = mStartY[i] = event.getY(index);
            mPointerCount++;
        }
    }
}
 
源代码6 项目: XposedNavigationBar   文件: GesturesListener.java
private int findIndex(int pointerId) {
    for (int i = 0; i < mDownPointers; i++) {
        if (mDownPointerId[i] == pointerId) {
            return i;
        }
    }
    if (mDownPointers == MAX_TRACKED_POINTERS || pointerId == MotionEvent.INVALID_POINTER_ID) {
        return UNTRACKED_POINTER;
    }
    mDownPointerId[mDownPointers++] = pointerId;
    return mDownPointers - 1;
}
 
源代码7 项目: materialup   文件: MultiPointerGestureDetector.java
/**
 * Resets the component to the initial state.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void reset() {
    mGestureInProgress = false;
    mCount = 0;
    for (int i = 0; i < MAX_POINTERS; i++) {
        mId[i] = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ?
                -1 : MotionEvent.INVALID_POINTER_ID;
    }
}
 
源代码8 项目: FrescoUtils   文件: MultiPointerGestureDetector.java
/**
 * Resets the component to the initial state.
 */
public void reset() {
  mGestureInProgress = false;
  mCount = 0;
  for (int i = 0; i < MAX_POINTERS; i++) {
    mId[i] = MotionEvent.INVALID_POINTER_ID;
  }
}
 
源代码9 项目: droidddle   文件: MultiPointerGestureDetector.java
/**
 * Resets the component to the initial state.
 */
public void reset() {
    mGestureInProgress = false;
    mCount = 0;
    for (int i = 0; i < MAX_POINTERS; i++) {
        mId[i] = MotionEvent.INVALID_POINTER_ID;
    }
}
 
/**
 * Resets the component to the initial state.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void reset() {
  mGestureInProgress = false;
  mCount = 0;
  for (int i = 0; i < MAX_POINTERS; i++) {
    mId[i] = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ?
            -1 : MotionEvent.INVALID_POINTER_ID;
  }
}
 
源代码11 项目: fresco   文件: MultiPointerGestureDetector.java
/** Resets the component to the initial state. */
public void reset() {
  mGestureInProgress = false;
  mPointerCount = 0;
  for (int i = 0; i < MAX_POINTERS; i++) {
    mId[i] = MotionEvent.INVALID_POINTER_ID;
  }
}
 
源代码12 项目: fresco   文件: MultiPointerGestureDetector.java
private void updatePointersOnTap(MotionEvent event) {
  mPointerCount = 0;
  for (int i = 0; i < MAX_POINTERS; i++) {
    int index = getPressedPointerIndex(event, i);
    if (index == -1) {
      mId[i] = MotionEvent.INVALID_POINTER_ID;
    } else {
      mId[i] = event.getPointerId(index);
      mCurrentX[i] = mStartX[i] = event.getX(index);
      mCurrentY[i] = mStartY[i] = event.getY(index);
      mPointerCount++;
    }
  }
}
 
源代码13 项目: android-bottomsheet   文件: ResolverDrawerLayout.java
private void resetTouch() {
    mActivePointerId = MotionEvent.INVALID_POINTER_ID;
    mIsDragging = false;
    mOpenOnClick = false;
    mInitialTouchX = mInitialTouchY = mLastTouchY = 0;
    mVelocityTracker.clear();
}
 
源代码14 项目: AcDisplay   文件: ForwardingListener.java
@Override
public void onViewDetachedFromWindow(View v) {
    mForwarding = false;
    mActivePointerId = MotionEvent.INVALID_POINTER_ID;

    if (mDisallowIntercept != null) {
        mSrc.removeCallbacks(mDisallowIntercept);
    }
}
 
源代码15 项目: bottomsheetrecycler   文件: BottomSheetBehavior.java
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        ignoreEvents = true;
        return false;
    }
    int action = event.getActionMasked();
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }
    velocityTracker.addMovement(event);
    switch (action) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            touchingScrollingChild = false;
            activePointerId = MotionEvent.INVALID_POINTER_ID;
            // Reset the ignore flag
            if (ignoreEvents) {
                ignoreEvents = false;
                return false;
            }
            break;
        case MotionEvent.ACTION_DOWN:
            int initialX = (int) event.getX();
            initialY = (int) event.getY();
            // Only intercept nested scrolling events here if the view not being moved by the
            // ViewDragHelper.
            if (mNestedScrollingChildRefList != null) {
                for (View childView : mNestedScrollingChildRefList) {
                    if (childView != null && parent.isPointInChildBounds(childView, initialX, initialY)) {
                        activePointerId = event.getPointerId(event.getActionIndex());
                        touchingScrollingChild = true;
                    }
                }
            }
            ignoreEvents =
                    activePointerId == MotionEvent.INVALID_POINTER_ID
                            && !parent.isPointInChildBounds(child, initialX, initialY);
            break;
        default: // fall out
    }
    if (!ignoreEvents
            && viewDragHelper != null
            && viewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    //View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
    return action == MotionEvent.ACTION_MOVE
            && !ignoreEvents
            && state != STATE_DRAGGING
            && !isPointInsideChildScrollView(parent, (int) event.getX(), (int) event.getY())
            && viewDragHelper != null
            && Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
}
 
源代码16 项目: Noyze   文件: MovableTouchListener.java
@Override
 public boolean onTouch(View v, MotionEvent event) {
 	if (null != mAnimator && mAnimator.isRunning()) return false;
 	if (null == mPopupWindow) return false;
 
 	switch (event.getAction() & MotionEvent.ACTION_MASK) {
 		case MotionEvent.ACTION_DOWN:
 			LayoutParams params = mPopupWindow.getWindowParams();
 			aPID = event.getPointerId(0);
 			downX = (int) (params.x - event.getRawX());
 			downY = (int) (params.y - event.getRawY());
	break;
case MotionEvent.ACTION_UP:
	// Handle "snapping" to the right/ left edge of the screen.
	if (null != mAnchor) {
		final Rect mBounds = mPopupWindow.getBounds();
		final int[] screen = mPopupWindow.getWindowDimensions();
		switch (mAnchor) {
			case AXIS_Y:
				if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) { // Snap right.
					snap(screen[0] - mBounds.width(), PopupWindow.POSITION_UNCHANGED);
				} else { // Snap left.
					snap(0, PopupWindow.POSITION_UNCHANGED);
				}
				break;
			case AXIS_X:
				if (mBounds.top + (mBounds.height() / 2) > (screen[1] / 2)) { // Snap bottom.
					snap(PopupWindow.POSITION_UNCHANGED, screen[1] - mBounds.height());
				} else { // Snap top.
					snap(PopupWindow.POSITION_UNCHANGED, 0);
				}
				break;
			case EDGES:
				if (mBounds.top + (mBounds.height() / 2) > (screen[1] / 2)) { // Snap bottom half.
					if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) // Snap bottom right.
						snap(screen[0] - mBounds.width(), screen[1] - mBounds.height());
					else // Snap bottom left.
						snap(0, screen[1] - mBounds.height());
				} else { // Snap top half.
					if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) // Snap top right.
						snap(screen[0] - mBounds.width(), 0);
					else // Snap top left.
						snap(0, 0);
				}
				break;
		}
	}
	break;
case MotionEvent.ACTION_POINTER_UP:
	// Extract the index of the pointer that left the touch sensor
	final int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
	final int pointerId = event.getPointerId(pointerIndex);
	if (pointerId == aPID) {
		// This was our active pointer going up. Choose a new
		// active pointer and adjust accordingly.
		final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
		aPID = event.getPointerId(newPointerIndex);
	}
case MotionEvent.ACTION_MOVE:
	// Find the index of the active pointer and fetch its position
	final int mPID = event.findPointerIndex(aPID);
	float xMove = event.getRawX();
	float yMove = event.getRawY();

	// From http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
	final int dx = (int) (xMove + downX);
	final int dy = (int) (yMove + downY);

	mPopupWindow.position(((lockX) ? PopupWindow.POSITION_UNCHANGED : dx),
					  ((lockY) ? PopupWindow.POSITION_UNCHANGED : dy));
					  
	break;
case MotionEvent.ACTION_CANCEL:
   			aPID = MotionEvent.INVALID_POINTER_ID;
   			break;
 	}
 	
 	return true;
 }
 
源代码17 项目: Noyze   文件: MovableTouchListener.java
@Override
 public boolean onTouch(View v, MotionEvent event) {
 	if (null != mAnimator && mAnimator.isRunning()) return false;
 	if (null == mPopupWindow) return false;
 
 	switch (event.getAction() & MotionEvent.ACTION_MASK) {
 		case MotionEvent.ACTION_DOWN:
 			LayoutParams params = mPopupWindow.getWindowParams();
 			aPID = event.getPointerId(0);
 			downX = (int) (params.x - event.getRawX());
 			downY = (int) (params.y - event.getRawY());
	break;
case MotionEvent.ACTION_UP:
	// Handle "snapping" to the right/ left edge of the screen.
	if (null != mAnchor) {
		final Rect mBounds = mPopupWindow.getBounds();
		final int[] screen = mPopupWindow.getWindowDimensions();
		switch (mAnchor) {
			case AXIS_Y:
				if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) { // Snap right.
					snap(screen[0] - mBounds.width(), PopupWindow.POSITION_UNCHANGED);
				} else { // Snap left.
					snap(0, PopupWindow.POSITION_UNCHANGED);
				}
				break;
			case AXIS_X:
				if (mBounds.top + (mBounds.height() / 2) > (screen[1] / 2)) { // Snap bottom.
					snap(PopupWindow.POSITION_UNCHANGED, screen[1] - mBounds.height());
				} else { // Snap top.
					snap(PopupWindow.POSITION_UNCHANGED, 0);
				}
				break;
			case EDGES:
				if (mBounds.top + (mBounds.height() / 2) > (screen[1] / 2)) { // Snap bottom half.
					if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) // Snap bottom right.
						snap(screen[0] - mBounds.width(), screen[1] - mBounds.height());
					else // Snap bottom left.
						snap(0, screen[1] - mBounds.height());
				} else { // Snap top half.
					if (mBounds.left + (mBounds.width() / 2) > (screen[0] / 2)) // Snap top right.
						snap(screen[0] - mBounds.width(), 0);
					else // Snap top left.
						snap(0, 0);
				}
				break;
		}
	}
	break;
case MotionEvent.ACTION_POINTER_UP:
	// Extract the index of the pointer that left the touch sensor
	final int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
	final int pointerId = event.getPointerId(pointerIndex);
	if (pointerId == aPID) {
		// This was our active pointer going up. Choose a new
		// active pointer and adjust accordingly.
		final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
		aPID = event.getPointerId(newPointerIndex);
	}
case MotionEvent.ACTION_MOVE:
	// Find the index of the active pointer and fetch its position
	final int mPID = event.findPointerIndex(aPID);
	float xMove = event.getRawX();
	float yMove = event.getRawY();

	// From http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
	final int dx = (int) (xMove + downX);
	final int dy = (int) (yMove + downY);

	mPopupWindow.position(((lockX) ? PopupWindow.POSITION_UNCHANGED : dx),
					  ((lockY) ? PopupWindow.POSITION_UNCHANGED : dy));
					  
	break;
case MotionEvent.ACTION_CANCEL:
   			aPID = MotionEvent.INVALID_POINTER_ID;
   			break;
 	}
 	
 	return true;
 }