예제 #1
0
  /** Handles reset button click. */
  private void onZoomResetButtonClick() {
    // resets image view scale and translation and makes it fit in screen's center
    mPinchToZoomTransformation.reset();
    updateImageView();

    updateZoomTextViewText();

    scaleTv(0, mImageViewWidth / 2.0f, mImageViewHeight / 2.0f);
  }
예제 #2
0
  /** Updates application UI and image on TV according to scale values. */
  private float getCurrentScale() {
    RectF imageRect = mPinchToZoomTransformation.getRect();

    float imageViewRatio = (float) mImageViewWidth / mImageViewHeight;
    float imageRatio = imageRect.width() / imageRect.height();

    return imageViewRatio < imageRatio
        ? imageRect.width() / mImageViewWidth
        : imageRect.height() / mImageViewHeight;
  }
예제 #3
0
  /**
   * Initializes mPinchToZoomTransformation.
   *
   * <p>After initialization subsequent calls will be ignored.
   *
   * <p>Must be called after Android finished layout measurements and after drawable was set on
   * ImageView.
   */
  private void initialize() {
    if (mPinchToZoomTransformation == null
        && mImageView != null
        && mImageView.getDrawable() != null) {
      int imageWidth = mImageView.getDrawable().getIntrinsicWidth();
      int imageHeight = mImageView.getDrawable().getIntrinsicHeight();
      mImageViewWidth = mImageView.getMeasuredWidth();
      mImageViewHeight = mImageView.getMeasuredHeight();

      mPinchToZoomTransformation =
          new PinchToZoomTransformation(imageWidth, imageHeight, mImageViewWidth, mImageViewHeight);
      mPinchToZoomTransformation.setMaxScale(5);

      mImageView.setScaleType(ImageView.ScaleType.MATRIX);
      mPinchToZoomTransformation.setScaleToFitInCenter();

      updateImageView();
    }
  }
예제 #4
0
  /** Updates application UI and image on TV according to rotation values. */
  private void updateUiAndTvRotation(RotationDirection rotationDirection) {
    PinchToZoomTransformation.RotationDirection pinchToZoomRotationDirection =
        rotationDirection == RotationDirection.CLOCKWISE
            ? PinchToZoomTransformation.RotationDirection.CLOCKWISE
            : PinchToZoomTransformation.RotationDirection.COUNTER_CLOCKWISE;

    mPinchToZoomTransformation.updateRotationAndFitInBounds(pinchToZoomRotationDirection);

    updateImageView();

    scaleTv(0, mImageViewWidth / 2.0f, mImageViewHeight / 2.0f);

    updateZoomTextViewText();
  }
예제 #5
0
  /** Updates application UI and image on TV according to scale values. */
  private void updateUiAndTvScale(float scaleFactorDelta, float scalePointX, float scalePointY) {
    // rounds scale values so that they are the same as those accepted by ViewController
    float roundedScaleFactorDelta = (float) ((int) (scaleFactorDelta * 100)) / 100;
    float roundedScalePointX = (int) scalePointX;
    float roundedScalePointY = (int) scalePointY;

    // applies rounded scale to transformation object
    // additionally the scale that was applied after bounds check is stored in newScaleFactorDelta
    float newScaleFactorDelta =
        mPinchToZoomTransformation.updateScaleInBounds(
            roundedScaleFactorDelta, roundedScalePointX, roundedScalePointY);

    updateImageView();

    scaleTv(newScaleFactorDelta, roundedScalePointX, roundedScalePointY);

    updateZoomTextViewText();
  }
예제 #6
0
  /** Abstracts call to ViewController.zoom() method. */
  private void scaleTv(float scaleFactorDelta, float scalePointX, float scalePointY) {
    if (mAllShareService.isImageReady()) {
      int tvScalePointX = (int) scalePointX;
      int tvScalePointY = (int) scalePointY;
      int tvScaleFactorDelta = (int) (scaleFactorDelta * 100);

      int rotation = mPinchToZoomTransformation.getRotation();

      mAllShareService
          .getViewController()
          .zoom(
              tvScalePointX,
              tvScalePointY,
              tvScaleFactorDelta,
              rotation,
              mImageViewWidth,
              mImageViewHeight);
    }
  }
예제 #7
0
 /** Updates ImageView with current transformation. */
 private void updateImageView() {
   mImageView.setImageMatrix(mPinchToZoomTransformation.getMatrix());
   mImageView.invalidate();
 }