android.graphics.RectF#equals ( )源码实例Demo

下面列出了android.graphics.RectF#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    RectF srcRect;
    if (mLastGenTrans == null || !drawableBounds.equals(mLastDrawableBounds)) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = mLastGenTrans.getDestinyRect();
    }
    RectF dstRect = generateRandomRect(drawableBounds, viewport);
    mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
            mTransitionInterpolator);

    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    RectF srcRect;
    if (mLastGenTrans == null || !drawableBounds.equals(mLastDrawableBounds)) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = mLastGenTrans.getDestinyRect();
    }
    RectF dstRect = generateRandomRect(drawableBounds, viewport);
    mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
            mTransitionInterpolator);

    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
public static void resizingBehaviorApply(ResizingBehavior behavior, RectF rect, RectF target, RectF result) {
  if (rect.equals(target) || target == null) {
    result.set(rect);
    return;
  }

  if (behavior == ResizingBehavior.Stretch) {
    result.set(target);
    return;
  }

  float xRatio = Math.abs(target.width() / rect.width());
  float yRatio = Math.abs(target.height() / rect.height());
  float scale = 0f;

  switch (behavior) {
    case AspectFit: {
      scale = Math.min(xRatio, yRatio);
      break;
    }
    case AspectFill: {
      scale = Math.max(xRatio, yRatio);
      break;
    }
    case Center: {
      scale = 1f;
      break;
    }
    default:
      break;
  }

  float newWidth = Math.abs(rect.width() * scale);
  float newHeight = Math.abs(rect.height() * scale);
  result.set(target.centerX() - newWidth / 2,
    target.centerY() - newHeight / 2,
    target.centerX() + newWidth / 2,
    target.centerY() + newHeight / 2);
}
 
public static void resizingBehaviorApply(ResizingBehavior behavior, RectF rect, RectF target, RectF result) {
  if (rect.equals(target) || target == null) {
    result.set(rect);
    return;
  }

  if (behavior == ResizingBehavior.Stretch) {
    result.set(target);
    return;
  }

  float xRatio = Math.abs(target.width() / rect.width());
  float yRatio = Math.abs(target.height() / rect.height());
  float scale = 0f;

  switch (behavior) {
    case AspectFit: {
      scale = Math.min(xRatio, yRatio);
      break;
    }
    case AspectFill: {
      scale = Math.max(xRatio, yRatio);
      break;
    }
    case Center: {
      scale = 1f;
      break;
    }
    default:
      break;
  }

  float newWidth = Math.abs(rect.width() * scale);
  float newHeight = Math.abs(rect.height() * scale);
  result.set(target.centerX() - newWidth / 2,
    target.centerY() - newHeight / 2,
    target.centerX() + newWidth / 2,
    target.centerY() + newHeight / 2);
}
 
/**
 * Sets the image bounds, in view-absolute coordinates.
 */
@Override
public void setImageBounds(RectF imageBounds) {
    if (!imageBounds.equals(mImageBounds)) {
        mImageBounds.set(imageBounds);
        onTransformChanged();
    }
}
 
@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    boolean firstTransition = mLastGenTrans == null;
    boolean drawableBoundsChanged = true;
    boolean viewportRatioChanged = true;

    RectF srcRect = null;
    RectF dstRect = null;

    if (!firstTransition) {
        dstRect = mLastGenTrans.getDestinyRect();
        drawableBoundsChanged = !drawableBounds.equals(mLastDrawableBounds);
        viewportRatioChanged = !MathUtils.haveSameAspectRatio(dstRect, viewport);
    }

    if (dstRect == null || drawableBoundsChanged || viewportRatioChanged) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = dstRect;
    }
    dstRect = generateRandomRect(drawableBounds, viewport);


    try {
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
                mTransitionInterpolator);
    } catch (IncompatibleRatioException e) {
        // Most likely the window was resized.
        srcRect = generateRandomRect(drawableBounds, viewport);
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
                mTransitionInterpolator);
    }
    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    boolean firstTransition = mLastGenTrans == null;
    boolean drawableBoundsChanged = true;
    boolean viewportRatioChanged = true;

    RectF srcRect = null;
    RectF dstRect = null;

    if (!firstTransition) {
        dstRect = mLastGenTrans.getDestinyRect();
        drawableBoundsChanged = !drawableBounds.equals(mLastDrawableBounds);
        viewportRatioChanged = !MathUtils.haveSameAspectRatio(dstRect, viewport);
    }

    if (dstRect == null || drawableBoundsChanged || viewportRatioChanged) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = dstRect;
    }
    dstRect = generateRandomRect(drawableBounds, viewport);

    mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
            mTransitionInterpolator);

    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    boolean firstTransition = mLastGenTrans == null;
    boolean drawableBoundsChanged = true;
    boolean viewportRatioChanged = true;

    RectF srcRect = null;
    RectF dstRect = null;

    if (!firstTransition) {
        dstRect = mLastGenTrans.getDestinyRect();
        drawableBoundsChanged = !drawableBounds.equals(mLastDrawableBounds);
        viewportRatioChanged = !MathUtils.haveSameAspectRatio(dstRect, viewport);
    }

    if (dstRect == null || drawableBoundsChanged || viewportRatioChanged) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = dstRect;
    }
    dstRect = generateRandomRect(drawableBounds, viewport);


    try {
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
                mTransitionInterpolator);
    } catch (IncompatibleRatioException e) {
        // Most likely the window was resized.
        srcRect = generateRandomRect(drawableBounds, viewport);
        mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
                mTransitionInterpolator);
    }
    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
@Override
public Transition generateNextTransition(RectF drawableBounds, RectF viewport) {
    boolean firstTransition = mLastGenTrans == null;
    boolean drawableBoundsChanged = true;
    boolean viewportRatioChanged = true;

    RectF srcRect = null;
    RectF dstRect = null;

    if (!firstTransition) {
        dstRect = mLastGenTrans.getDestinyRect();
        drawableBoundsChanged = !drawableBounds.equals(mLastDrawableBounds);
        viewportRatioChanged = !MathUtils.haveSameAspectRatio(dstRect, viewport);
    }

    if (dstRect == null || drawableBoundsChanged || viewportRatioChanged) {
        srcRect = generateRandomRect(drawableBounds, viewport);
    } else {
        /* Sets the destiny rect of the last transition as the source one
         if the current drawable has the same dimensions as the one of
         the last transition. */
        srcRect = dstRect;
    }
    dstRect = generateRandomRect(drawableBounds, viewport);

    mLastGenTrans = new Transition(srcRect, dstRect, mTransitionDuration,
            mTransitionInterpolator);

    mLastDrawableBounds = drawableBounds;

    return mLastGenTrans;
}
 
源代码10 项目: fresco   文件: DefaultZoomableController.java
/** Sets the image bounds, in view-absolute coordinates. */
@Override
public void setImageBounds(RectF imageBounds) {
  if (!imageBounds.equals(mImageBounds)) {
    mImageBounds.set(imageBounds);
    onTransformChanged();
    if (mImageBoundsListener != null) {
      mImageBoundsListener.onImageBoundsSet(mImageBounds);
    }
  }
}
 
源代码11 项目: Camera2   文件: TextureViewHelper.java
/**
 * Returns a transformation matrix that implements rotation that is
 * consistent with CaptureLayoutHelper and TextureViewHelper. The magical
 * invariant for CaptureLayoutHelper and TextureViewHelper that must be
 * obeyed is that the bounding box of the view must be EXACTLY the bounding
 * box of the surfaceDimensions AFTER the transformation has been applied.
 *
 * @param currentDisplayOrientation The current display orientation,
 *                                  measured counterclockwise from to the device's natural
 *                                  orientation (in degrees, always a multiple of 90, and between
 *                                  0 and 270, inclusive).
 * @param surfaceDimensions         The dimensions of the
 *                                  {@link android.view.Surface} on which the preview image is
 *                                  being rendered. It usually only makes sense for the upper-left
 *                                  corner to be at the origin.
 * @param desiredBounds             The boundaries within the
 *                                  {@link android.view.Surface} where the final image should
 *                                  appear. These can be used to translate and scale the output,
 *                                  but note that the image will be stretched to fit, possibly
 *                                  changing its aspect ratio.
 * @return The transform matrix that should be applied to the
 * {@link android.view.Surface} in order for the image to display
 * properly in the device's current orientation.
 */
public Matrix getPreviewRotationalTransform(int currentDisplayOrientation,
                                            RectF surfaceDimensions,
                                            RectF desiredBounds)
{
    if (surfaceDimensions.equals(desiredBounds))
    {
        return new Matrix();
    }

    Matrix transform = new Matrix();
    transform.setRectToRect(surfaceDimensions, desiredBounds, Matrix.ScaleToFit.FILL);

    RectF normalRect = surfaceDimensions;
    // Bounding box of 90 or 270 degree rotation.
    RectF rotatedRect = new RectF(normalRect.width() / 2 - normalRect.height() / 2,
            normalRect.height() / 2 - normalRect.width() / 2,
            normalRect.width() / 2 + normalRect.height() / 2,
            normalRect.height() / 2 + normalRect.width() / 2);

    OrientationManager.DeviceOrientation deviceOrientation =
            OrientationManager.DeviceOrientation.from(currentDisplayOrientation);

    // This rotation code assumes that the aspect ratio of the content
    // (not of necessarily the surface) equals the aspect ratio of view that is receiving
    // the preview.  So, a 4:3 surface that contains 16:9 data will look correct as
    // long as the view is also 16:9.
    switch (deviceOrientation)
    {
        case CLOCKWISE_90:
            transform.setRectToRect(rotatedRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(270, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_180:
            transform.setRectToRect(normalRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(180, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_270:
            transform.setRectToRect(rotatedRect, desiredBounds, Matrix.ScaleToFit.FILL);
            transform.preRotate(90, mWidth / 2, mHeight / 2);
            break;
        case CLOCKWISE_0:
        default:
            transform.setRectToRect(normalRect, desiredBounds, Matrix.ScaleToFit.FILL);
            break;
    }

    return transform;
}
 
源代码12 项目: Camera2   文件: CameraDeviceInfo.java
/**
 * @param currentDisplayOrientation
 *          The current display orientation, measured counterclockwise
 *          from to the device's natural orientation (in degrees, always
 *          a multiple of 90, and between 0 and 270, inclusive).
 * @param surfaceDimensions
 *          The dimensions of the {@link android.view.Surface} on which
 *          the preview image is being rendered. It usually only makes
 *          sense for the upper-left corner to be at the origin.
 * @param desiredBounds
 *          The boundaries within the {@link android.view.Surface} where
 *          the final image should appear. These can be used to
 *          translate and scale the output, but note that the image will
 *          be stretched to fit, possibly changing its aspect ratio.
 * @return
 *          The transform matrix that should be applied to the
 *          {@link android.view.Surface} in order for the image to
 *          display properly in the device's current orientation.
 */
public Matrix getPreviewTransform(int currentDisplayOrientation, RectF surfaceDimensions,
                                  RectF desiredBounds) {
    if (!orientationIsValid(currentDisplayOrientation) ||
            surfaceDimensions.equals(desiredBounds)) {
        return new Matrix();
    }

    Matrix transform = new Matrix();
    transform.setRectToRect(surfaceDimensions, desiredBounds, Matrix.ScaleToFit.FILL);
    return transform;
}