Beispiel #1
0
 @Override
 protected void onZoom(float scale) {
   super.onZoom(scale);
   if (mScaleDetector != null) {
     if (!mScaleDetector.isInProgress()) mCurrentScaleFactor = scale;
   }
 }
Beispiel #2
0
 @Override
 public boolean onTouchEvent(@NonNull MotionEvent ev) {
   stopAnimationsOnTouch = true;
   mScaleDetector.onTouchEvent(ev);
   if (!mScaleDetector.isInProgress()) mGestureDetector.onTouchEvent(ev);
   return true;
 }
Beispiel #3
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   mScaleDetector.onTouchEvent(event);
   if (!mScaleDetector.isInProgress()) mGestureDetector.onTouchEvent(event);
   int action = event.getAction();
   switch (action & MotionEvent.ACTION_MASK) {
     case MotionEvent.ACTION_UP:
       if (getScale() < 1f) {
         zoomTo(1f, 50);
       }
       break;
   }
   return true;
 }
 @Override
 public boolean isScaling() {
   return mDetector.isInProgress();
 }
Beispiel #5
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (mScaleDetector != null) {
     mScaleDetector.onTouchEvent(event);
     if (!mScaleDetector.isInProgress()) {
       if (mGestureDetector != null) {
         mGestureDetector.onTouchEvent(event);
       }
     }
   }
   float x = event.getX();
   float y = event.getY();
   int action = event.getAction();
   switch (action & MotionEvent.ACTION_MASK) {
     case MotionEvent.ACTION_DOWN:
       if (INNER_RECT) {
         if (circleContain(x, y, mBitmapRectPoints[0], mBitmapRectPoints[1], mRadius, mRadius)) {
           mDragPoint.set(mBitmapRectPoints[0], mBitmapRectPoints[1]);
         } else if (circleContain(
             x, y, mBitmapRectPoints[2], mBitmapRectPoints[3], mRadius, mRadius)) {
           mDragPoint.set(mBitmapRectPoints[2], mBitmapRectPoints[3]);
         } else if (circleContain(
             x, y, mBitmapRectPoints[4], mBitmapRectPoints[5], mRadius, mRadius)) {
           mDragPoint.set(mBitmapRectPoints[4], mBitmapRectPoints[5]);
         } else if (circleContain(
             x, y, mBitmapRectPoints[6], mBitmapRectPoints[7], mRadius, mRadius)) {
           mDragPoint.set(mBitmapRectPoints[6], mBitmapRectPoints[7]);
         } else {
           break;
         }
       } else {
         if (circleContain(x, y, mMarginRectF.left, mMarginRectF.top, mRadius, mRadius)) {
           mDragPoint.set(mMarginRectF.left, mMarginRectF.top);
         } else if (circleContain(x, y, mMarginRectF.right, mMarginRectF.top, mRadius, mRadius)) {
           mDragPoint.set(mMarginRectF.right, mMarginRectF.top);
         } else if (circleContain(
             x, y, mMarginRectF.left, mMarginRectF.bottom, mRadius, mRadius)) {
           mDragPoint.set(mMarginRectF.left, mMarginRectF.bottom);
         } else if (circleContain(
             x, y, mMarginRectF.right, mMarginRectF.bottom, mRadius, mRadius)) {
           mDragPoint.set(mMarginRectF.right, mMarginRectF.bottom);
         } else {
           break;
         }
       }
       postInvalidate();
       break;
     case MotionEvent.ACTION_MOVE:
       if (mDragPoint.x == INVALID_POINT && mDragPoint.y == INVALID_POINT) {
         break;
       }
       float scale = Float.NEGATIVE_INFINITY;
       float newSpanX = 0;
       float newSpanY = 0;
       float oldSpanX = 0;
       float oldSpanY = 0;
       float scaleX = 0;
       float scaleY = 0;
       if (INNER_RECT) {
         if (circleContain(
             mDragPoint.x,
             mDragPoint.y,
             mMarginRectF.left,
             mMarginRectF.top,
             mMarginRectF.centerX(),
             mMarginRectF.centerY())) {
           newSpanX = mMarginRectF.centerX() - x;
           newSpanY = mMarginRectF.centerY() - y;
           oldSpanX = mMarginRectF.centerX() - mDragPoint.x;
           oldSpanY = mMarginRectF.centerY() - mDragPoint.y;
         } else if (circleContain(
             mDragPoint.x,
             mDragPoint.y,
             mMarginRectF.left,
             mMarginRectF.bottom,
             mMarginRectF.centerX(),
             mMarginRectF.centerY())) {
           newSpanX = mMarginRectF.centerX() - x;
           newSpanY = y - mMarginRectF.centerY();
           oldSpanX = mMarginRectF.centerX() - mDragPoint.x;
           oldSpanY = mDragPoint.y - mMarginRectF.centerY();
         } else if (circleContain(
             mDragPoint.x,
             mDragPoint.y,
             mMarginRectF.right,
             mMarginRectF.top,
             mMarginRectF.centerX(),
             mMarginRectF.centerY())) {
           newSpanX = x - mMarginRectF.centerX();
           newSpanY = mMarginRectF.centerY() - y;
           oldSpanX = mDragPoint.x - mMarginRectF.centerX();
           oldSpanY = mMarginRectF.centerY() - mDragPoint.y;
         } else {
           newSpanX = x - mMarginRectF.centerX();
           newSpanY = y - mMarginRectF.centerY();
           oldSpanX = mDragPoint.x - mMarginRectF.centerX();
           oldSpanY = mDragPoint.y - mMarginRectF.centerY();
         }
       } else {
         if (mDragPoint.x == mMarginRectF.left) {
           if (mDragPoint.y == mMarginRectF.top) {
             newSpanX = mMarginRectF.centerX() - x;
             newSpanY = mMarginRectF.centerY() - y;
             oldSpanX = mMarginRectF.centerX() - mMarginRectF.left;
             oldSpanY = mMarginRectF.centerY() - mMarginRectF.top;
           } else {
             newSpanX = mMarginRectF.centerX() - x;
             newSpanY = y - mMarginRectF.centerY();
             oldSpanX = mMarginRectF.centerX() - mMarginRectF.left;
             oldSpanY = mMarginRectF.bottom - mMarginRectF.centerY();
           }
         } else {
           if (mDragPoint.y == mMarginRectF.top) {
             newSpanX = x - mMarginRectF.centerX();
             newSpanY = mMarginRectF.centerY() - y;
             oldSpanX = mMarginRectF.right - mMarginRectF.centerX();
             oldSpanY = mMarginRectF.centerY() - mMarginRectF.top;
           } else {
             newSpanX = x - mMarginRectF.centerX();
             newSpanY = y - mMarginRectF.centerY();
             oldSpanX = mMarginRectF.right - mMarginRectF.centerX();
             oldSpanY = mMarginRectF.bottom - mMarginRectF.centerY();
           }
         }
       }
       scaleX = newSpanX / oldSpanX;
       scaleY = newSpanY / oldSpanY;
       scale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
       if (INNER_RECT) {
         float radius =
             computeRadius(
                 x, y, mDragPoint.x, mDragPoint.y, mMarginRectF.centerX(), mMarginRectF.centerY());
         postScaleWithRadius(scale, radius, mMarginRectF.centerX(), mMarginRectF.centerY());
       } else {
         postScale(scale, mMarginRectF.centerX(), mMarginRectF.centerY());
       }
       break;
     case MotionEvent.ACTION_UP:
       if (getScale() < 1f) {
         zoomTo(1f, 50);
       }
     default:
       mDragPoint.set(INVALID_POINT, INVALID_POINT);
       postInvalidate();
       break;
   }
   return true;
 }
Beispiel #6
0
 boolean isScaleGestureDetectionInProgress() {
   return isMultiTouchZoomSupported() && mMultiTouchDetector.isInProgress();
 }
Beispiel #7
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    // Let the ScaleGestureDetector inspect all events.
    mScaleDetector.onTouchEvent(ev);

    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        {
          final float x = ev.getX();
          final float y = ev.getY();

          mLastTouchX = x;
          mLastTouchY = y;
          mActivePointerId = ev.getPointerId(0);
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = ev.findPointerIndex(mActivePointerId);
          final float x = ev.getX(pointerIndex);
          final float y = ev.getY(pointerIndex);

          // Only move if the ScaleGestureDetector isn't processing a gesture.
          if (!mScaleDetector.isInProgress()) {
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;

            mPosX += dx;
            mPosY += dy;

            invalidate();
          }

          mLastTouchX = x;
          mLastTouchY = y;

          break;
        }

      case MotionEvent.ACTION_UP:
        {
          mActivePointerId = INVALID_POINTER_ID;
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          mActivePointerId = INVALID_POINTER_ID;
          break;
        }

      case MotionEvent.ACTION_POINTER_UP:
        {
          final int pointerIndex =
              (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
                  >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
          final int pointerId = ev.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;
            mLastTouchX = ev.getX(newPointerIndex);
            mLastTouchY = ev.getY(newPointerIndex);
            mActivePointerId = ev.getPointerId(newPointerIndex);
          }
          break;
        }
    }

    return true;
  }
  @Override
  public boolean handleTouchEvent(MotionEvent ev, float scaleFactor, int xPos, int yPos) {

    mScaleDetector.onTouchEvent(ev);
    mGestureDetector.onTouchEvent(ev);

    final int action = ev.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          final float x = ev.getX();
          final float y = ev.getY();

          // Remember where we started
          mLastTouchX = x;
          mLastTouchY = y;
          mActivePointerId = ev.getPointerId(0);

          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = ev.findPointerIndex(mActivePointerId);

          if (pointerIndex < 0) return false;

          final float x = ev.getX(pointerIndex);
          final float y = ev.getY(pointerIndex);

          if (!mScaleDetector.isInProgress()) {
            // Calculate the distance moved
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;

            // Move the object
            pan(dx, dy, scaleFactor, xPos, yPos);

            // Remember this touch position for the next move event
            mLastTouchX = x;
            mLastTouchY = y;
          }
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          mActivePointerId = INVALID_POINTER_ID;
          break;
        }
      case MotionEvent.ACTION_CANCEL:
        {
          mActivePointerId = INVALID_POINTER_ID;
          break;
        }
      case MotionEvent.ACTION_POINTER_UP:
        {
          // Extract the index of the pointer that left the touch sensor
          final int pointerIndex =
              (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
                  >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
          final int pointerId = ev.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;
            mLastTouchX = ev.getX(newPointerIndex);
            mLastTouchY = ev.getY(newPointerIndex);
            mActivePointerId = ev.getPointerId(newPointerIndex);
          }
          break;
        }
    } // and switch statement
    return true;
  }
 public boolean isScaling() {
   return scaleGestureDetector.isInProgress();
 }