Example #1
0
 public boolean onScale(ScaleGestureDetector detector) {
   mScale *= detector.getScaleFactor();
   mFocusX = detector.getFocusX();
   mFocusY = detector.getFocusY();
   invalidate();
   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;
    }
Example #3
0
 @Override
 public boolean onTouchEvent(@NonNull MotionEvent ev) {
   stopAnimationsOnTouch = true;
   mScaleDetector.onTouchEvent(ev);
   if (!mScaleDetector.isInProgress()) mGestureDetector.onTouchEvent(ev);
   return true;
 }
  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;
  }
Example #5
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;
  }
    @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;
    }
Example #7
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   float xScale = ((float) detector.getCurrentSpanX()) / detector.getPreviousSpanX();
   yAmplifier *= (((float) detector.getCurrentSpanY()) / detector.getPreviousSpanY());
   yAmplifier = Math.max(Math.min(yAmplifier, MAX_YAMP), MIN_YAMP);
   shownDataAmount /= xScale;
   shownDataAmount = Math.min(Math.max(1, (shownDataAmount)), MAXSAMPLEPACKETS);
   return true;
 }
Example #8
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;
  }
Example #9
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   Log.i(TAG, "onScale " + detector.getScaleFactor());
   mSampleSize *= detector.getScaleFactor();
   if (mSampleSize < 0.2f) {
     mSampleSize = 0.2f;
   }
   setFigureSize(mSampleSize);
   Log.i(TAG, "samplesize = " + mSampleSize);
   invalidate();
   return true;
 }
Example #10
0
 @Override
 public boolean onScaleBegin(ScaleGestureDetector detector) {
   Logger.i(
       TAG,
       "onScaleBegin: "
           + detector.getFocusX()
           + "x"
           + detector.getFocusY()
           + " "
           + detector.getScaleFactor());
   return true;
 }
Example #11
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;
    }
    @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;
    }
Example #13
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;
    }
  @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;
  }
Example #15
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;
 }
Example #16
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;
  }
Example #18
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   // TODO Auto-generated method stub
   if (mScaleView == null) {
     mScaleFactor *= detector.getScaleFactor();
     mScaleFactor = adjustScale(mScaleFactor);
     invalidate();
     requestLayout();
   } else {
     LayoutParams param = (LayoutParams) mScaleView.getLayoutParams();
     param.fScale *= detector.getScaleFactor();
     updateViewLayout(mScaleView, param);
   }
   return true;
 }
Example #19
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;
 }
Example #20
0
 @Override
 protected void onZoom(float scale) {
   super.onZoom(scale);
   if (mScaleDetector != null) {
     if (!mScaleDetector.isInProgress()) mCurrentScaleFactor = scale;
   }
 }
Example #21
0
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   scaleFactor *= detector.getScaleFactor();
   scaleFactor = Math.max(MIN_ZOOM, Math.min(scaleFactor, MAX_ZOOM));
   Log.e("Player", "onScale " + scaleFactor);
   return true;
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // Avoid short-circuit logic evaluation - ensure all gesture detectors see all events so
    // that they generate correct notifications.
    boolean handled = mScroller.onTouchEvent(event);
    handled |= mZoomer.onTouchEvent(event);
    handled |= mTapDetector.onTouchEvent(event);
    mSwipePinchDetector.onTouchEvent(event);

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mViewer.setAnimationEnabled(false);
        mSuppressCursorMovement = false;
        mSuppressFling = false;
        mSwipeCompleted = false;
        break;

      case MotionEvent.ACTION_POINTER_DOWN:
        mTotalMotionY = 0;
        break;

      case MotionEvent.ACTION_UP:
        releaseAnyHeldButton();
        break;

      default:
        break;
    }
    return handled;
  }
 public void onTouchEvent(MotionEvent event) {
   mGestureDetector.onTouchEvent(event);
   mScaleDetector.onTouchEvent(event);
   if (event.getAction() == MotionEvent.ACTION_UP) {
     mListener.onUp(event.getX(), event.getY());
   }
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    mScaleGestureDetector.onTouchEvent(event);

    if (!mScaling) mGestureDetector.onTouchEvent(event);

    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
      mUserInteracting = true;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
      mScrollDisabled = false;
      mUserInteracting = false;

      View v = mChildViews.get(mCurrent);
      if (v != null) {
        if (mScroller.isFinished()) {
          // If, at the end of user interaction, there is no
          // current inertial scroll in operation then animate
          // the view onto screen if necessary
          slideViewOntoScreen(v);
        }

        if (mScroller.isFinished()) {
          // If still there is no inertial scroll in operation
          // then the layout is stable
          postSettle(v);
        }
      }
    }

    requestLayout();
    return true;
  }
 @Override
 public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
   float spanX =
       scaleGestureDetector.getCurrentSpanX() - scaleGestureDetector.getPreviousSpanX();
   float spanY =
       scaleGestureDetector.getCurrentSpanY() - scaleGestureDetector.getPreviousSpanY();
   LayoutParams lParams = (LayoutParams) getLayoutParams();
   float newWidth = lParams.width + spanX;
   float newHeight = lParams.height + spanY;
   lParams.width = (int) newWidth;
   lParams.height = (int) newHeight;
   setLayoutParams(lParams);
   Log.i("spanX", spanX + "");
   Log.i("spanY", spanY + "");
   return true;
 }
 @Override
 public void onScaleEnd(ScaleGestureDetector detector) {
   controls.pOnPinchZoomGestureDetected(
       PasObj, detector.getScaleFactor(), 2); // scalefactor->float
   // Log.i("tag", "onScaleEnd");
   super.onScaleEnd(detector);
 }
 @Override
 public boolean onScaleBegin(ScaleGestureDetector detector) {
   controls.pOnPinchZoomGestureDetected(
       PasObj, detector.getScaleFactor(), 0); // scalefactor->float
   // Log.i("tag", "onScaleBegin");
   return true;
 }
  @Override
  public boolean onTouchEvent(MotionEvent e) {
    boolean b = scaleGestureDetector.onTouchEvent(e);

    boolean c = gestureDetector.onTouchEvent(e);

    return b || c || super.onTouchEvent(e);
  }
 @Override
 public boolean onScale(ScaleGestureDetector detector) {
   mScaleFactor *= detector.getScaleFactor();
   mScaleFactor = Math.max(MIN_ZOOM, Math.min(mScaleFactor, MAX_ZOOM));
   // Log.i("tag", "onScale = "+ mScaleFactor);
   controls.pOnPinchZoomGestureDetected(PasObj, mScaleFactor, 1); // scalefactor->float
   return true;
 }
 @Override
 public void onScaleEnd(ScaleGestureDetector detector) {
   if (detector.getScaleFactor() < 1f) {
     bus.post(Pinch.INSTANCE);
   } else {
     bus.post(Zoom.INSTANCE);
   }
 }