示例#1
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;
  }
示例#2
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;
 }
  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;
  }