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

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

源代码1 项目: AndroidStudyDemo   文件: ZrcAbsListView.java
private void onTouchMove(MotionEvent ev) {
    if (mTouchMode == TOUCH_MODE_INVALID) {
        mTouchMode = TOUCH_MODE_SCROLL;
    }
    int pointerIndex = ev.findPointerIndex(mActivePointerId);
    if (pointerIndex == -1) {
        pointerIndex = 0;
        mActivePointerId = ev.getPointerId(pointerIndex);
    }
    if (mDataChanged) {
        layoutChildren();
    }
    final int x = (int) ev.getX(pointerIndex);
    final int y = (int) ev.getY(pointerIndex);
    switch (mTouchMode) {
    case TOUCH_MODE_DOWN:
    case TOUCH_MODE_TAP:
    case TOUCH_MODE_DONE_WAITING:
        startScrollIfNeeded(x, y);
        break;
    case TOUCH_MODE_SCROLL:
        scrollIfNeeded(x, y);
        break;
    }
}
 
源代码2 项目: Multiwii-Remote   文件: JoystickView.java
private boolean processMoveEvent(MotionEvent ev) {
	if (pointerId != INVALID_POINTER_ID) {
		final int pointerIndex = ev.findPointerIndex(pointerId);
		// Translate touch position to center of view
		float x = ev.getX(pointerIndex);
		touchX = x - cX - offsetX;
		float y = ev.getY(pointerIndex);
		touchY = y - cY - offsetY;

		// Log.d(TAG,
		// String.format("ACTION_MOVE: (%03.0f, %03.0f) => (%03.0f, %03.0f)",
		// x, y, touchX, touchY));

		reportOnMoved();
		invalidate();

		touchPressure = ev.getPressure(pointerIndex);
		reportOnPressure();

		return true;
	}
	return false;
}
 
private boolean onGestureFinished(MotionEvent e) {
  final int pointerIndex = e.findPointerIndex(activePointerId);

  if (e.getActionIndex() == pointerIndex) {
    onFling(e, e, 0, 0);
    return true;
  }

  return false;
}
 
源代码4 项目: ImagePicker   文件: 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 = CropCompat.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);
    try {
        return super.onTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        // Fix for support lib bug, happening when onDestroy is
        return true;
    }
}
 
源代码6 项目: TelePlus-Android   文件: ItemTouchHelper.java
@Override
public void onLongPress(MotionEvent e) {
    if (!mShouldReactToLongPress) {
        return;
    }
    View child = findChildView(e);
    if (child != null) {
        ViewHolder vh = mRecyclerView.getChildViewHolder(child);
        if (vh != null) {
            if (!mCallback.hasDragFlag(mRecyclerView, vh)) {
                return;
            }
            int pointerId = e.getPointerId(0);
            // Long press is deferred.
            // Check w/ active pointer id to avoid selecting after motion
            // event is canceled.
            if (pointerId == mActivePointerId) {
                final int index = e.findPointerIndex(mActivePointerId);
                final float x = e.getX(index);
                final float y = e.getY(index);
                mInitialTouchX = x;
                mInitialTouchY = y;
                mDx = mDy = 0f;
                if (DEBUG) {
                    Log.d(TAG,
                            "onlong press: x:" + mInitialTouchX + ",y:" + mInitialTouchY);
                }
                if (mCallback.isLongPressDragEnabled()) {
                    select(vh, ACTION_STATE_DRAG);
                }
            }
        }
    }
}
 
源代码7 项目: Carbon   文件: ItemTouchHelper.java
@Override
public void onLongPress(MotionEvent e) {
    if (!mShouldReactToLongPress) {
        return;
    }
    View child = findChildView(e);
    if (child != null) {
        ViewHolder vh = mRecyclerView.getChildViewHolder(child);
        if (vh != null) {
            if (!mCallback.hasDragFlag(mRecyclerView, vh)) {
                return;
            }
            int pointerId = e.getPointerId(0);
            // Long press is deferred.
            // Check w/ active pointer id to avoid selecting after motion
            // event is canceled.
            if (pointerId == mActivePointerId) {
                final int index = e.findPointerIndex(mActivePointerId);
                final float x = e.getX(index);
                final float y = e.getY(index);
                mInitialTouchX = x;
                mInitialTouchY = y;
                mDx = mDy = 0f;
                if (DEBUG) {
                    Log.d(TAG,
                            "onlong press: x:" + mInitialTouchX + ",y:" + mInitialTouchY);
                }
                if (mCallback.isLongPressDragEnabled()) {
                    select(vh, ACTION_STATE_DRAG);
                }
            }
        }
    }
}
 
源代码8 项目: Typewriter   文件: TypewriterRefreshLayout.java
private float getMotionEventY(MotionEvent motionEvent, int activePointerId) {
    final int index = motionEvent.findPointerIndex(activePointerId);
    if (index < 0) {
        return -1f;
    }
    return motionEvent.getY(index);
}
 
源代码9 项目: Swipe-Deck   文件: SwipeListener.java
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (deactivated) return false;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_DOWN:
            click = true;
            //gesture has begun
            float x;
            float y;
            //cancel any current animations
            v.clearAnimation();

            mActivePointerId = event.getPointerId(0);

            x = event.getX();
            y = event.getY();

            if(event.findPointerIndex(mActivePointerId) == 0) {
                callback.cardActionDown();
            }

            initialXPress = x;
            initialYPress = y;
            break;

        case MotionEvent.ACTION_MOVE:
            //gesture is in progress

            final int pointerIndex = event.findPointerIndex(mActivePointerId);
            //Log.i("pointer index: " , Integer.toString(pointerIndex));
            if(pointerIndex < 0 || pointerIndex > 0 ){
                break;
            }

            final float xMove = event.getX(pointerIndex);
            final float yMove = event.getY(pointerIndex);

            //calculate distance moved
            final float dx = xMove - initialXPress;
            final float dy = yMove - initialYPress;

            //throw away the move in this case as it seems to be wrong
            //TODO: figure out why this is the case
            if((int)initialXPress == 0 && (int) initialYPress == 0){
                //makes sure the pointer is valid
                break;
            }
            //calc rotation here
            float posX = card.getX() + dx;
            float posY = card.getY() + dy;

            //in this circumstance consider the motion a click
            if (Math.abs(dx + dy) > 5) click = false;

            card.setX(posX);
            card.setY(posY);

            //card.setRotation
            float distobjectX = posX - initialX;
            float rotation = ROTATION_DEGREES * 2.f * distobjectX / parentWidth;
            card.setRotation(rotation);

            if (rightView != null && leftView != null){
                //set alpha of left and right image
                float alpha = (((posX - paddingLeft) / (parentWidth * OPACITY_END)));
                //float alpha = (((posX - paddingLeft) / parentWidth) * ALPHA_MAGNITUDE );
                //Log.i("alpha: ", Float.toString(alpha));
                rightView.setAlpha(alpha);
                leftView.setAlpha(-alpha);
            }

            break;

        case MotionEvent.ACTION_UP:
            //gesture has finished
            //check to see if card has moved beyond the left or right bounds or reset
            //card position
            checkCardForEvent();

            if(event.findPointerIndex(mActivePointerId) == 0) {
                callback.cardActionUp();
            }
            //check if this is a click event and then perform a click
            //this is a workaround, android doesn't play well with multiple listeners

            if (click) v.performClick();
            //if(click) return false;

            break;

        default:
            return false;
    }
    return true;
}
 
@Override
public boolean onTouchEvent (MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mDownX = (int)event.getX();
            mDownY = (int)event.getY();
            mActivePointerId = event.getPointerId(0);
            break;
        case MotionEvent.ACTION_MOVE:
            if (mActivePointerId == INVALID_POINTER_ID) {
                break;
            }

            int pointerIndex = event.findPointerIndex(mActivePointerId);

            mLastEventY = (int) event.getY(pointerIndex);
            int deltaY = mLastEventY - mDownY;

            if (mCellIsMobile) {
                mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
                        mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
                mHoverCell.setBounds(mHoverCellCurrentBounds);
                invalidate();

                handleCellSwitch();

                mIsMobileScrolling = false;
                handleMobileCellScroll();

                return false;
            }
            break;
        case MotionEvent.ACTION_UP:
            touchEventsEnded();
            break;
        case MotionEvent.ACTION_CANCEL:
            touchEventsCancelled();
            break;
        case MotionEvent.ACTION_POINTER_UP:
            /* If a multitouch event took place and the original touch dictating
             * the movement of the hover cell has ended, then the dragging event
             * ends and the hover cell is animated to its corresponding position
             * in the listview. */
            pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
                    MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            final int pointerId = event.getPointerId(pointerIndex);
            if (pointerId == mActivePointerId) {
                touchEventsEnded();
            }
            break;
        default:
            break;
    }

    return super.onTouchEvent(event);
}
 
源代码11 项目: HaoReader   文件: SwipeRefreshLayout.java
@Override
public boolean onTouchEvent(MotionEvent ev) {
    int action = ev.getActionMasked();
    if (!this.mRefreshing && this.mReturningToStart && action == 0) {
        this.mReturningToStart = false;
    }

    if (this.isEnabled() && !this.mReturningToStart && !this.canChildScrollUp()) {
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                this.mLastMotionY = this.mInitialMotionY = ev.getY();
                this.mActivePointerId = ev.getPointerId(0);
                this.mIsBeingDragged = false;
                this.mCurrPercentage = 0.0F;
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                this.mIsBeingDragged = false;
                this.mActivePointerId = INVALID_POINTER;
                if(!this.mRefreshing && this.mCurrPercentage != 0.0F){
                    updatePositionTimeout(50L);
                }
                return false;
            case MotionEvent.ACTION_MOVE:
                int pointerIndex = ev.findPointerIndex(this.mActivePointerId);
                if (pointerIndex < 0) {
                    Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
                    return false;
                }

                float y = ev.getY(pointerIndex);
                float yDiff = y - this.mInitialMotionY;
                if (!this.mIsBeingDragged && yDiff > (float) this.mTouchSlop) {
                    this.mIsBeingDragged = true;
                }

                if (this.mIsBeingDragged) {
                    if (yDiff > this.mDistanceToTriggerSync) {
                        this.startRefresh();
                    } else {
                        this.setTriggerPercentage(this.mAccelerateInterpolator.getInterpolation(yDiff / this.mDistanceToTriggerSync));
                        if (this.mLayoutDraggingTogether) {
                            this.updateContentOffsetTop((int) yDiff);
                        }
                        if (this.mLastMotionY > y && this.mTarget.getTop() == this.getPaddingTop()) {
                            this.removeCallbacks(this.mCancel);
                        } else {
                            this.updatePositionTimeout(RETURN_TO_ORIGINAL_POSITION_TIMEOUT);
                        }
                    }

                    this.mLastMotionY = y;
                }
            case MotionEvent.ACTION_OUTSIDE:
            default:
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                int index = ev.getActionIndex();
                this.mLastMotionY = ev.getY(index);
                this.mActivePointerId = ev.getPointerId(index);
                break;
            case MotionEvent.ACTION_POINTER_UP:
                this.onSecondaryPointerUp(ev);
        }

        return true;
    } else {
        return false;
    }
}
 
源代码12 项目: 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;
 }
 
源代码13 项目: Travel-Mate   文件: FlipViewPager.java
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    // Custom code starts here
    View view = mCurrent.pageView;
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            final View childView = viewGroup.getChildAt(i);
            checkIfChildWasClicked(ev, childView);
        }
    }

    // Custom code ends here
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        toggleFlip(false);
        mActivePointerId = INVALID_POINTER;
        recycleVelocity();
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN && !mFlipping) return false;

    switch (action) {
        case MotionEvent.ACTION_MOVE:
            int activePointerId = this.mActivePointerId;
            if (activePointerId == INVALID_POINTER) break;

            int pointerIndex = ev.findPointerIndex(activePointerId);
            if (pointerIndex == -1) {
                this.mActivePointerId = INVALID_POINTER;
                break;
            }

            float x = ev.getX(pointerIndex);
            float dx = x - mLastMotionX;
            float xDiff = Math.abs(dx);
            float y = ev.getY(pointerIndex);
            float dy = y - mLastMotionY;
            float yDiff = Math.abs(dy);

            if (xDiff > mTouchSlop && xDiff > yDiff) {
                toggleFlip(true);
                mLastMotionX = x;
                mLastMotionY = y;
            }
            break;

        case MotionEvent.ACTION_DOWN:
            this.mActivePointerId = ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK;
            mLastMotionX = ev.getX(this.mActivePointerId);
            mLastMotionY = ev.getY(this.mActivePointerId);
            toggleFlip(!mScroller.isFinished());
            break;
        case MotionEvent.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            break;
    }

    if (!mFlipping)
        trackVelocity(ev);
    return !mFlipping;
}
 
源代码14 项目: Carbon   文件: ItemTouchHelper.java
@Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
    mGestureDetector.onTouchEvent(event);
    if (DEBUG) {
        Log.d(TAG, "intercept: x:" + event.getX() + ",y:" + event.getY() + ", " + event);
    }
    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN) {
        mActivePointerId = event.getPointerId(0);
        mInitialTouchX = event.getX();
        mInitialTouchY = event.getY();
        obtainVelocityTracker();
        if (mSelected == null) {
            final RecoverAnimation animation = findAnimation(event);
            if (animation != null) {
                mInitialTouchX -= animation.mX;
                mInitialTouchY -= animation.mY;
                endRecoverAnimation(animation.mViewHolder, true);
                if (mPendingCleanup.remove(animation.mViewHolder.itemView)) {
                    mCallback.clearView(mRecyclerView, animation.mViewHolder);
                }
                select(animation.mViewHolder, animation.mActionState);
                updateDxDy(event, mSelectedFlags, 0);
            }
        }
    } else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mActivePointerId = ACTIVE_POINTER_ID_NONE;
        select(null, ACTION_STATE_IDLE);
    } else if (mActivePointerId != ACTIVE_POINTER_ID_NONE) {
        // in a non scroll orientation, if distance change is above threshold, we
        // can select the item
        final int index = event.findPointerIndex(mActivePointerId);
        if (DEBUG) {
            Log.d(TAG, "pointer index " + index);
        }
        if (index >= 0) {
            checkSelectForSwipe(action, event, index);
        }
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(event);
    }
    return mSelected != null;
}
 
源代码15 项目: ReSwipeCard   文件: ReItemTouchHelper.java
@Override
public void onTouchEvent(RecyclerView recyclerView, 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 = MotionEventCompat.getActionMasked(event);
    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) {
                if (mCallback.enableHardWare() && viewHolder.itemView.getLayerType() != View.LAYER_TYPE_HARDWARE) {
                    viewHolder.itemView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                }
                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 = MotionEventCompat.getActionIndex(event);
            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 项目: TelePlus-Android   文件: ItemTouchHelper.java
@Override
public void onTouchEvent(RecyclerView recyclerView, 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;
        }
    }
}
 
源代码17 项目: UltimateAndroid   文件: PullToZoomListView.java
public boolean onTouchEvent(MotionEvent paramMotionEvent) {
	Log.d("mmm", "" + (0xFF & paramMotionEvent.getAction()));
	switch (0xFF & paramMotionEvent.getAction()) {
	case 4:
	case 0:
		if (!this.mScalingRunnalable.mIsFinished) {
			this.mScalingRunnalable.abortAnimation();
		}
		this.mLastMotionY = paramMotionEvent.getY();
		this.mActivePointerId = paramMotionEvent.getPointerId(0);
		this.mMaxScale = (this.mScreenHeight / this.mHeaderHeight);
		this.mLastScale = (this.mHeaderContainer.getBottom() / this.mHeaderHeight);
		break;
	case 2:
		Log.d("mmm", "mActivePointerId" + mActivePointerId);
		int j = paramMotionEvent.findPointerIndex(this.mActivePointerId);
		if (j == -1) {
			Log.e("PullToZoomListView", "Invalid pointerId="
					+ this.mActivePointerId + " in onTouchEvent");
		} else {
			if (this.mLastMotionY == -1.0F)
				this.mLastMotionY = paramMotionEvent.getY(j);
			if (this.mHeaderContainer.getBottom() >= this.mHeaderHeight) {
				ViewGroup.LayoutParams localLayoutParams = this.mHeaderContainer
						.getLayoutParams();
				float f = ((paramMotionEvent.getY(j) - this.mLastMotionY + this.mHeaderContainer
						.getBottom()) / this.mHeaderHeight - this.mLastScale)
						/ 2.0F + this.mLastScale;
				if ((this.mLastScale <= 1.0D) && (f < this.mLastScale)) {
					localLayoutParams.height = this.mHeaderHeight;
					this.mHeaderContainer
							.setLayoutParams(localLayoutParams);
					return super.onTouchEvent(paramMotionEvent);
				}
				this.mLastScale = Math.min(Math.max(f, 1.0F),
						this.mMaxScale);
				localLayoutParams.height = ((int) (this.mHeaderHeight * this.mLastScale));
				if (localLayoutParams.height < this.mScreenHeight)
					this.mHeaderContainer
							.setLayoutParams(localLayoutParams);
				this.mLastMotionY = paramMotionEvent.getY(j);
				return true;
			}
			this.mLastMotionY = paramMotionEvent.getY(j);
		}
		break;
	case 1:
		reset();
		endScraling();
		break;
	case 3:
		int i = paramMotionEvent.getActionIndex();
		this.mLastMotionY = paramMotionEvent.getY(i);
		this.mActivePointerId = paramMotionEvent.getPointerId(i);
		break;
	case 5:
		onSecondaryPointerUp(paramMotionEvent);
		this.mLastMotionY = paramMotionEvent.getY(paramMotionEvent
				.findPointerIndex(this.mActivePointerId));
		break;
	case 6:
	}
	return super.onTouchEvent(paramMotionEvent);
}
 
@Override
public boolean onTouchEvent(
    @NonNull CoordinatorLayout parent, @NonNull V child, @NonNull MotionEvent ev) {
  boolean consumeUp = false;
  switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_MOVE:
      final int activePointerIndex = ev.findPointerIndex(activePointerId);
      if (activePointerIndex == -1) {
        return false;
      }

      final int y = (int) ev.getY(activePointerIndex);
      int dy = lastMotionY - y;
      lastMotionY = y;
      // We're being dragged so scroll the ABL
      scroll(parent, child, dy, getMaxDragOffset(child), 0);
      break;
    case MotionEvent.ACTION_POINTER_UP:
      int newIndex = ev.getActionIndex() == 0 ? 1 : 0;
      activePointerId = ev.getPointerId(newIndex);
      lastMotionY = (int) (ev.getY(newIndex) + 0.5f);
      break;
    case MotionEvent.ACTION_UP:
      if (velocityTracker != null) {
        consumeUp = true;
        velocityTracker.addMovement(ev);
        velocityTracker.computeCurrentVelocity(1000);
        float yvel = velocityTracker.getYVelocity(activePointerId);
        fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
      }

      // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL:
      isBeingDragged = false;
      activePointerId = INVALID_POINTER;
      if (velocityTracker != null) {
        velocityTracker.recycle();
        velocityTracker = null;
      }
      break;
  }

  if (velocityTracker != null) {
    velocityTracker.addMovement(ev);
  }

  return isBeingDragged || consumeUp;
}
 
源代码19 项目: UltimateAndroid   文件: PullToZoomListView.java
public boolean onTouchEvent(MotionEvent paramMotionEvent) {
    Log.d(TAG, "action = " + (0xFF & paramMotionEvent.getAction()));
    if (mHeaderView != null && !isHideHeader && isEnableZoom) {
        switch (0xFF & paramMotionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_OUTSIDE:
                if (!mScalingRunnable.isFinished()) {
                    mScalingRunnable.abortAnimation();
                }
                mLastMotionY = paramMotionEvent.getY();
                mActivePointerId = paramMotionEvent.getPointerId(0);
                mMaxScale = (mScreenHeight / mHeaderHeight);
                mLastScale = (mHeaderContainer.getBottom() / mHeaderHeight);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "mActivePointerId" + mActivePointerId);
                int j = paramMotionEvent.findPointerIndex(mActivePointerId);
                if (j == INVALID_VALUE) {
                    Log.e("PullToZoomListView", "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                } else {
                    if (mLastMotionY == -1.0F) {
                        mLastMotionY = paramMotionEvent.getY(j);
                    }
                    if (mHeaderContainer.getBottom() >= mHeaderHeight) {
                        ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams();
                        float f = ((paramMotionEvent.getY(j) - mLastMotionY + mHeaderContainer.getBottom()) / mHeaderHeight - mLastScale) / 2.0F + mLastScale;
                        if ((mLastScale <= 1.0D) && (f < mLastScale)) {
                            localLayoutParams.height = mHeaderHeight;
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                            return super.onTouchEvent(paramMotionEvent);
                        }
                        mLastScale = Math.min(Math.max(f, 1.0F), mMaxScale);
                        localLayoutParams.height = ((int) (mHeaderHeight * mLastScale));
                        if (localLayoutParams.height < mScreenHeight) {
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                        }
                        mLastMotionY = paramMotionEvent.getY(j);
                        return true;
                    }
                    mLastMotionY = paramMotionEvent.getY(j);
                }
                break;
            case MotionEvent.ACTION_UP:
                reset();
                endScaling();
                break;
            case MotionEvent.ACTION_CANCEL:
                int i = paramMotionEvent.getActionIndex();
                mLastMotionY = paramMotionEvent.getY(i);
                mActivePointerId = paramMotionEvent.getPointerId(i);
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                onSecondaryPointerUp(paramMotionEvent);
                mLastMotionY = paramMotionEvent.getY(paramMotionEvent.findPointerIndex(mActivePointerId));
                break;
        }
    }
    return super.onTouchEvent(paramMotionEvent);
}
 
源代码20 项目: TelePlus-Android   文件: ItemTouchHelper.java
@Override
public void onTouchEvent(RecyclerView recyclerView, 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;
        }
    }
}