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

The following examples show how to use android.graphics.RectF#round() . 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: FrescoVitoRegionDecoder.java    From fresco with MIT License 6 votes vote down vote up
private @Nullable Rect computeRegionToDecode(
    EncodedImage encodedImage, ImageDecodeOptions options) {
  if (!(options instanceof FrescoVitoImageDecodeOptions)) {
    return null;
  }
  FrescoVitoImageDecodeOptions frescoVitoOptions = (FrescoVitoImageDecodeOptions) options;

  Rect regionToDecode = new Rect();
  Matrix matrix = new Matrix();
  frescoVitoOptions.scaleType.getTransform(
      matrix,
      frescoVitoOptions.parentBounds,
      encodedImage.getWidth(),
      encodedImage.getHeight(),
      frescoVitoOptions.focusPoint.x,
      frescoVitoOptions.focusPoint.y);
  matrix.invert(matrix);

  RectF tempRectangle = new RectF(frescoVitoOptions.parentBounds);
  matrix.mapRect(tempRectangle);

  tempRectangle.round(regionToDecode);
  return regionToDecode;
}
 
Example 2
Source File: DisplayContent.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
        DisplayCutout cutout, int rotation) {
    if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
        return WmDisplayCutout.NO_CUTOUT;
    }
    if (rotation == ROTATION_0) {
        return WmDisplayCutout.computeSafeInsets(
                cutout, mInitialDisplayWidth, mInitialDisplayHeight);
    }
    final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
    final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
                    cutout, mInitialDisplayWidth, mInitialDisplayHeight)
            .getDisplayCutout().getBoundingRects();
    transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
            mTmpMatrix);
    final Region region = Region.obtain();
    for (int i = 0; i < bounds.size(); i++) {
        final Rect rect = bounds.get(i);
        final RectF rectF = new RectF(bounds.get(i));
        mTmpMatrix.mapRect(rectF);
        rectF.round(rect);
        region.op(rect, Op.UNION);
    }

    return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
            rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
            rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
}
 
Example 3
Source File: CDrawable.java    From FabricView with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the bounds of this object. Takes into consideration all the transforms attached
 * to it.
 * @return The position of this object on the canvas.
 */
public Rect computeBounds() {
    RectF bounds = new RectF(x, y, x+width, y+height);
    Matrix m = new Matrix();
    for (CTransform t :
            mTransforms) {
        t.applyTransform(m);
    }
    m.mapRect(bounds);
    lastBounds = new Rect();
    bounds.round(lastBounds);
    return lastBounds;
}
 
Example 4
Source File: PDGraphicsState.java    From PdfBox-Android with Apache License 2.0 5 votes vote down vote up
/**
     * Constructor with a given page size to initialize the clipping path.
     * @param page the size of the page
     */
    public PDGraphicsState(PDRectangle page)
    {
//        clippingPath = new Area(new GeneralPath(page.toGeneralPath()));TODO: PdfBox-Android
    	RectF bounds = new RectF();
    	page.toGeneralPath().computeBounds(bounds, true);
    	clippingPath = new Region();
    	Rect boundsRounded = new Rect();
    	bounds.round(boundsRounded);
    	clippingPath.setPath(page.toGeneralPath(), new Region(boundsRounded));
    }
 
Example 5
Source File: PDGraphicsState.java    From PdfBox-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Modify the current clipping path by intersecting it with the given path.
 * @param path path to intersect with the clipping path
 */
public void intersectClippingPath(Path path)
{
	RectF bounds = new RectF();
	path.computeBounds(bounds, true);
	Region r = new Region();
	Rect boundsRounded = new Rect();
	bounds.round(boundsRounded);
	r.setPath(path, new Region(boundsRounded));
    intersectClippingPath(r);
}
 
Example 6
Source File: DisplayCutout.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static void toRectAndAddToRegion(Path p, Region inoutRegion, Rect inoutRect) {
    final RectF rectF = new RectF();
    p.computeBounds(rectF, false /* unused */);
    rectF.round(inoutRect);
    inoutRegion.op(inoutRect, Op.UNION);
}
 
Example 7
Source File: RCTCameraUtils.java    From react-native-camera-face-detector with MIT License 4 votes vote down vote up
/**
 * Computes a Camera.Area corresponding to the new focus area to focus the camera on. This is
 * done by deriving a square around the center of a MotionEvent pointer (with side length equal
 * to FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH), then transforming this rectangle's/square's
 * coordinates into the (-1000, 1000) coordinate system used for camera focus areas.
 *
 * Also note that we operate on RectF instances for the most part, to avoid any integer
 * division rounding errors going forward. We only round at the very end for playing into
 * the final focus areas list.
 *
 * @throws RuntimeException if unable to compute valid intersection between MotionEvent region
 * and SurfaceTexture region.
 */
protected static Camera.Area computeFocusAreaFromMotionEvent(final MotionEvent event, final int surfaceTextureWidth, final int surfaceTextureHeight) {
    // Get position of first touch pointer.
    final int pointerId = event.getPointerId(0);
    final int pointerIndex = event.findPointerIndex(pointerId);
    final float centerX = event.getX(pointerIndex);
    final float centerY = event.getY(pointerIndex);

    // Build event rect. Note that coordinates increase right and down, such that left <= right
    // and top <= bottom.
    final RectF eventRect = new RectF(
            centerX - FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // left
            centerY - FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // top
            centerX + FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // right
            centerY + FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH // bottom
    );

    // Intersect this rect with the rect corresponding to the full area of the parent surface
    // texture, making sure we are not placing any amount of the eventRect outside the parent
    // surface's area.
    final RectF surfaceTextureRect = new RectF(
            (float) 0, // left
            (float) 0, // top
            (float) surfaceTextureWidth, // right
            (float) surfaceTextureHeight // bottom
    );
    final boolean intersectSuccess = eventRect.intersect(surfaceTextureRect);
    if (!intersectSuccess) {
        throw new RuntimeException(
                "MotionEvent rect does not intersect with SurfaceTexture rect; unable to " +
                        "compute focus area"
        );
    }

    // Transform into (-1000, 1000) focus area coordinate system. See
    // https://developer.android.com/reference/android/hardware/Camera.Area.html.
    // Note that if this is ever changed to a Rect instead of RectF, be cautious of integer
    // division rounding!
    final RectF focusAreaRect = new RectF(
            (eventRect.left / surfaceTextureWidth) * 2000 - 1000, // left
            (eventRect.top / surfaceTextureHeight) * 2000 - 1000, // top
            (eventRect.right / surfaceTextureWidth) * 2000 - 1000, // right
            (eventRect.bottom / surfaceTextureHeight) * 2000 - 1000 // bottom
    );
    Rect focusAreaRectRounded = new Rect();
    focusAreaRect.round(focusAreaRectRounded);
    return new Camera.Area(focusAreaRectRounded, FOCUS_AREA_WEIGHT);
}