List of usage examples for android.view MotionEvent getPointerCount
public final int getPointerCount()
From source file:jackson.com.slidingmenulib.MyViewDragHelper.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; }/*from w ww. ja v a2s . c o m*/ final float x = ev.getX(i); final float y = ev.getY(i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
From source file:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java
/** * Manage cursor for measurement/*from w w w .ja v a 2s . c o m*/ */ private void measureEvent(MotionEvent event) { switch (event.getPointerCount()) { case 1: graphView.setCursor(event.getX(), event.getY()); // TODO: if touch point is very close to boundary for a long time, move the view break; case 2: if (isInGraphView(event.getX(1), event.getY(1))) { isMeasure = !isMeasure; SelectorText st = (SelectorText) findViewById(R.id.graph_view_mode); st.performClick(); } } }
From source file:com.yanzhenjie.durban.view.OverlayView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (mCropViewRect.isEmpty() || mFreestyleCropMode == FREESTYLE_CROP_MODE_DISABLE) { return false; }// w w w. j av a2s. co m float x = event.getX(); float y = event.getY(); if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { mCurrentTouchCornerIndex = getCurrentTouchIndex(x, y); boolean shouldHandle = mCurrentTouchCornerIndex != -1; if (!shouldHandle) { mPreviousTouchX = -1; mPreviousTouchY = -1; } else if (mPreviousTouchX < 0) { mPreviousTouchX = x; mPreviousTouchY = y; } return shouldHandle; } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) { if (event.getPointerCount() == 1 && mCurrentTouchCornerIndex != -1) { x = Math.min(Math.max(x, getPaddingLeft()), getWidth() - getPaddingRight()); y = Math.min(Math.max(y, getPaddingTop()), getHeight() - getPaddingBottom()); updateCropViewRect(x, y); mPreviousTouchX = x; mPreviousTouchY = y; return true; } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { mPreviousTouchX = -1; mPreviousTouchY = -1; mCurrentTouchCornerIndex = -1; if (mCallback != null) { mCallback.onCropRectUpdated(mCropViewRect); } } return false; }
From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { // Ignore touch events if not enabled. return false; }// w ww. j av a 2 s. c o m final int action = event.getAction(); final int pointerCount = event.getPointerCount(); final Handler handler = getHandler(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: { // Throw away event if we have already seen at least this many // fingers before. if (mMaxFingersDown > pointerCount) { return true; } if (handler != null) { handler.removeCallbacks(mPendingCheckForTap); handler.removeCallbacks(mPendingCheckForLongPress); } mPendingCheckForTap = new CheckForTap(); postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); mMaxFingersDown = pointerCount; mMotionPosition = INVALID_POSITION; updateMotionCoords(event, pointerCount); mTouchMode = TOUCH_MODE_DOWN; return true; } case MotionEvent.ACTION_DOWN: { mMaxFingersDown = pointerCount; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); updateMotionCoords(event, pointerCount); mMotionPosition = pointToPosition(mMotionX.get(0).intValue(), mMotionY.get(0).intValue()); mTouchMode = TOUCH_MODE_DOWN; return true; } case MotionEvent.ACTION_MOVE: { if (mMaxFingersDown == 1 && mMotionPosition != NO_MATCHED_CHILD && mMotionPosition == pointToPosition((int) event.getX(), (int) event.getY())) { // Ignore movement in single touch mode until the user has // moved out of the prop hit area. return true; } boolean moveIsOverSlop = false; int touchSlop = mMaxFingersDown > 1 ? mTouchSlop * 6 : mTouchSlop; for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { int pointerId = event.getPointerId(pointerIndex); moveIsOverSlop = moveIsOverSlop || Math.abs(event.getY(pointerIndex) - mMotionY.get(pointerId)) > touchSlop || Math.abs(event.getX(pointerIndex) - mMotionX.get(pointerId)) > touchSlop; } if (mTouchMode != TOUCH_MODE_AT_REST && moveIsOverSlop) { // Too much movement to be a tap event. mTouchMode = TOUCH_MODE_AT_REST; final View child = getChildAt(mMotionPosition); if (child != null) { child.setPressed(false); } setPressed(false); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } mMotionPosition = NO_MATCHED_CHILD; updateSelectorState(); invalidate(); } return true; } case MotionEvent.ACTION_UP: { if (mTouchMode == TOUCH_MODE_FINISHED_LONG_PRESS) { return true; } if (mTouchMode == TOUCH_MODE_AT_REST) { break; } // Handle stage multi-touch. if (mMotionPosition == NO_MATCHED_CHILD) { if (mPerformPropClick == null) { mPerformPropClick = new PerformClick(); } final PerformClick performPropClick = mPerformPropClick; performPropClick.mClickMotionPosition = mMotionPosition; performPropClick.rememberWindowAttachCount(); if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) { if (handler != null) { handler.removeCallbacks( mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged) { // Got here so must be a tap. The long press would // have triggered inside the delayed runnable. mTouchMode = TOUCH_MODE_TAP; positionSelector(this); setPressed(true); updateSelectorState(); invalidate(); resetSelectorTransition(getVirtualFingers()); if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_AT_REST; setPressed(false); if (!mDataChanged) { performPropClick.run(); } updateSelectorState(); invalidate(); } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_AT_REST; } } else if (!mDataChanged) { performPropClick.run(); } } else { // Handle touch on child. final View child = getChildAt(mMotionPosition); if (child != null && !child.hasFocusable()) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformPropClick == null) { mPerformPropClick = new PerformClick(); } final PerformClick performPropClick = mPerformPropClick; performPropClick.mClickMotionPosition = mMotionPosition; performPropClick.rememberWindowAttachCount(); if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) { if (handler != null) { handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged) { // Got here so must be a tap. The long press // would // have triggered inside the delayed runnable. mTouchMode = TOUCH_MODE_TAP; child.setPressed(true); positionSelector(child); setPressed(true); updateSelectorState(); invalidate(); resetSelectorTransition(getVirtualFingers()); if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_AT_REST; child.setPressed(false); setPressed(false); updateSelectorState(); invalidate(); if (!mDataChanged) { performPropClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_AT_REST; updateSelectorState(); invalidate(); } } else if (!mDataChanged) { performPropClick.run(); } } } return true; } } return true; }
From source file:com.cyanogenmod.filemanager.ui.widgets.ViewDragHelper.java
private void saveLastMotion(MotionEvent ev) { final int pointerCount = ev.getPointerCount(); for (int i = 0; i < pointerCount; i++) { final int pointerId = ev.getPointerId(i); final float x = ev.getX(i); final float y = ev.getY(i); mLastMotionX[pointerId] = x;//from w w w. jav a 2 s . com mLastMotionY[pointerId] = y; } }
From source file:ngoctdn.vng.gesture.CupcakeGestureDetector.java
public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mVelocityTracker = VelocityTracker.obtain(); if (null != mVelocityTracker) { mVelocityTracker.addMovement(ev); } else {//from w ww .j a v a2s.c o m Log.i(LOG_TAG, "Velocity tracker is null"); } mLastTouchX = getActiveX(ev); mLastTouchY = getActiveY(ev); mFirstRawTouchY = ev.getRawY(); mLastRawTouchY = ev.getRawY(); mIsDragging = false; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_POINTER_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; case MotionEvent.ACTION_MOVE: { final float x = getActiveX(ev); final float y = getActiveY(ev); final float dx = x - mLastTouchX, dy = y - mLastTouchY; if (!mIsDragging) { // Use Pythagoras to see if drag length is larger than // touch slop mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop; } if (mIsDragging) { if (ev.getPointerCount() == 1) mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy); mLastTouchX = x; mLastTouchY = y; mLastRawTouchY = ev.getRawY(); // if (mListener != null) { // mListener.onScrolling(mLastRawTouchY, ev.getRawY()); // mLastRawTouchY = ev.getRawY(); // } if (null != mVelocityTracker) { mVelocityTracker.addMovement(ev); } } if (mActivePointerId == -1 && mListener != null) { mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0); } break; } case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { if (mIsDragging) { if (null != mVelocityTracker) { mLastTouchX = getActiveX(ev); mLastTouchY = getActiveY(ev); // if (mListener != null) { // mListener.onScrolling(mFirstTouchY, mLastTouchY); // } // Compute velocity within the last 1000ms mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity(); // If the velocity is greater than minVelocity, call // listener if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) { mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY); } } } if (mListener != null) { mLastRawTouchY = ev.getRawY(); if (mVelocityTracker != null) mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity()); else mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0); } // Recycle Velocity Tracker if (null != mVelocityTracker) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } return true; }
From source file:ngoctdn.vng.gesture.DragGestureDetector.java
public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mVelocityTracker = VelocityTracker.obtain(); if (null != mVelocityTracker) { mVelocityTracker.addMovement(ev); } else {/* w ww .ja v a 2s .c o m*/ Log.i(LOG_TAG, "Velocity tracker is null"); } mLastTouchX = getActiveX(ev); mLastTouchY = getActiveY(ev); mFirstRawTouchY = ev.getRawY(); mLastRawTouchY = ev.getRawY(); mIsDragging = false; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_POINTER_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; case MotionEvent.ACTION_MOVE: { final float x = getActiveX(ev); final float y = getActiveY(ev); final float dx = x - mLastTouchX, dy = y - mLastTouchY; if (!mIsDragging) { // Use Pythagoras to see if drag length is larger than // touch slop mIsDragging = (float) Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop; } if (mIsDragging) { if (ev.getPointerCount() == 1) mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy); mLastTouchX = x; mLastTouchY = y; mLastRawTouchY = ev.getRawY(); // if (mListener != null) { // mListener.onScrolling(mLastRawTouchY, ev.getRawY()); // mLastRawTouchY = ev.getRawY(); // } if (null != mVelocityTracker) { mVelocityTracker.addMovement(ev); } } if (mActivePointerId == -1 && mListener != null) { mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0); } break; } // case MotionEvent.ACTION_CANCEL: { // if (mListener != null) { // mLastRawTouchY = ev.getRawY(); // mListener.onRelease(mFirstRawTouchY, ev.getRawY()); // } // // Recycle Velocity Tracker // if (null != mVelocityTracker) { // mVelocityTracker.recycle(); // mVelocityTracker = null; // } // break; // } case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { if (mIsDragging) { if (null != mVelocityTracker) { mLastTouchX = getActiveX(ev); mLastTouchY = getActiveY(ev); // if (mListener != null) { // mListener.onScrolling(mFirstTouchY, mLastTouchY); // } // Compute velocity within the last 1000ms mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity(); // If the velocity is greater than minVelocity, call // listener if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) { mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY); } } } if (mListener != null) { mLastRawTouchY = ev.getRawY(); if (mVelocityTracker != null) mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity()); else mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0); } // Recycle Velocity Tracker if (null != mVelocityTracker) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } return true; }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
/** * Manage cursor for measurement//from w w w . j a va2 s . com */ private void measureEvent(MotionEvent event) { switch (event.getPointerCount()) { case 1: graphView.setCursor(event.getX(), event.getY()); // TODO: if touch point is very close to boundary for a long time, move the view break; case 2: if (isInGraphView(event.getX(1), event.getY(1))) { switchMeasureAndScaleMode(); } } }
From source file:com.jsibbold.zoomage.ZoomageView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (isEnabled() && (zoomable || translatable)) { if (getScaleType() != ScaleType.MATRIX) { super.setScaleType(ScaleType.MATRIX); }//from w ww . java 2 s .c o m if (startValues == null) { setStartValues(); } //get the current state of the image matrix, its values, and the bounds of the drawn bitmap matrix.set(getImageMatrix()); matrix.getValues(mValues); updateBounds(mValues); scaleDetector.onTouchEvent(event); /* if the event is a down touch, or if the number of touch points changed, * we should reset our start point, as event origins have likely shifted to a * different part of the screen*/ if (event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getPointerCount() != previousPointerCount) { last.set(scaleDetector.getFocusX(), scaleDetector.getFocusY()); } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { final float focusx = scaleDetector.getFocusX(); final float focusy = scaleDetector.getFocusY(); if (translatable) { //calculate the distance for translation float xdistance = getXDistance(focusx, last.x); float ydistance = getYDistance(focusy, last.y); matrix.postTranslate(xdistance, ydistance); } if (zoomable) { matrix.postScale(scaleBy, scaleBy, focusx, focusy); } setImageMatrix(matrix); last.set(focusx, focusy); } if (event.getActionMasked() == MotionEvent.ACTION_UP) { scaleBy = 1f; resetImage(); } //this tracks whether they have changed the number of fingers down previousPointerCount = event.getPointerCount(); return true; } return super.onTouchEvent(event); }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; mGestureDetector.onTouchEvent(event); mScaleGestureDetector.onTouchEvent(event); if (mInteractionMode == InteractionMode.SCALE) { return true; }/* w w w. j a v a2 s. c om*/ int ex = (int) event.getX(); int ey = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; System.currentTimeMillis(); mMasterImage.setOriginalTranslation(mMasterImage.getTranslation()); } if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) { mTouch.x = ex; mTouch.y = ey; float scaleFactor = mMasterImage.getScaleFactor(); if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = mMasterImage.getOriginalTranslation(); Point translation = mMasterImage.getTranslation(); translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); mMasterImage.setTranslation(translation); } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; mTouch.y = 0; if (mMasterImage.getScaleFactor() <= 1) { mMasterImage.setScaleFactor(1); mMasterImage.resetTranslation(); } } float scaleFactor = mMasterImage.getScaleFactor(); Point translation = mMasterImage.getTranslation(); constrainTranslation(translation, scaleFactor); mMasterImage.setTranslation(translation); invalidate(); return true; }