Java Code Examples for android.view.MotionEvent#ACTION_POINTER_1_DOWN
The following examples show how to use
android.view.MotionEvent#ACTION_POINTER_1_DOWN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TouchImageView.java From YiBo with Apache License 2.0 | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (Logger.isDebug()) { Log.d(TAG, "onTouchEvent……"); dumpEvent(event); } int action = event.getAction() & MotionEvent.ACTION_MASK; if (event.getPointerCount() == 2 && (action == MotionEvent.ACTION_POINTER_1_DOWN || action == MotionEvent.ACTION_POINTER_2_DOWN )) { mScaleGesture = true; } else if (event.getPointerCount() == 1 && action == MotionEvent.ACTION_DOWN) { mScaleGesture = false; } if (mScaleGesture) { mScaleGestureDetector.onTouchEvent(event); } else { mGestureDetector.onTouchEvent(event); } return true; }
Example 2
Source File: PhotoView.java From imsdk-android with MIT License | 5 votes |
private boolean onTouchEventInternal(@NonNull MotionEvent event) { int touchCount = event.getPointerCount(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_1_DOWN: case MotionEvent.ACTION_POINTER_2_DOWN: maxTouchCount = Math.max(maxTouchCount, touchCount); return true; default: break; } return false; }
Example 3
Source File: DragPinchListener.java From AndroidPDF with Apache License 2.0 | 4 votes |
@Override public boolean onTouch(View v, MotionEvent event) { mView = v ; switch (event.getAction()) { // NORMAL CASE : FIRST POINTER DOWN case MotionEvent.ACTION_DOWN: // Start dragging startDrag(event); state = State.DRAG; lastDownX = event.getX(); lastDownY = event.getY(); break; // NORMAL CASE : SECOND POINTER DOWN case MotionEvent.ACTION_POINTER_2_DOWN: startDrag(event); startZoom(event); state = State.ZOOM; break; // NORMAL CASE : SECOND POINTER UP case MotionEvent.ACTION_POINTER_2_UP: // End zooming, goes back to dragging state = State.DRAG; break; // NORMAL CASE : FIRST POINTER UP case MotionEvent.ACTION_UP: // End everything state = State.NONE; endDrag(); // Treat clicks if (isClick(event, lastDownX, lastDownY, event.getX(), event.getY())) { long time = System.currentTimeMillis(); handlerClick.removeCallbacks(runnableClick); if (onDoubleTapListener != null) { if (time - lastClickTime < MAX_DOUBLE_CLICK_TIME) { onDoubleTapListener.onDoubleTap(event.getX(), event.getY()); lastClickTime = 0; } else { lastClickTime = System.currentTimeMillis(); handlerClick.postDelayed(runnableClick, MAX_CLICK_TIME); } } else { handlerClick.postDelayed(runnableClick,0); } } break; // TRICKY CASE : FIRST POINTER UP WHEN SECOND STILL DOWN case MotionEvent.ACTION_POINTER_1_UP: dragLastX = pointer2LastX; dragLastY = pointer2LastY; state = State.DRAG; break; // TRICKY CASE : FIRST POINTER UP THEN DOWN WHILE SECOND POINTER STILL UP case MotionEvent.ACTION_POINTER_1_DOWN: pointer2LastX = event.getX(POINTER1); pointer2LastY = event.getY(POINTER1); startDrag(event); startZoom(event); state = State.ZOOM; break; // NORMAL CASE : MOVE case MotionEvent.ACTION_MOVE: switch (state) { case ZOOM: pointer2LastX = event.getX(POINTER2); pointer2LastY = event.getY(POINTER2); zoom(event); case DRAG: drag(event); break; default: break; } break; } return true; }
Example 4
Source File: ScaleImageView.java From umeng_community_android with MIT License | 4 votes |
@SuppressWarnings("deprecation") @Override public boolean onTouchEvent(MotionEvent event) { if (mDetector.onTouchEvent(event)) { return true; } int touchCount = event.getPointerCount(); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_1_DOWN: case MotionEvent.ACTION_POINTER_2_DOWN: if (touchCount >= 2) { float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); mPrevDistance = distance; isScaling = true; } else { mPrevMoveX = (int) event.getX(); mPrevMoveY = (int) event.getY(); mLastX = mPrevMoveX; mLastY = mPrevMoveY; } case MotionEvent.ACTION_MOVE: if (touchCount >= 2 && isScaling) { float dist = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); // if ( Math.abs(dist - mPrevDistance) < mSlop ) { // Log.d("", "######## move dis " + dist + " " + mSlop); // return false; // } float scale = (dist - mPrevDistance) / dispDistance(); mPrevDistance = dist; scale += 1; scale = scale * scale; zoomTo(scale, mWidth / 2, mHeight / 2); cutting(); } else if (!isScaling) { int distanceX = mPrevMoveX - (int) event.getX(); int distanceY = mPrevMoveY - (int) event.getY(); mPrevMoveX = (int) event.getX(); mPrevMoveY = (int) event.getY(); mMatrix.postTranslate(-distanceX, -distanceY); cutting(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_2_UP: if (event.getPointerCount() <= 1) { isScaling = false; checkExecuteCallback(event); } else { if (mDefaultScale == 0f) { mDefaultScale = mScale; } } mPrevDistance = 0; mPrevMoveX = 0; mPrevMoveY = 0; mLastX = 0; mLastY = 0; break; } return true; }
Example 5
Source File: ScaleImageView.java From ImageChoose with MIT License | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (mDetector.onTouchEvent(event)) { return true; } int touchCount = event.getPointerCount(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_1_DOWN: case MotionEvent.ACTION_POINTER_2_DOWN: if (touchCount >= 2) { float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); mPrevDistance = distance; isScaling = true; } else { mPrevMoveX = (int) event.getX(); mPrevMoveY = (int) event.getY(); } case MotionEvent.ACTION_MOVE: if (touchCount >= 2 && isScaling) { float dist = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1)); float scale = (dist - mPrevDistance) / dispDistance(); mPrevDistance = dist; scale += 1; scale = scale * scale; zoomTo(scale, mWidth / 2, mHeight / 2); cutting(); } else if (!isScaling) { int distanceX = mPrevMoveX - (int) event.getX(); int distanceY = mPrevMoveY - (int) event.getY(); mPrevMoveX = (int) event.getX(); mPrevMoveY = (int) event.getY(); mMatrix.postTranslate(-distanceX, -distanceY); cutting(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_2_UP: if (event.getPointerCount() <= 1) { isScaling = false; } break; } return true; }