Java Code Examples for android.view.MotionEvent#ACTION_POINTER_UP

The following examples show how to use android.view.MotionEvent#ACTION_POINTER_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: ScrollAndScaleView.java    From KChartView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            touch = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (event.getPointerCount() == 1) {
                //长按之后移动
                if (isLongPress) {
                    onLongPress(event);
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            isLongPress = false;
            touch = false;
            invalidate();
            break;
        case MotionEvent.ACTION_CANCEL:
            isLongPress = false;
            touch = false;
            invalidate();
            break;
    }
    mMultipleTouch=event.getPointerCount()>1;
    this.mDetector.onTouchEvent(event);
    this.mScaleDetector.onTouchEvent(event);
    return true;
}
 
Example 2
Source File: ScrollAndScaleView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            touch = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (event.getPointerCount() == 1) {
                //长按之后移动
                if (isLongPress || !isClosePress) {
                    onLongPress(event);
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            if (!isClosePress) {
                isLongPress = false;
            }
            touch = false;
            invalidate();
            break;
        case MotionEvent.ACTION_CANCEL:
            if (!isClosePress) {
                isLongPress = false;
            }
            touch = false;
            invalidate();
            break;
    }
    mMultipleTouch = event.getPointerCount() > 1;
    this.mDetector.onTouchEvent(event);
    this.mScaleDetector.onTouchEvent(event);
    return true;
}
 
Example 3
Source File: QBadgeView.java    From BottomNavigationBar with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN:
            float x = event.getX();
            float y = event.getY();
            if (mDraggable && event.getPointerId(event.getActionIndex()) == 0
                    && (x > mBadgeBackgroundRect.left && x < mBadgeBackgroundRect.right &&
                    y > mBadgeBackgroundRect.top && y < mBadgeBackgroundRect.bottom)
                    && mBadgeText != null) {
                initRowBadgeCenter();
                mDragging = true;
                updataListener(OnDragStateChangedListener.STATE_START);
                mDefalutRadius = DisplayUtil.dp2px(getContext(), 7);
                getParent().requestDisallowInterceptTouchEvent(true);
                screenFromWindow(true);
                mDragCenter.x = event.getRawX();
                mDragCenter.y = event.getRawY();
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (mDragging) {
                mDragCenter.x = event.getRawX();
                mDragCenter.y = event.getRawY();
                invalidate();
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_CANCEL:
            if (event.getPointerId(event.getActionIndex()) == 0 && mDragging) {
                mDragging = false;
                onPointerUp();
            }
            break;
    }
    return mDragging || super.onTouchEvent(event);
}
 
Example 4
Source File: PZSImageView.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private int parseMotionEvent(MotionEvent ev) {

		switch (ev.getAction() & MotionEvent.ACTION_MASK) {
		case MotionEvent.ACTION_DOWN:
			if( isDoubleTap(ev) )
				return PZS_ACTION_FIT_CENTER;
			else
				return PZS_ACTION_INIT;
		case MotionEvent.ACTION_POINTER_DOWN:
			//more than one pointer is pressed...
			return PZS_ACTION_TRANSLATE_TO_SCALE;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_POINTER_UP:
			if( ev.getPointerCount() == 2 ){
				return PZS_ACTION_SCALE_TO_TRANSLATE;
			}else{
				return PZS_ACTION_INIT;
			}
		case MotionEvent.ACTION_MOVE:
			if( ev.getPointerCount() == 1 )
				return PZS_ACTION_TRANSLATE;
			else if( ev.getPointerCount() == 2 )
				return PZS_ACTION_SCALE;
			return 0;
		}
		return 0;
	}
 
Example 5
Source File: RotateGestureDetector.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleInProgressEvent(int actionCode, MotionEvent event) {
    switch (actionCode) {
        case MotionEvent.ACTION_POINTER_UP:
            // Gesture ended but 
            updateStateByEvent(event);

            if (!mSloppyGesture) {
                mListener.onRotateEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_CANCEL:
            if (!mSloppyGesture) {
                mListener.onRotateEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_MOVE:
            updateStateByEvent(event);

            // Only accept the event if our relative pressure is within
            // a certain limit. This can help filter shaky data as a
            // finger is lifted.
            if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) {
                final boolean updatePrevious = mListener.onRotate(this);
                if (updatePrevious) {
                    mPrevEvent.recycle();
                    mPrevEvent = MotionEvent.obtain(event);
                }
            }
            break;
    }
}
 
Example 6
Source File: RotateGestureDetector.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void handleInProgressEvent(int actionCode, MotionEvent event) {
    switch (actionCode) {
        case MotionEvent.ACTION_POINTER_UP:
            // Gesture ended but
            updateStateByEvent(event);

            if (!mSloppyGesture) {
                mListener.onRotateEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_CANCEL:
            if (!mSloppyGesture) {
                mListener.onRotateEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_MOVE:
            updateStateByEvent(event);

            // Only accept the event if our relative pressure is within
            // a certain limit. This can help filter shaky data as a
            // finger is lifted.
            if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) {
                final boolean updatePrevious = mListener.onRotate(this);
                if (updatePrevious) {
                    mPrevEvent.recycle();
                    mPrevEvent = MotionEvent.obtain(event);
                }
            }
            break;
    }
}
 
Example 7
Source File: RotateGestureDetector.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
public void onTouchEvent(MotionEvent event) {

        final int Action = event.getActionMasked();

        switch (Action) {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_POINTER_UP:
                if (event.getPointerCount() == 2) mPrevSlope = caculateSlope(event);
                break;
            case MotionEvent.ACTION_MOVE:
                if (event.getPointerCount() > 1) {
                    mCurrSlope = caculateSlope(event);

                    double currDegrees = Math.toDegrees(Math.atan(mCurrSlope));
                    double prevDegrees = Math.toDegrees(Math.atan(mPrevSlope));

                    double deltaSlope = currDegrees - prevDegrees;

                    if (Math.abs(deltaSlope) <= MAX_DEGREES_STEP) {
                        mListener.onRotate((float) deltaSlope, (x2 + x1) / 2, (y2 + y1) / 2);
                    }
                    mPrevSlope = mCurrSlope;
                }
                break;
            default:
                break;
        }
    }
 
Example 8
Source File: ShoveGestureDetector.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void handleInProgressEvent(int actionCode, MotionEvent event){ 	
    switch (actionCode) {
        case MotionEvent.ACTION_POINTER_UP:
            // Gesture ended but 
            updateStateByEvent(event);

            if (!mSloppyGesture) {
                mListener.onShoveEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_CANCEL:
            if (!mSloppyGesture) {
                mListener.onShoveEnd(this);
            }

            resetState();
            break;

        case MotionEvent.ACTION_MOVE:
            updateStateByEvent(event);

// Only accept the event if our relative pressure is within
// a certain limit. This can help filter shaky data as a
// finger is lifted. Also check that shove is meaningful.
            if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD
            		&& Math.abs(getShovePixelsDelta()) > 0.5f) {
                final boolean updatePrevious = mListener.onShove(this);
                if (updatePrevious) {
                    mPrevEvent.recycle();
                    mPrevEvent = MotionEvent.obtain(event);
                }
            }
            break;
    }
}
 
Example 9
Source File: TextImageView.java    From TextImageView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
  scaleDetector.onTouchEvent(event);
  rotateDetector.onTouchEvent(event);
  super.onTouchEvent(event);

  final int action = event.getAction();
  switch(action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
      recalculateFocalPoint(event);
      return true;
    case MotionEvent.ACTION_MOVE:
      if (0 < texts.size()) {
        final float x = focalPoint.x;
        final float y = focalPoint.y;
        TextProperties tp = texts.get(texts.size() - 1);

        recalculateFocalPoint(event);

        if (panEnabled) {
          tp.textPosition.x += focalPoint.x - x;
          tp.textPosition.y += focalPoint.y - y;

          tp.rotationCenter.x += focalPoint.x - x;
          tp.rotationCenter.y += focalPoint.y - y;

          reclampText();

          invalidate();
        }
      }
      return true;
  }
  return false;
}
 
Example 10
Source File: MultiPointerGestureDetector.java    From materialup with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the index of the i-th pressed pointer.
 * Normally, the index will be equal to i, except in the case when the pointer is released.
 *
 * @return index of the specified pointer or -1 if not found (i.e. not enough pointers are down)
 */
private int getPressedPointerIndex(MotionEvent event, int i) {
    final int count = event.getPointerCount();
    final int action = event.getActionMasked();
    final int index = event.getActionIndex();
    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_POINTER_UP) {
        if (i >= index) {
            i++;
        }
    }
    return (i < count) ? i : -1;
}
 
Example 11
Source File: ReorderRecyclerView.java    From wear-notify-for-reddit with Apache License 2.0 4 votes vote down vote up
private void handleMotionEvent(MotionEvent event) {
    Log.d(TAG, String.format("handleMotionEvent %s", event));

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE:

            if (activePointerId == INVALID_POINTER_ID) {
                break;
            }

            int pointerIndex = event.findPointerIndex(activePointerId);

            lastEventY = (int) event.getY(pointerIndex);
            lastEventX = (int) event.getX(pointerIndex);
            int deltaY = lastEventY - downY;
            int deltaX = lastEventX - downX;

            if (cellIsMobile) {
                hoverCellCurrentBounds.offsetTo(hoverCellOriginalBounds.left + deltaX + totalOffsetX,
                        hoverCellOriginalBounds.top + deltaY + totalOffsetY);
                hoverCell.setBounds(hoverCellCurrentBounds);
                invalidate();

                handleCellSwitch();

                handleMobileCellScroll();
            }
            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 == activePointerId) {
                touchEventsEnded();
            }
            break;
        default:
            break;
    }
}
 
Example 12
Source File: TextureVodActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mTouching = false;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mTouching = true;
            if (event.getPointerCount() == 2) {
                lastSpan = getCurrentSpan(event);
                centerPointX = getFocusX(event);
                centerPointY = getFocusY(event);
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (event.getPointerCount() == 1) {
                float posX = event.getX();
                float posY = event.getY();
                if (lastMoveX == -1 && lastMoveX == -1) {
                    lastMoveX = posX;
                    lastMoveY = posY;
                }
                movedDeltaX = posX - lastMoveX;
                movedDeltaY = posY - lastMoveY;

                if (Math.abs(movedDeltaX) > 5 || Math.abs(movedDeltaY) > 5) {
                    if (mVideoView != null) {
                        mVideoView.moveVideo(movedDeltaX, movedDeltaY);
                    }
                    mTouching = true;
                }
                lastMoveX = posX;
                lastMoveY = posY;
            } else if (event.getPointerCount() == 2) {
                double spans = getCurrentSpan(event);
                if (spans > 5)
                {
                    deltaRatio = (float) (spans / lastSpan);
                    totalRatio = mVideoView.getVideoScaleRatio() * deltaRatio;
                    /*
                    //限定缩放边界,如果视频的宽度小于屏幕的宽度则停止播放
                    if ((rotateNum / 90) %2 != 0){
                        if (totalRatio * mVideoWidth <= mVideoView.getHeight())
                            break;
                    }
                    else {
                        if (totalRatio * mVideoWidth <= mVideoView.getWidth())
                            break;
                    }
                    */
                    if(mVideoView != null){
                        mVideoView.setVideoScaleRatio(totalRatio, centerPointX, centerPointY);
                    }
                    lastSpan = spans;
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            if (event.getPointerCount() == 2) {
                lastMoveX = -1;
                lastMoveY = -1;
            }
            break;
        case MotionEvent.ACTION_UP:
            lastMoveX = -1;
            lastMoveY = -1;

            if (!mTouching){
                dealTouchEvent(v, event);
            }
            break;
        default:
            break;
    }
    return true;
}
 
Example 13
Source File: Joystick.java    From Bugstick with MIT License 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!isEnabled()) return false;

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN: {
            if (detectingDrag || !hasStick()) return false;

            downX = event.getX(0);
            downY = event.getY(0);
            activePointerId = event.getPointerId(0);

            onStartDetectingDrag();
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            if (INVALID_POINTER_ID == activePointerId) break;
            if (detectingDrag && dragExceedsSlop(event)) {
                onDragStart();
                return true;
            }
            break;
        }
        case MotionEvent.ACTION_POINTER_UP: {
            final int pointerIndex = event.getActionIndex();
            final int pointerId = event.getPointerId(pointerIndex);

            if (pointerId != activePointerId)
                break; // if active pointer, fall through and cancel!
        }
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            onTouchEnded();

            onStopDetectingDrag();
            break;
        }
    }

    return false;
}
 
Example 14
Source File: DrawerLayoutContainer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean onTouchEvent(MotionEvent ev)
{
    if (!parentActionBarLayout.checkTransitionAnimation())
    {
        if (drawerOpened && ev != null && ev.getX() > drawerPosition && !startedTracking)
        {
            if (ev.getAction() == MotionEvent.ACTION_UP)
            {
                closeDrawer(false);
            }
            return true;
        }

        if (allowOpenDrawer && parentActionBarLayout.fragmentsStack.size() == 1)
        {
            if (ev != null && (ev.getAction() == MotionEvent.ACTION_DOWN || ev.getAction() == MotionEvent.ACTION_MOVE) && !startedTracking && !maybeStartTracking)
            {
                parentActionBarLayout.getHitRect(rect);
                startedTrackingX = (int) ev.getX();
                startedTrackingY = (int) ev.getY();
                if (rect.contains(startedTrackingX, startedTrackingY))
                {
                    startedTrackingPointerId = ev.getPointerId(0);
                    maybeStartTracking = true;
                    cancelCurrentAnimation();
                    if (velocityTracker != null)
                    {
                        velocityTracker.clear();
                    }
                }
            }
            else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId)
            {
                if (velocityTracker == null)
                {
                    velocityTracker = VelocityTracker.obtain();
                }
                float dx = (int) (ev.getX() - startedTrackingX);
                float dy = Math.abs((int) ev.getY() - startedTrackingY);
                velocityTracker.addMovement(ev);
                if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.2f, true) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.4f, true)))
                {
                    prepareForDrawerOpen(ev);
                    startedTrackingX = (int) ev.getX();
                    requestDisallowInterceptTouchEvent(true);
                }
                else if (startedTracking)
                {
                    if (!beginTrackingSent)
                    {
                        if (((Activity) getContext()).getCurrentFocus() != null)
                        {
                            AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
                        }
                        beginTrackingSent = true;
                    }
                    moveDrawerByX(dx);
                    startedTrackingX = (int) ev.getX();
                }
            }
            else if (ev == null || ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP))
            {
                if (velocityTracker == null)
                {
                    velocityTracker = VelocityTracker.obtain();
                }
                velocityTracker.computeCurrentVelocity(1000);
                if (startedTracking || drawerPosition != 0 && drawerPosition != drawerLayout.getMeasuredWidth())
                {
                    float velX = velocityTracker.getXVelocity();
                    float velY = velocityTracker.getYVelocity();
                    boolean backAnimation = drawerPosition < drawerLayout.getMeasuredWidth() / 2.0f && (velX < 3500 || Math.abs(velX) < Math.abs(velY)) || velX < 0 && Math.abs(velX) >= 3500;
                    if (!backAnimation)
                    {
                        openDrawer(!drawerOpened && Math.abs(velX) >= 3500);
                    }
                    else
                    {
                        closeDrawer(drawerOpened && Math.abs(velX) >= 3500);
                    }
                }
                startedTracking = false;
                maybeStartTracking = false;
                if (velocityTracker != null)
                {
                    velocityTracker.recycle();
                    velocityTracker = null;
                }
            }
        }
        return startedTracking;
    }
    return false;
}
 
Example 15
Source File: TouchImageView.java    From PhotoPicker with Apache License 2.0 4 votes vote down vote up
@Override public boolean onTouch(View v, MotionEvent event) {
  mScaleDetector.onTouchEvent(event);
  mGestureDetector.onTouchEvent(event);
  PointF curr = new PointF(event.getX(), event.getY());

  if (state == State.NONE || state == State.DRAG || state == State.FLING) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        last.set(curr);
        if (fling != null) fling.cancelFling();
        setState(State.DRAG);
        break;

      case MotionEvent.ACTION_MOVE:
        if (state == State.DRAG) {
          float deltaX = curr.x - last.x;
          float deltaY = curr.y - last.y;
          float fixTransX = getFixDragTrans(deltaX, viewWidth, getImageWidth());
          float fixTransY = getFixDragTrans(deltaY, viewHeight, getImageHeight());
          matrix.postTranslate(fixTransX, fixTransY);
          fixTrans();
          last.set(curr.x, curr.y);
        }
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        setState(State.NONE);
        break;
    }
  }

  setImageMatrix(matrix);

  //
  // User-defined OnTouchListener
  //
  if (userTouchListener != null) {
    userTouchListener.onTouch(v, event);
  }

  //
  // OnTouchImageViewListener is set: TouchImageView dragged by user.
  //
  if (touchImageViewListener != null) {
    touchImageViewListener.onMove();
  }

  //
  // indicate event was handled
  //
  return true;
}
 
Example 16
Source File: RotationGestureDetector.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean onTouchEvent(MotionEvent event) {
    if (event.getPointerCount() != 2)
        return false;

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN: {
            sX = event.getX(0);
            sY = event.getY(0);
            fX = event.getX(1);
            fY = event.getY(1);
        }
        break;

        case MotionEvent.ACTION_MOVE: {
            float nfX, nfY, nsX, nsY;
            nsX = event.getX(0);
            nsY = event.getY(0);
            nfX = event.getX(1);
            nfY = event.getY(1);

            angle = angleBetweenLines(fX, fY, sX, sY, nfX, nfY, nsX, nsY);

            if (mListener != null) {
                if (Float.isNaN(startAngle)) {
                    startAngle = angle;
                    mListener.onRotationBegin(this);
                } else {
                    mListener.onRotation(this);
                }
            }
        }
        break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            startAngle = Float.NaN;
        }
        break;

        case MotionEvent.ACTION_POINTER_UP: {
            startAngle = Float.NaN;

            if (mListener != null) {
                mListener.onRotationEnd(this);
            }
        }
        break;
    }
    return true;
}
 
Example 17
Source File: TouchImageView.java    From MarkdownEditors with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    mScaleDetector.onTouchEvent(event);
    mGestureDetector.onTouchEvent(event);
    PointF curr = new PointF(event.getX(), event.getY());

    if (state == State.NONE || state == State.DRAG || state == State.FLING) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                last.set(curr);
                if (fling != null)
                    fling.cancelFling();
                setState(State.DRAG);
                break;

            case MotionEvent.ACTION_MOVE:
                if (state == State.DRAG) {
                    float deltaX = curr.x - last.x;
                    float deltaY = curr.y - last.y;
                    float fixTransX = getFixDragTrans(deltaX, viewWidth, getImageWidth());
                    float fixTransY = getFixDragTrans(deltaY, viewHeight, getImageHeight());
                    matrix.postTranslate(fixTransX, fixTransY);
                    fixTrans();
                    last.set(curr.x, curr.y);
                }
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
                setState(State.NONE);
                break;
        }
    }

    setImageMatrix(matrix);

    //
    // User-defined OnTouchListener
    //
    if (userTouchListener != null) {
        userTouchListener.onTouch(v, event);
    }

    //
    // OnTouchImageViewListener is set: TouchImageView dragged by user.
    //
    if (touchImageViewListener != null) {
        touchImageViewListener.onMove();
    }

    //
    // indicate event was handled
    //
    return true;
}
 
Example 18
Source File: PicViewer.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
 * 触屏监听
 */
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // 主点按下
    case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        prev.set(event.getX(), event.getY());
        mode = DRAG;
        break;
    // 副点按下
    case MotionEvent.ACTION_POINTER_DOWN:
        dist = spacing(event);
        // 如果连续两点距离大于10,则判定为多点模式
        if (spacing(event) > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - prev.x, event.getY()
                    - prev.y);
        } else if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > 10f) {
                matrix.set(savedMatrix);
                float tScale = newDist / dist;
                matrix.postScale(tScale, tScale, mid.x, mid.y);
            }
        }
        break;
    }
    ivViewer.setImageMatrix(matrix);
    CheckView();
    return true;
}
 
Example 19
Source File: TelescopeLayout.java    From telescope with Apache License 2.0 4 votes vote down vote up
@Override public boolean onTouchEvent(MotionEvent event) {
  if (!isEnabled()) {
    return false;
  }

  // Capture all clicks while capturing/saving.
  if (capturing || saving) {
    return true;
  }

  switch (event.getActionMasked()) {
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
      if (pressing) {
        cancel();
      }

      return false;
    case MotionEvent.ACTION_DOWN:
      if (!pressing && event.getPointerCount() == pointerCount) {
        start();
      }
      return true;
    case MotionEvent.ACTION_POINTER_DOWN:
      if (event.getPointerCount() == pointerCount) {
        // There's a few cases where we'll get called called in both onInterceptTouchEvent and
        // here, so make sure we only start once.
        if (!pressing) {
          start();
        }
        return true;
      } else {
        cancel();
      }
      break;
    case MotionEvent.ACTION_MOVE:
      if (pressing) {
        invalidate();
        return true;
      }
      break;
  }

  return super.onTouchEvent(event);
}
 
Example 20
Source File: ItemTouchHelper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent event) {
    mGestureDetector.onTouchEvent(event);
    if (DEBUG) {
        Log.d(TAG,
                "on touch: x:" + mInitialTouchX + ",y:" + mInitialTouchY + ", :" + event);
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(event);
    }
    if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
        return;
    }
    final int action = event.getActionMasked();
    final int activePointerIndex = event.findPointerIndex(mActivePointerId);
    if (activePointerIndex >= 0) {
        checkSelectForSwipe(action, event, activePointerIndex);
    }
    ViewHolder viewHolder = mSelected;
    if (viewHolder == null) {
        return;
    }
    switch (action) {
        case MotionEvent.ACTION_MOVE: {
            // Find the index of the active pointer and fetch its position
            if (activePointerIndex >= 0) {
                updateDxDy(event, mSelectedFlags, activePointerIndex);
                moveIfNecessary(viewHolder);
                mRecyclerView.removeCallbacks(mScrollRunnable);
                mScrollRunnable.run();
                mRecyclerView.invalidate();
            }
            break;
        }
        case MotionEvent.ACTION_CANCEL:
            if (mVelocityTracker != null) {
                mVelocityTracker.clear();
            }
            // fall through
        case MotionEvent.ACTION_UP:
            select(null, ACTION_STATE_IDLE);
            mActivePointerId = ACTIVE_POINTER_ID_NONE;
            break;
        case MotionEvent.ACTION_POINTER_UP: {
            final int pointerIndex = event.getActionIndex();
            final int pointerId = event.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 = event.getPointerId(newPointerIndex);
                updateDxDy(event, mSelectedFlags, pointerIndex);
            }
            break;
        }
    }
}