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

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

源代码1 项目: android_9.0.0_r45   文件: HorizontalScrollView.java
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = (int) ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码2 项目: Lay-s   文件: PLAAbsListView.java
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
    MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mMotionX = (int) ev.getX(newPointerIndex);
        mMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码3 项目: LB-Launcher   文件: 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();
        }
    }
}
 
源代码4 项目: 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();
        }
    }
}
 
源代码5 项目: Nimingban   文件: BothScrollView.java
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = (int) ev.getY(newPointerIndex);
        mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码6 项目: prayer-times-android   文件: MyScrollView.java
private void onSecondaryPointerUp(@NonNull MotionEvent ev) {
    int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
        mLastMotionY = ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码7 项目: timecat   文件: CardStackView.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();
        }
    }
}
 
@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);
}
 
源代码9 项目: iBeebo   文件: VersionedGestureDetector.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:
            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);
}
 
@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);
}
 
源代码11 项目: ImageSelector   文件: CropCompat.java
@TargetApi(VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
 return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
源代码12 项目: UltimateAndroid   文件: Compat.java
@TargetApi(VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
源代码13 项目: giffun   文件: Util.java
static int getPointerIndex(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
源代码14 项目: MoeGallery   文件: Compat.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
源代码15 项目: photo-editor-android   文件: MultiTouchListener.java
@Override
public boolean onTouch(View view, MotionEvent event) {
    mScaleGestureDetector.onTouchEvent(view, event);

    if (!isTranslateEnabled) {
        return true;
    }

    int action = event.getAction();

    int x = (int) event.getRawX();
    int y = (int) event.getRawY();

    switch (action & event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPrevX = event.getX();
            mPrevY = event.getY();
            mPrevRawX = event.getRawX();
            mPrevRawY = event.getRawY();
            mActivePointerId = event.getPointerId(0);
            deleteView.setVisibility(View.VISIBLE);
            view.bringToFront();
            firePhotoEditorSDKListener(view, true);
            break;
        case MotionEvent.ACTION_MOVE:
            int pointerIndexMove = event.findPointerIndex(mActivePointerId);
            if (pointerIndexMove != -1) {
                float currX = event.getX(pointerIndexMove);
                float currY = event.getY(pointerIndexMove);
                if (!mScaleGestureDetector.isInProgress()) {
                    adjustTranslation(view, currX - mPrevX, currY - mPrevY);
                }
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            if (isViewInBounds(deleteView, x, y)) {
                if (onMultiTouchListener != null)
                    onMultiTouchListener.onRemoveViewListener(view);
            } else if (!isViewInBounds(photoEditImageView, x, y)) {
                view.animate().translationY(0).translationY(0);
            }
            deleteView.setVisibility(View.GONE);
            firePhotoEditorSDKListener(view, false);
            float mCurrentCancelX = event.getRawX();
            float mCurrentCancelY = event.getRawY();
            if (mCurrentCancelX == mPrevRawX || mCurrentCancelY == mPrevRawY) {
                if (view instanceof TextView) {
                    if (onMultiTouchListener != null) {
                        onMultiTouchListener.onEditTextClickListener(
                                ((TextView) view).getText().toString(), ((TextView) view).getCurrentTextColor());
                    }
                    if (onPhotoEditorSDKListener != null) {
                        onPhotoEditorSDKListener.onEditTextChangeListener(
                                ((TextView) view).getText().toString(), ((TextView) view).getCurrentTextColor());
                    }
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            int pointerIndexPointerUp = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            int pointerId = event.getPointerId(pointerIndexPointerUp);
            if (pointerId == mActivePointerId) {
                int newPointerIndex = pointerIndexPointerUp == 0 ? 1 : 0;
                mPrevX = event.getX(newPointerIndex);
                mPrevY = event.getY(newPointerIndex);
                mActivePointerId = event.getPointerId(newPointerIndex);
            }
            break;
    }

    return true;
}
 
源代码16 项目: Alite   文件: MultiTouchHandler.java
@Override
public boolean onTouch(View v, MotionEvent event) {		
	if (freeze != -1 && (System.currentTimeMillis() - freeze) < delay) {
		return true;
	}
	freeze = -1;
	synchronized (this) {
		if (currentView != v) {
			return false;
		}
		scaleDetector.onTouchEvent(event);
		sweepDetector.onTouchEvent(event);
		int action = event.getAction() & MotionEvent.ACTION_MASK;
		int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
		int pointerCount = event.getPointerCount();
		TouchEvent touchEvent;
		
		for (int i = 0; i < MAX_TOUCHPOINTS; i++) {
			if (i >= pointerCount) {
				isTouched[i] = false;
				id[i] = -1;
				continue;
			}
			int pointerId = event.getPointerId(i);
			if (event.getAction() != MotionEvent.ACTION_MOVE && i != pointerIndex) {
				continue;
			}
			switch (action) {
				case MotionEvent.ACTION_DOWN:
				case MotionEvent.ACTION_POINTER_DOWN:
					touchEvent = touchEventPool.newObject();
					touchEvent.type = TouchEvent.TOUCH_DOWN;
					touchEvent.pointer = pointerId;
					touchEvent.x = touchX[i] = (int) ((event.getX(i) - offsetX) * scaleX);
					touchEvent.y = touchY[i] = (int) ((event.getY(i) - offsetY) * scaleY);
					isTouched[i] = true;
					id[i] = pointerId;
					touchEventsBuffer.add(touchEvent);
					break;
					
				case MotionEvent.ACTION_UP:
				case MotionEvent.ACTION_POINTER_UP:
				case MotionEvent.ACTION_CANCEL:
					touchEvent = touchEventPool.newObject();
					touchEvent.type = TouchEvent.TOUCH_UP;
					touchEvent.pointer = pointerId;
					touchEvent.x = touchX[i] = (int) ((event.getX(i) - offsetX) * scaleX);
					touchEvent.y = touchY[i] = (int) ((event.getY(i) - offsetY) * scaleY);
					isTouched[i] = false;
					id[i] = -1;
					touchEventsBuffer.add(touchEvent);
					break;
					
				case MotionEvent.ACTION_MOVE:
					touchEvent = touchEventPool.newObject();
					touchEvent.type = TouchEvent.TOUCH_DRAGGED;
					touchEvent.pointer = pointerId;
					touchEvent.x = touchX[i] = (int) ((event.getX(i) - offsetX) * scaleX);
					touchEvent.y = touchY[i] = (int) ((event.getY(i) - offsetY) * scaleY);
					isTouched[i] = true;
					id[i] = pointerId;
					touchEventsBuffer.add(touchEvent);
					break;								
			}
		}
		return true;
	}		
}
 
源代码17 项目: Simple-Solitaire   文件: DynamicListView.java
@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);
}
 
源代码18 项目: GalleryFinal   文件: Compat.java
@TargetApi(VERSION_CODES.HONEYCOMB)
private static int getPointerIndexHoneyComb(int action) {
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}
 
源代码19 项目: PhotoEditor   文件: MultiTouchListener.java
@Override
public boolean onTouch(View view, MotionEvent event) {
    mScaleGestureDetector.onTouchEvent(view, event);
    mGestureListener.onTouchEvent(event);

    if (!isTranslateEnabled) {
        return true;
    }

    int action = event.getAction();

    int x = (int) event.getRawX();
    int y = (int) event.getRawY();

    switch (action & event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPrevX = event.getX();
            mPrevY = event.getY();
            mPrevRawX = event.getRawX();
            mPrevRawY = event.getRawY();
            mActivePointerId = event.getPointerId(0);
            if (deleteView != null) {
                deleteView.setVisibility(View.VISIBLE);
            }
            view.bringToFront();
            firePhotoEditorSDKListener(view, true);
            break;
        case MotionEvent.ACTION_MOVE:
            int pointerIndexMove = event.findPointerIndex(mActivePointerId);
            if (pointerIndexMove != -1) {
                float currX = event.getX(pointerIndexMove);
                float currY = event.getY(pointerIndexMove);
                if (!mScaleGestureDetector.isInProgress()) {
                    adjustTranslation(view, currX - mPrevX, currY - mPrevY);
                }
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            if (deleteView != null && isViewInBounds(deleteView, x, y)) {
                if (onMultiTouchListener != null)
                    onMultiTouchListener.onRemoveViewListener(view);
            } else if (!isViewInBounds(photoEditImageView, x, y)) {
                view.animate().translationY(0).translationY(0);
            }
            if (deleteView != null) {
                deleteView.setVisibility(View.GONE);
            }
            firePhotoEditorSDKListener(view, false);
            break;
        case MotionEvent.ACTION_POINTER_UP:
            int pointerIndexPointerUp = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            int pointerId = event.getPointerId(pointerIndexPointerUp);
            if (pointerId == mActivePointerId) {
                int newPointerIndex = pointerIndexPointerUp == 0 ? 1 : 0;
                mPrevX = event.getX(newPointerIndex);
                mPrevY = event.getY(newPointerIndex);
                mActivePointerId = event.getPointerId(newPointerIndex);
            }
            break;
    }
    return true;
}
 
源代码20 项目: ImagePicker   文件: Util.java
static int getPointerIndex(int action)
{
    return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
}