android.view.MotionEvent#getPointerId ( )源码实例Demo

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

源代码1 项目: TurboLauncher   文件: PagedView.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;
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码2 项目: simple-keyboard   文件: MoreKeysKeyboardView.java
@Override
public boolean onTouchEvent(final MotionEvent me) {
    final int action = me.getActionMasked();
    final int index = me.getActionIndex();
    final int x = (int)me.getX(index);
    final int y = (int)me.getY(index);
    final int pointerId = me.getPointerId(index);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        onDownEvent(x, y, pointerId);
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        onUpEvent(x, y, pointerId);
        break;
    case MotionEvent.ACTION_MOVE:
        onMoveEvent(x, y, pointerId);
        break;
    }
    return true;
}
 
@Override
protected void onHoverExit(final MotionEvent event) {
    final Key lastKey = getLastHoverKey();
    if (DEBUG_HOVER) {
        Log.d(TAG, "onHoverExit: key=" + getHoverKeyOf(event) + " last=" + lastKey);
    }
    if (lastKey != null) {
        super.onHoverExitFrom(lastKey);
    }
    setLastHoverKey(null);
    final int actionIndex = event.getActionIndex();
    final int x = (int)event.getX(actionIndex);
    final int y = (int)event.getY(actionIndex);
    final int pointerId = event.getPointerId(actionIndex);
    final long eventTime = event.getEventTime();
    // A hover exit event at one pixel width or height area on the edges of more keys keyboard
    // are treated as closing.
    mMoreKeysKeyboardValidBounds.set(0, 0, mKeyboardView.getWidth(), mKeyboardView.getHeight());
    mMoreKeysKeyboardValidBounds.inset(CLOSING_INSET_IN_PIXEL, CLOSING_INSET_IN_PIXEL);
    if (mMoreKeysKeyboardValidBounds.contains(x, y)) {
        // Invoke {@link MoreKeysKeyboardView#onUpEvent(int,int,int,long)} as if this hover
        // exit event selects a key.
        mKeyboardView.onUpEvent(x, y, pointerId, eventTime);
        // TODO: Should fix this reference. This is a hack to clear the state of
        // {@link PointerTracker}.
        PointerTracker.dismissAllMoreKeysPanels();
        return;
    }
    // Close the more keys keyboard.
    // TODO: Should fix this reference. This is a hack to clear the state of
    // {@link PointerTracker}.
    PointerTracker.dismissAllMoreKeysPanels();
}
 
@Override
public boolean onTouchEvent(MotionEvent event) {
    mScaleDetector.onTouchEvent(event);

    final int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN: {
            mIsFocus = true;

            mLastTouchX = event.getX();
            mLastTouchY = event.getY();

            mActivePointerId = event.getPointerId(0);
            break;
        }
        case MotionEvent.ACTION_UP: {
            if (mIsFocus) {
                handleFocus(mCamera.getParameters());
            }
            mActivePointerId = INVALID_POINTER_ID;
            break;
        }
        case MotionEvent.ACTION_POINTER_DOWN: {
            mCamera.cancelAutoFocus();
            mIsFocus = false;
            break;
        }
        case MotionEvent.ACTION_CANCEL: {
            mActivePointerId = INVALID_POINTER_ID;
            break;
        }
    }

    return true;
}
 
源代码5 项目: RxTools-master   文件: RxCardStackView.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) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码6 项目: UltimateAndroid   文件: PullToZoomListView.java
private void onSecondaryPointerUp(MotionEvent paramMotionEvent) {
	int i = (paramMotionEvent.getAction()) >> 8;
	if (paramMotionEvent.getPointerId(i) == this.mActivePointerId)
		if (i != 0) {
			int j = 1;
			this.mLastMotionY = paramMotionEvent.getY(0);
			this.mActivePointerId = paramMotionEvent.getPointerId(0);
			return;
		}
}
 
源代码7 项目: Travel-Mate   文件: FlipViewPager.java
private void onSecondaryPointerUp(MotionEvent ev) {
    int pointerIndex = ev.getActionIndex();
    int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null)
            mVelocityTracker.clear();
    }
}
 
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // Ignore deprecation, ACTION_POINTER_ID_MASK and
            // ACTION_POINTER_ID_SHIFT has same value and are deprecated
            // You can have either deprecation or lint target api warning
            final int pointerIndex = Compat.getPointerIndex(ev.getAction());
            final int pointerId = ev.getPointerId(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;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }
            break;
    }

    mActivePointerIndex = ev
            .findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
                    : 0);
    try {
        return super.onTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        // Fix for support lib bug, happening when onDestroy is
        return true;
    }
}
 
源代码9 项目: Tweetin   文件: EclairGestureDetector.java
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // Ignore deprecation, ACTION_POINTER_ID_MASK and
            // ACTION_POINTER_ID_SHIFT has same value and are deprecated
            // You can have either deprecation or lint target api warning
            final int pointerIndex = Compat.getPointerIndex(ev.getAction());
            final int pointerId = ev.getPointerId(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;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }
            break;
    }

    mActivePointerIndex = ev
            .findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
                    : 0);
    return super.onTouchEvent(ev);
}
 
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // Ignore deprecation, ACTION_POINTER_ID_MASK and
            // ACTION_POINTER_ID_SHIFT has same value and are deprecated
            // You can have either deprecation or lint target api warning
            final int pointerIndex = Compat.getPointerIndex(ev.getAction());
            final int pointerId = ev.getPointerId(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;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }
            break;
    }

    mActivePointerIndex = ev
            .findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
                    : 0);
    return super.onTouchEvent(ev);
}
 
源代码11 项目: SmartSwipe   文件: SwipeHelper.java
private void saveLastMotion(MotionEvent ev) {
    final int pointerCount = ev.getPointerCount();
    for (int i = 0; i < pointerCount; i++) {
        final int pointerId = ev.getPointerId(i);
        // If pointer is invalid then skip saving on ACTION_MOVE.
        if (!isValidPointerForActionMove(pointerId)) {
            continue;
        }
        final float x = ev.getX(i);
        final float y = ev.getY(i);
        mLastMotionX[pointerId] = x;
        mLastMotionY[pointerId] = y;
    }
}
 
@Override
public boolean onTouchEvent(MotionEvent ev) {
	final int action = ev.getAction();
	switch (action & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			mActivePointerId = ev.getPointerId(0);
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			mActivePointerId = INVALID_POINTER_ID;
			break;
		case MotionEvent.ACTION_POINTER_UP:
			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.
				final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
				mActivePointerId = ev.getPointerId(newPointerIndex);
				mLastTouchX = ev.getX(newPointerIndex);
				mLastTouchY = ev.getY(newPointerIndex);
			}
			break;
	}

	mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
	return super.onTouchEvent(ev);
}
 
源代码13 项目: MusicPlayer   文件: ScaleDragDetector.java
private void onTouchActivePointer(int action, MotionEvent ev) {
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            //final int pointerIndex = MotionEventCompat.getActionIndex(ev);
            //final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);

            final int pointerIndex = ev.getActionIndex();
            final int pointerId = ev.getPointerId(pointerIndex);

            if (pointerId == mActivePointerId) {
                final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }

            break;
    }

    mActivePointerIndex =
            ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}
 
@Override
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
    if (!isEnabled() || canChildScrollUp() || mIsRefreshing) {
        return false;
    }

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
        case MotionEvent.ACTION_DOWN:
            setTargetOffsetTop(0, true);
            mActivePointerId = motionEvent.getPointerId(0);
            mIsBeingDragged = false;
            final float initialMotionY = getMotionEventY(motionEvent, mActivePointerId);
            if (initialMotionY == -1f) {
                return false;
            }
            mInitialMotionY = initialMotionY;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mActivePointerId == INVALID_POINTER_ID) {
                return false;
            }

            final float y = getMotionEventY(motionEvent, mActivePointerId);
            if (y == -1f) {
                return false;
            }
            final float yDiff = y - mInitialMotionY;
            if (yDiff > mTouchSlop && !mIsBeingDragged) {
                mIsBeingDragged = true;
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mIsBeingDragged = false;
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            onSecondaryPointerUp(motionEvent);
            break;
    }

    return mIsBeingDragged;
}
 
源代码15 项目: Telegram   文件: ItemTouchHelper.java
@Override
public void onTouchEvent(@NonNull RecyclerView recyclerView, @NonNull MotionEvent event) {
    mGestureDetector.onTouchEvent(event);
    if (DEBUG) {
        Log.d(TAG,
                "on touch: x:" + mInitialTouchX + ",y:" + mInitialTouchY + ", :" + event);
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(event);
    }
    if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
        return;
    }
    final int action = event.getActionMasked();
    final int activePointerIndex = event.findPointerIndex(mActivePointerId);
    if (activePointerIndex >= 0) {
        checkSelectForSwipe(action, event, activePointerIndex);
    }
    ViewHolder viewHolder = mSelected;
    if (viewHolder == null) {
        return;
    }
    switch (action) {
        case MotionEvent.ACTION_MOVE: {
            // Find the index of the active pointer and fetch its position
            if (activePointerIndex >= 0) {
                updateDxDy(event, mSelectedFlags, activePointerIndex);
                moveIfNecessary(viewHolder);
                mRecyclerView.removeCallbacks(mScrollRunnable);
                mScrollRunnable.run();
                mRecyclerView.invalidate();
            }
            break;
        }
        case MotionEvent.ACTION_CANCEL:
            if (mVelocityTracker != null) {
                mVelocityTracker.clear();
            }
            // fall through
        case MotionEvent.ACTION_UP:
            select(null, ACTION_STATE_IDLE);
            mActivePointerId = ACTIVE_POINTER_ID_NONE;
            break;
        case MotionEvent.ACTION_POINTER_UP: {
            final int pointerIndex = event.getActionIndex();
            final int pointerId = event.getPointerId(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;
                mActivePointerId = event.getPointerId(newPointerIndex);
                updateDxDy(event, mSelectedFlags, pointerIndex);
            }
            break;
        }
    }
}
 
源代码16 项目: PullRefreshView   文件: EventResolver.java
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    c.setScrollState(FlingLayout.SCROLL_STATE_TOUCH_SCROLL);
    acquireVelocityTracker(ev);
    int pointerCount = ev.getPointerCount();
    int pointerIndex = ev.getActionIndex();
    switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            tepmY = downY = y;
            tepmX = downX = x;
            if (!isNestedScrollingEnabled()) {
                float moveP = c.getMoveP();
                if (moveP != 0) {
                    return true;
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            tepmX = ev.getX(pointerIndex);
            tepmY = ev.getY(pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            pointerIndex = ev.findPointerIndex(mPointerId);
            float mx;
            float my;
            if (pointerCount > pointerIndex && pointerIndex >= 0) {
                mx = ev.getX(pointerIndex);
                my = ev.getY(pointerIndex);
            } else {
                mx = ev.getX();
                my = ev.getY();
            }
            //意图分析,避免误操作
            float _tepmX = tepmX;
            float _tepmY = tepmY;
            tepmX = mx;
            tepmY = my;
            if (!isNestedScrollingEnabled()) {
                if (tryToMove(ev, _tepmX, _tepmY, mx, my)) {
                    return true;
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            createVelocity(ev);
        case MotionEvent.ACTION_CANCEL:
            if (!isNestedScrollingEnabled()) {
                c.startRelease();
                isScrolling = false;
            }
            releaseVelocityTracker();
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // 获取离开屏幕的手指的索引
            int pointerIdLeave = ev.getPointerId(pointerIndex);
            if (mPointerId == pointerIdLeave) {
                // 离开屏幕的正是目前的有效手指,此处需要重新调整,并且需要重置VelocityTracker
                int reIndex = pointerIndex == 0 ? 1 : 0;
                mPointerId = ev.getPointerId(reIndex);
                // 调整触摸位置,防止出现跳动
                tepmX = ev.getX(reIndex);
                tepmY = ev.getY(reIndex);
            }
    }
    return c.superDispatchTouchEvent(ev) || isScrolling;
}
 
源代码17 项目: Bugstick   文件: Joystick.java
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!isEnabled()) return false;

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN: {
            if (detectingDrag || !hasStick()) return false;

            downX = event.getX(0);
            downY = event.getY(0);
            activePointerId = event.getPointerId(0);

            onStartDetectingDrag();
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            if (INVALID_POINTER_ID == activePointerId) break;
            if (detectingDrag && dragExceedsSlop(event)) {
                onDragStart();
                return true;
            }
            break;
        }
        case MotionEvent.ACTION_POINTER_UP: {
            final int pointerIndex = event.getActionIndex();
            final int pointerId = event.getPointerId(pointerIndex);

            if (pointerId != activePointerId)
                break; // if active pointer, fall through and cancel!
        }
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            onTouchEnded();

            onStopDetectingDrag();
            break;
        }
    }

    return false;
}
 
源代码18 项目: android-midisuite   文件: MusicKeyboardView.java
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    int action = event.getActionMasked();
    // Track individual fingers.
    int pointerIndex = event.getActionIndex();
    int id = event.getPointerId(pointerIndex);
    // Get the pointer's current position
    float x = event.getX(pointerIndex);
    float y = event.getY(pointerIndex);
    // Some devices can return negative x or y, which can cause an array exception.
    x = Math.max(x, 0.0f);
    y = Math.max(y, 0.0f);
    boolean handled =  false;
    switch (action) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN:
            onFingerDown(id, x, y);
            handled = true;
            break;
        case MotionEvent.ACTION_MOVE:
            int pointerCount = event.getPointerCount();
            for (int i = 0; i < pointerCount; i++) {
                id = event.getPointerId(i);
                x = event.getX(i);
                y = event.getY(i);
                x = Math.max(x, 0.0f);
                y = Math.max(y, 0.0f);
                onFingerMove(id, x, y);
            }
            handled = true;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            onFingerUp(id, x, y);
            handled = true;
            break;
        case MotionEvent.ACTION_CANCEL:
            onAllFingersUp();
            handled = true;
            break;
        default:
            break;
    }

    // Must return true or we do not get the ACTION_MOVE and
    // ACTION_UP events.
    return true;
}
 
源代码19 项目: Telegram   文件: ItemTouchHelper.java
/**
 * Checks whether we should select a View for swiping.
 */
@SuppressWarnings("WeakerAccess") /* synthetic access */
void checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) {
    if (mSelected != null || action != MotionEvent.ACTION_MOVE
            || mActionState == ACTION_STATE_DRAG || !mCallback.isItemViewSwipeEnabled()) {
        return;
    }
    if (mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
        return;
    }
    final ViewHolder vh = findSwipedView(motionEvent);
    if (vh == null) {
        return;
    }
    final int movementFlags = mCallback.getAbsoluteMovementFlags(mRecyclerView, vh);

    final int swipeFlags = (movementFlags & ACTION_MODE_SWIPE_MASK)
            >> (DIRECTION_FLAG_COUNT * ACTION_STATE_SWIPE);

    if (swipeFlags == 0) {
        return;
    }

    // mDx and mDy are only set in allowed directions. We use custom x/y here instead of
    // updateDxDy to avoid swiping if user moves more in the other direction
    final float x = motionEvent.getX(pointerIndex);
    final float y = motionEvent.getY(pointerIndex);

    // Calculate the distance moved
    final float dx = x - mInitialTouchX;
    final float dy = y - mInitialTouchY;
    // swipe target is chose w/o applying flags so it does not really check if swiping in that
    // direction is allowed. This why here, we use mDx mDy to check slope value again.
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);

    if (absDx < mSlop && absDy < mSlop) {
        return;
    }
    if (absDx > absDy) {
        if (dx < 0 && (swipeFlags & LEFT) == 0) {
            return;
        }
        if (dx > 0 && (swipeFlags & RIGHT) == 0) {
            return;
        }
    } else {
        if (dy < 0 && (swipeFlags & UP) == 0) {
            return;
        }
        if (dy > 0 && (swipeFlags & DOWN) == 0) {
            return;
        }
    }
    mDx = mDy = 0f;
    mActivePointerId = motionEvent.getPointerId(0);
    select(vh, ACTION_STATE_SWIPE);
}
 
源代码20 项目: RecyclerPager   文件: PageRecyclerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent e) {

        final int action = e.getActionMasked();
        final int actionIndex = e.getActionIndex();

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mScrollPointerId = e.getPointerId(0);
                mInitialTouchX = (int) (e.getX() + 0.5f);
                mInitialTouchY = (int) (e.getY() + 0.5f);
                return super.onInterceptTouchEvent(e);

            case MotionEvent.ACTION_POINTER_DOWN:
                mScrollPointerId = e.getPointerId(actionIndex);
                mInitialTouchX = (int) (e.getX(actionIndex) + 0.5f);
                mInitialTouchY = (int) (e.getY(actionIndex) + 0.5f);
                return super.onInterceptTouchEvent(e);

            case MotionEvent.ACTION_MOVE: {
                final int index = e.findPointerIndex(mScrollPointerId);
                if (index < 0) {
                    return false;
                }
                final int x = (int) (e.getX(actionIndex) + 0.5f);
                final int y = (int) (e.getY(actionIndex) + 0.5f);

                LayoutManager layoutManager = getLayoutManager();

                if (layoutManager != null && getScrollState() != SCROLL_STATE_DRAGGING) {
                    final int dx = x - mInitialTouchX;
                    final int dy = y - mInitialTouchY;
                    final boolean canScrollHorizontally = layoutManager.canScrollHorizontally();
                    final boolean canScrollVertically = layoutManager.canScrollVertically();
                    boolean startScroll = false;

                    if (canScrollHorizontally && Math.abs(dx) > mTouchSlop && (Math.abs(dx) * 0.5f
                            >= Math.abs(dy) || canScrollVertically)) {
                        startScroll = true;
                    }

                    if (canScrollVertically && Math.abs(dy) > mTouchSlop && (Math.abs(dy) * 0.5f
                            >= Math.abs(dx) || canScrollHorizontally)) {
                        startScroll = true;
                    }

                    return startScroll && super.onInterceptTouchEvent(e);
                }
                return super.onInterceptTouchEvent(e);
            }

            default:
                return super.onInterceptTouchEvent(e);
        }
    }