Java Code Examples for android.view.MotionEvent#ACTION_POINTER_2_UP

The following examples show how to use android.view.MotionEvent#ACTION_POINTER_2_UP . 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 vote down vote up
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: LoopViewPager.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (MotionEventCompat.getActionMasked(ev)) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEventCompat.ACTION_POINTER_DOWN:
            mHandler.removeMessages(AUTO_SCROLL_MESSAGE);
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_POINTER_2_UP:
        case MotionEvent.ACTION_POINTER_3_UP:
        case MotionEvent.ACTION_CANCEL:
            mHandler.removeMessages(AUTO_SCROLL_MESSAGE);
            mHandler.sendEmptyMessageDelayed(AUTO_SCROLL_MESSAGE, delayTimeInMills);
            break;
        default:
            break;
    }
    return super.onTouchEvent(ev);
}
 
Example 3
Source File: FixedViewPager.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (MotionEventCompat.getActionMasked(ev)) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEventCompat.ACTION_POINTER_DOWN:
            if (null != mOnViewPagerTouchListener) {
                mOnViewPagerTouchListener.onTouchDown();
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_POINTER_2_UP:
        case MotionEvent.ACTION_POINTER_3_UP:
        case MotionEvent.ACTION_CANCEL:
            if (null != mOnViewPagerTouchListener) {
                mOnViewPagerTouchListener.onTouchUp();
            }
            break;
        default:
            break;
    }
    return super.onTouchEvent(ev);
}
 
Example 4
Source File: KeyboardController.java    From gravitydefied with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: TextSticker.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    gestureDetector.onTouchEvent(event);
    if (MotionEvent.ACTION_UP == event.getAction() || MotionEvent.ACTION_POINTER_UP == event.getAction() || MotionEvent.ACTION_POINTER_1_UP == event.getAction() || MotionEvent.ACTION_POINTER_2_UP == event.getAction()) {
        setDoubleDownPoints(0, 0, 0, 0);
        lastDoubleDegress = 1000;
        lastDegree = computeDegree(new Point((int) dstPs[4], (int) dstPs[5]), new Point((int) dstPs[8], (int) dstPs[9]));
    }

    return !isOut;
}
 
Example 6
Source File: BitmapSticker.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    gestureDetector.onTouchEvent(event);
    if (MotionEvent.ACTION_UP == event.getAction() || MotionEvent.ACTION_POINTER_UP == event.getAction() || MotionEvent.ACTION_POINTER_1_UP == event.getAction() || MotionEvent.ACTION_POINTER_2_UP == event.getAction()) {
        setDoubleDownPoints(0, 0, 0, 0);
        lastDoubleDegress = 1000;
        lastDegree = computeDegree(new Point((int) dstPs[4], (int) dstPs[5]), new Point((int) dstPs[8], (int) dstPs[9]));
    }

    return !isOut;
}
 
Example 7
Source File: TextSticker.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    gestureDetector.onTouchEvent(event);
    if (MotionEvent.ACTION_UP == event.getAction() || MotionEvent.ACTION_POINTER_UP == event.getAction() || MotionEvent.ACTION_POINTER_1_UP == event.getAction() || MotionEvent.ACTION_POINTER_2_UP == event.getAction()) {
        setDoubleDownPoints(0, 0, 0, 0);
        lastDoubleDegress = 1000;
        lastDegree = computeDegree(new Point((int) dstPs[4], (int) dstPs[5]), new Point((int) dstPs[8], (int) dstPs[9]));
    }

    return !isOut;
}
 
Example 8
Source File: BitmapSticker.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    gestureDetector.onTouchEvent(event);
    if (MotionEvent.ACTION_UP == event.getAction() || MotionEvent.ACTION_POINTER_UP == event.getAction() || MotionEvent.ACTION_POINTER_1_UP == event.getAction() || MotionEvent.ACTION_POINTER_2_UP == event.getAction()) {
        setDoubleDownPoints(0, 0, 0, 0);
        lastDoubleDegress = 1000;
        lastDegree = computeDegree(new Point((int) dstPs[4], (int) dstPs[5]), new Point((int) dstPs[8], (int) dstPs[9]));
    }

    return !isOut;
}
 
Example 9
Source File: DragPinchListener.java    From AndroidPDF with Apache License 2.0 4 votes vote down vote up
@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 10
Source File: ScaleImageView.java    From umeng_community_android with MIT License 4 votes vote down vote up
@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 11
Source File: ScaleImageView.java    From ImageChoose with MIT License 4 votes vote down vote up
@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;
}