Java Code Examples for android.view.MotionEvent#ACTION_POINTER_2_DOWN
The following examples show how to use
android.view.MotionEvent#ACTION_POINTER_2_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: VideoContainerGestureDetector.java From sealrtc-android with MIT License | 6 votes |
public boolean onTouchEvent(MotionEvent event) { // Log.d(TAG, parsEvent("onTouchEvent: ", event)); if (event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) { // Log.d(TAG, "onTouchEvent: scale is true"); isScaling = true; } if (event.getAction() == MotionEvent.ACTION_POINTER_UP || event.getAction() == MotionEvent.ACTION_POINTER_2_UP) { isScaling = false; } if (translateGestureAble && mGesture != null) { mGesture.onTouchEvent(event); } if (scaleGestureAble && mScaleGesture != null) { mScaleGesture.onTouchEvent(event); } checkScrollBounds(event); return true; }
Example 2
Source File: KeyboardController.java From gravitydefied with GNU General Public License v2.0 | 6 votes |
private static String actionToString(int action) { switch (action) { case MotionEvent.ACTION_DOWN: return "ACTION_DOWN"; case MotionEvent.ACTION_POINTER_DOWN: return "ACTION_POINTER_DOWN"; case MotionEvent.ACTION_POINTER_2_DOWN: return "ACTION_POINTER_2_DOWN"; case MotionEvent.ACTION_POINTER_2_UP: return "ACTION_POINTER_2_UP"; case MotionEvent.ACTION_POINTER_3_DOWN: return "ACTION_POINTER_3_DOWN"; case MotionEvent.ACTION_POINTER_3_UP: return "ACTION_POINTER_3_UP"; case MotionEvent.ACTION_UP: return "ACTION_UP"; case MotionEvent.ACTION_POINTER_UP: return "ACTION_POINTER_UP"; case MotionEvent.ACTION_MOVE: return "ACTION_MOVE"; } return "?"; }
Example 3
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 4
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 5
Source File: VideoContainerGestureDetector.java From sealrtc-android with MIT License | 4 votes |
private String parsEvent(String method, MotionEvent event) { String parseStr = null; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { parseStr = "ACTION_DOWN"; break; } case MotionEvent.ACTION_MOVE: { parseStr = "ACTION_MOVE"; break; } case MotionEvent.ACTION_UP: { parseStr = "ACTION_UP"; break; } case MotionEvent.ACTION_CANCEL: { parseStr = "ACTION_CANCEL"; break; } case MotionEvent.ACTION_SCROLL: { parseStr = "ACTION_SCROLL"; break; } case MotionEvent.ACTION_POINTER_UP: { parseStr = "ACTION_POINTER_UP"; break; } case MotionEvent.ACTION_POINTER_2_DOWN: { parseStr = "ACTION_POINTER_2_DOWN"; break; } default: { } } return method + event.getAction() + " -- " + parseStr; }
Example 6
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 7
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 8
Source File: GestureDetector.java From Carbon with Apache License 2.0 | 4 votes |
private void handleTwoPointers(MotionEvent event) { clicks = 0; switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_2_DOWN: case MotionEvent.ACTION_MOVE: if (!transforming) { transforming = true; handler.removeCallbacks(pressHandler); pressHandler = null; handler.removeCallbacks(longPressHandler); longPressHandler = null; handler.removeCallbacks(tapHandler); tapHandler = null; prevRotation = (float) Math.atan2(event.getY(0) - event.getY(1), event.getX(0) - event.getX(1)); prevDist = (float) Math.sqrt(Math.pow(event.getX(0) - event.getX(1), 2) + Math.pow(event.getY(0) - event.getY(1), 2)); prevCenterX = (event.getX(0) + event.getX(1)) / 2; prevCenterY = (event.getY(0) + event.getY(1)) / 2; } else { float dist = (float) Math.sqrt(Math.pow(event.getX(0) - event.getX(1), 2) + Math.pow(event.getY(0) - event.getY(1), 2)); float cx = (event.getX(0) + event.getX(1)) / 2; float cy = (event.getY(0) + event.getY(1)) / 2; float dx = cx - prevCenterX; float dy = cy - prevCenterY; float rotation = (float) Math.atan2(event.getY(0) - event.getY(1), event.getX(0) - event.getX(1)); float scale = dist / prevDist; float rx = rotation - prevRotation; fireTransformEvent(event, cx, cy, dx, dy, rx, scale); prevCenterX = cx; prevCenterY = cy; prevRotation = rotation; prevDist = dist; } break; } }
Example 9
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; }