예제 #1
0
    @Override
    public boolean onScale(ScaleGestureDetector detector) {

      // calc scale factor
      scaleFactor *= detector.getScaleFactor();
      scaleFactor =
          Math.max(
              SessionView.MIN_SCALE_FACTOR, Math.min(scaleFactor, SessionView.MAX_SCALE_FACTOR));
      sessionView.setZoom(scaleFactor);

      if (!sessionView.isAtMinZoom() && !sessionView.isAtMaxZoom()) {
        // transform scroll origin to the new zoom space
        float transOriginX = scrollView.getScrollX() * detector.getScaleFactor();
        float transOriginY = scrollView.getScrollY() * detector.getScaleFactor();

        // transform center point to the zoomed space
        float transCenterX =
            (scrollView.getScrollX() + detector.getFocusX()) * detector.getScaleFactor();
        float transCenterY =
            (scrollView.getScrollY() + detector.getFocusY()) * detector.getScaleFactor();

        // scroll by the difference between the distance of the transformed center/origin point and
        // their old distance (focusX/Y)
        scrollView.scrollBy(
            (int) ((transCenterX - transOriginX) - detector.getFocusX()),
            (int) ((transCenterY - transOriginY) - detector.getFocusY()));
      }

      return true;
    }
예제 #2
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   if (ignoreDetectorEvents()) return false;
   // It is possible that pinchBegin() was never called when we reach here.
   // This happens when webkit handles the 2nd touch down event. That causes
   // ContentView to ignore the onScaleBegin() call. And if webkit does not
   // handle the touch move events afterwards, we will face a situation
   // that pinchBy() is called without any pinchBegin().
   // To solve this problem, we call pinchBegin() here if it is never called.
   if (!mPinchEventSent) {
     mContentViewCore
         .getContentViewGestureHandler()
         .pinchBegin(
             detector.getEventTime(), (int) detector.getFocusX(), (int) detector.getFocusY());
     mPinchEventSent = true;
   }
   mContentViewCore
       .getContentViewGestureHandler()
       .pinchBy(
           detector.getEventTime(),
           (int) detector.getFocusX(),
           (int) detector.getFocusY(),
           detector.getScaleFactor());
   return true;
 }
    @Override
    public boolean onScale(ScaleGestureDetector detector) {

      float mScaleFactor = detector.getScaleFactor();

      float origScale = saveScale;

      saveScale *= mScaleFactor;

      if (saveScale > maxScale) {

        saveScale = maxScale;

        mScaleFactor = maxScale / origScale;

      } else if (saveScale < minScale) {

        saveScale = minScale;

        mScaleFactor = minScale / origScale;
      }

      if (origWidth * saveScale <= viewWidth || origHeight * saveScale <= viewHeight)
        matrix.postScale(mScaleFactor, mScaleFactor, viewWidth / 2, viewHeight / 2);
      else matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());

      fixTrans();

      return true;
    }
예제 #4
0
 public boolean onScale(ScaleGestureDetector detector) {
   mScale *= detector.getScaleFactor();
   mFocusX = detector.getFocusX();
   mFocusY = detector.getFocusY();
   invalidate();
   return true;
 }
예제 #5
0
  public boolean onScale(ScaleGestureDetector detector) {
    float previousScale = mScale;
    float scale_factor = mReflow ? REFLOW_SCALE_FACTOR : 1.0f;
    float min_scale = MIN_SCALE * scale_factor;
    float max_scale = MAX_SCALE * scale_factor;
    mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), min_scale), max_scale);

    if (mReflow) {
      applyToChildren(
          new ViewMapper() {
            @Override
            void applyToView(View view) {
              onScaleChild(view, mScale);
            }
          });
    } else {
      float factor = mScale / previousScale;

      View v = mChildViews.get(mCurrent);
      if (v != null) {
        // Work out the focus point relative to the view top left
        int viewFocusX = (int) detector.getFocusX() - (v.getLeft() + mXScroll);
        int viewFocusY = (int) detector.getFocusY() - (v.getTop() + mYScroll);
        // Scroll to maintain the focus point
        mXScroll += viewFocusX - viewFocusX * factor;
        mYScroll += viewFocusY - viewFocusY * factor;
        requestLayout();
      }
    }
    return true;
  }
    @Override
    public boolean onScale(ScaleGestureDetector detector) {

      float mScaleFactor = mImageViewBase.getScaleFactor();
      float oldScaleFactor = mScaleFactor;
      mScaleFactor *= detector.getScaleFactor();

      // Don't let the object get too small or too large.
      float minValue =
          Math.min(
              (((float) mImageViewBase.getFrameWidth()) / mImageViewBase.getImageWidth()),
              (((float) mImageViewBase.getFrameHeigth()) / mImageViewBase.getImageHeight()));
      mScaleFactor = Math.max(minValue, Math.min(mScaleFactor, 10.0f));
      mImageViewBase.setScaleFactor(mScaleFactor);

      // let the old center remain on the center
      int xPos = mImageViewBase.getImageXPosition();
      int yPos = mImageViewBase.getImageYPosition();

      float focusX = detector.getFocusX() / oldScaleFactor - xPos;
      float focusY = detector.getFocusY() / oldScaleFactor - yPos;

      xPos = (int) ((oldScaleFactor / mScaleFactor) * (focusX + xPos) - focusX);
      yPos = (int) ((oldScaleFactor / mScaleFactor) * (focusY + yPos) - focusY);

      // check if we meet border
      xPos = checkBordersX(mScaleFactor, xPos);
      yPos = checkBordersY(mScaleFactor, yPos);

      mImageViewBase.setImageXPosition(xPos);
      mImageViewBase.setImageYPosition(yPos);

      return true;
    }
예제 #7
0
  public boolean onScale(ScaleGestureDetector detector) {
    // the velocity of the pinch in scale factor per ms
    float velocity =
        (detector.getCurrentSpan() - detector.getPreviousSpan()) / detector.getTimeDelta();
    float currentSpan = detector.getCurrentSpanX();
    float prevSpan = detector.getPreviousSpanX();

    double diff = Math.abs(currentSpan - prevSpan);

    /*
     * If Shove is in progress do not handle scale
     * If previous scale is handled then keep on handling scale
     * else give some buffer for shove to be processed
     */
    if (mDoubleTapScale
        || mScaleHandled
        || (!mShoveHandled
            && diff
                > PINCH_THRESHOLD
                    * Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels))) {
      mScaleHandled = true;
      float focusX = mDoubleTapScale ? mapView.getWidth() * 0.5f : detector.getFocusX();
      float focusY = mDoubleTapScale ? mapView.getHeight() * 0.5f : detector.getFocusY();
      mLastDoubleGestureTime = detector.getEventTime();
      handlePinchGesture(focusX, focusY, detector.getScaleFactor(), velocity);
      return true;
    }
    mScaleHandled = false;
    return false;
  }
예제 #8
0
  @Override
  public boolean onScale(ScaleGestureDetector detector) {
    Logger.i(
        TAG,
        "onScale: "
            + detector.getFocusX()
            + "x"
            + detector.getFocusY()
            + " "
            + detector.getScaleFactor());
    float scale = detector.getScaleFactor();

    if (mVisibleGrid == GRID_SMALL && scale > 1 && scale < 1.33) {
      mSmallRecView.setScaleX(scale);
      mSmallRecView.setScaleY(scale);

      float alpha = (1.33f - scale) / 0.33f;
      mSmallRecView.setAlpha(alpha);
      mBigRecView.setAlpha(1 - alpha);
    } else if (mVisibleGrid == GRID_BIG && scale < 1 && scale > 0.75) {
      mBigRecView.setScaleX(scale);
      mBigRecView.setScaleY(scale);

      float alpha = (scale - 0.75f) / 0.25f;
      mSmallRecView.setAlpha(1 - alpha);
      mBigRecView.setAlpha(alpha);
    }
    return false;
  }
예제 #9
0
 @Override
 public boolean onScaleBegin(ScaleGestureDetector detector) {
   Logger.i(
       TAG,
       "onScaleBegin: "
           + detector.getFocusX()
           + "x"
           + detector.getFocusY()
           + " "
           + detector.getScaleFactor());
   return true;
 }
예제 #10
0
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
      scaleImage(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY(), true);

      //
      // OnTouchImageViewListener is set: TouchImageView pinch zoomed by user.
      //
      if (touchImageViewListener != null) {
        touchImageViewListener.onMove();
      }
      return true;
    }
예제 #11
0
  @Override
  public boolean onScale(ScaleGestureDetector detector) {
    float scaleFactor = detector.getScaleFactor();

    this.m.setZoomOffsetX((int) detector.getFocusX());
    this.m.setZoomOffsetY((int) detector.getFocusY());

    double relPosX = this.v.toAbsoluteX(this.m.getZoomOffsetX());
    double relPosY = this.v.toAbsoluteY(this.m.getZoomOffsetY());
    this.m.updateZoomLevel(scaleFactor, v.getWidth(), v.getHeight(), relPosX, relPosY);

    // return super.onScale(detector);
    return true;
  }
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
      float scale = getScale();
      float scaleFactor = detector.getScaleFactor();

      if ((getDrawable() != null)
          && (!(((scale >= maxScale) && (scaleFactor > 1f))
              || ((scale <= 0.75) && (scaleFactor < 1f))))) {
        suppMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
        checkAndDisplayMatrix();
      }

      return true;
    }
예제 #13
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   float oldScaleFactor = getCanvasCamera().getScale();
   float scaleFactor = oldScaleFactor * detector.getScaleFactor();
   scaleFactor = Math.max(MIN_ZOOM, Math.min(scaleFactor, MAX_ZOOM));
   if (scaleFactor != oldScaleFactor) {
     float scaleDifference = scaleFactor / oldScaleFactor;
     float zoomTranslationX = (1 - scaleDifference) * detector.getFocusX() / scaleFactor;
     float zoomTranslationY = (1 - scaleDifference) * detector.getFocusY() / scaleFactor;
     getCanvasCamera()
         .setScaleAndRelativeTranslate(scaleFactor, zoomTranslationX, zoomTranslationY);
     invalidate();
   }
   return true;
 }
  private boolean judgePinch(ScaleGestureDetector detector) {
    boolean res = false;
    float curDist = detector.getCurrentSpan();
    float preDist = detector.getPreviousSpan();
    pinch = preDist - curDist;
    if ((curDist < preDist) && (pinch > PINCH_THRESHOLD)) {
      res = true;
      gestureName = GESTURE_PINCH;
      focus_x = detector.getFocusX();
      focus_y = detector.getFocusY();

      gestureLabel.setText(gestureName + "\n x:" + focus_x + " y:" + focus_y + "\npinch:" + pinch);
    }
    return res;
  }
예제 #15
0
 @SuppressWarnings("unused")
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   float span = detector.getCurrentSpan() - detector.getPreviousSpan();
   float targetScale = mCurrentScaleFactor * detector.getScaleFactor();
   if (mScaleEnabled) {
     targetScale = Math.min(getMaxZoom(), Math.max(targetScale, MIN_ZOOM));
     zoomTo(targetScale, detector.getFocusX(), detector.getFocusY());
     mCurrentScaleFactor = Math.min(getMaxZoom(), Math.max(targetScale, MIN_ZOOM));
     mDoubleTapDirection = 1;
     invalidate();
     return true;
   }
   return false;
 }
예제 #16
0
 @Override
 public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
   float x = scaleGestureDetector.getFocusX();
   float y = scaleGestureDetector.getFocusY();
   int index = getActiveIndexByXY(x, y);
   if (index >= 0) {
     mActiveIndex = index;
     mScaleFactor = 1.f;
     Figure f = mFigures.get(mActiveIndex);
     origX = f.x;
     origY = f.y;
     origWidth = f.width;
     origHeight = f.height;
     return true;
   }
   return false;
 }
    /** Called when the user is in the process of pinch-zooming. */
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
      if (!mSwipePinchDetector.isPinching()) {
        return false;
      }

      if (Math.abs(detector.getScaleFactor() - 1) < MIN_ZOOM_DELTA) {
        return false;
      }

      float scaleFactor = detector.getScaleFactor();
      synchronized (mRenderData) {
        mRenderData.transform.postScale(
            scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
      }
      repositionImageWithZoom();
      return true;
    }
예제 #18
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   float mScaleFactor = (float) Math.min(Math.max(.95f, detector.getScaleFactor()), 1.05);
   float origScale = saveScale;
   saveScale *= mScaleFactor;
   if (saveScale > maxScale) {
     saveScale = maxScale;
     mScaleFactor = maxScale / origScale;
   } else if (saveScale < minScale) {
     saveScale = minScale;
     mScaleFactor = minScale / origScale;
   }
   right = width * saveScale - width - (2 * redundantXSpace * saveScale);
   bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
   if (origWidth * saveScale <= width || origHeight * saveScale <= height) {
     matrix.postScale(mScaleFactor, mScaleFactor, width / 2, height / 2);
     if (mScaleFactor < 1) {
       matrix.getValues(m);
       float x = m[Matrix.MTRANS_X];
       float y = m[Matrix.MTRANS_Y];
       if (mScaleFactor < 1) {
         if (Math.round(origWidth * saveScale) < width) {
           if (y < -bottom) matrix.postTranslate(0, -(y + bottom));
           else if (y > 0) matrix.postTranslate(0, -y);
         } else {
           if (x < -right) matrix.postTranslate(-(x + right), 0);
           else if (x > 0) matrix.postTranslate(-x, 0);
         }
       }
     }
   } else {
     matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());
     matrix.getValues(m);
     float x = m[Matrix.MTRANS_X];
     float y = m[Matrix.MTRANS_Y];
     if (mScaleFactor < 1) {
       if (x < -right) matrix.postTranslate(-(x + right), 0);
       else if (x > 0) matrix.postTranslate(-x, 0);
       if (y < -bottom) matrix.postTranslate(0, -(y + bottom));
       else if (y > 0) matrix.postTranslate(0, -y);
     }
   }
   return true;
 }
  @Override
  public boolean onScale(ScaleGestureDetector detector) {
    Log.i(TAG, "onScale");

    float previousScale = mScale;
    mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE);
    float factor = mScale / previousScale;

    View v = mChildViews.get(mCurrent);
    if (v != null) {
      // Work out the focus point relative to the view top left
      int viewFocusX = (int) detector.getFocusX() - (v.getLeft() + mXScroll);
      int viewFocusY = (int) detector.getFocusY() - (v.getTop() + mYScroll);
      // Scroll to maintain the focus point
      mXScroll += viewFocusX - viewFocusX * factor;
      mYScroll += viewFocusY - viewFocusY * factor;
      requestLayout();
    }
    return true;
  }
예제 #20
0
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
      float mScaleFactor = detector.getScaleFactor();
      float origScale = mSaveScale;
      mSaveScale *= mScaleFactor;
      if (mSaveScale > mMaxScale) {
        mSaveScale = mMaxScale;
        mScaleFactor = mMaxScale / origScale;
      } else if (mSaveScale < mMinScale) {
        mSaveScale = mMinScale;
        mScaleFactor = mMinScale / origScale;
      }

      if (mOrigWidth * mSaveScale <= mViewWidth || mOrigHeight * mSaveScale <= mViewHeight)
        mMatrix.postScale(mScaleFactor, mScaleFactor, mViewWidth / 2, mViewHeight / 2);
      else
        mMatrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());

      fixTrans();
      return true;
    }
  //// TODO: 16/12/15 Still get better method to judge the rotate gesture
  private boolean judgeRotate(ScaleGestureDetector detector) {
    boolean res = false;

    double preDistX = detector.getPreviousSpanX();
    double preDistY = detector.getPreviousSpanY();
    double curDistX = detector.getCurrentSpanX();
    double curDistY = detector.getCurrentSpanY();

    double atanPre = Math.atan2(preDistY, preDistX);
    double atanCur = Math.atan2(curDistY, curDistX);
    rotate = atanCur - atanPre;

    if (Math.abs(rotate) > ROTATE_THRESHOLD) {
      res = true;
      gestureName = GESTURE_ROTATE;
      focus_x = detector.getFocusX();
      focus_y = detector.getFocusY();
      gestureLabel.setText(
          gestureName + "\n x:" + focus_x + " y:" + focus_y + "\ndeltaAngel:" + rotate);
    }
    return res;
  }
  @SuppressLint("NewApi")
  @Override
  public boolean onScale(ScaleGestureDetector detector) {
    float scale = getScale();
    float scaleFactor = detector.getScaleFactor();

    if (getDrawable() == null) return true;

    /** 缩放的范围控制 */
    if ((scale < SCALE_MAX && scaleFactor > 1.0f) || (scale > initScale && scaleFactor < 1.0f)) {
      /** 最大值最小值判断 */
      if (scaleFactor * scale < initScale) {
        scaleFactor = initScale / scale;
      }
      if (scaleFactor * scale > SCALE_MAX) {
        scaleFactor = SCALE_MAX / scale;
      }
      /** 设置缩放比例 */
      mScaleMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
      checkBorderAndCenterWhenScale();
      setImageMatrix(mScaleMatrix);
    }
    return true;
  }
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   mListener.onScale(
       detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
   return true;
 }
 @Override
 public boolean onScaleBegin(ScaleGestureDetector detector) {
   return mListener.onScaleBegin(detector.getFocusX(), detector.getFocusY());
 }
예제 #25
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   PostScale(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
   return false;
 }
예제 #26
0
 public boolean onScale(ScaleGestureDetector paramScaleGestureDetector) {
   float f = paramScaleGestureDetector.getScaleFactor() * this.aAK.getScale();
   this.aAK.a(f, paramScaleGestureDetector.getFocusX(), paramScaleGestureDetector.getFocusY());
   return true;
 }