Java Code Examples for android.graphics.RectF#equals()

The following examples show how to use android.graphics.RectF#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomTransitionGenerator.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: RandomTransitionGenerator.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
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);
}
 
Example 4
Source File: ManeuversStyleKit.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
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);
}
 
Example 5
Source File: DefaultZoomableController.java    From CommentGallery with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the image bounds, in view-absolute coordinates.
 */
@Override
public void setImageBounds(RectF imageBounds) {
    if (!imageBounds.equals(mImageBounds)) {
        mImageBounds.set(imageBounds);
        onTransformChanged();
    }
}
 
Example 6
Source File: KenBurnsTransitionGenerator.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: RandomTransitionGenerator.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: KenBurnsTransitionGenerator.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: RandomTransitionGenerator.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: DefaultZoomableController.java    From fresco with MIT License 5 votes vote down vote up
/** 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);
    }
  }
}
 
Example 11
Source File: TextureViewHelper.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: CameraDeviceInfo.java    From Camera2 with Apache License 2.0 3 votes vote down vote up
/**
 * @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;
}