当前位置: 首页>>代码示例>>Java>>正文


Java RectF.round方法代码示例

本文整理汇总了Java中android.graphics.RectF.round方法的典型用法代码示例。如果您正苦于以下问题:Java RectF.round方法的具体用法?Java RectF.round怎么用?Java RectF.round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.RectF的用法示例。


在下文中一共展示了RectF.round方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onLayout

import android.graphics.RectF; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final RectF layoutRect = tempRectF1;
    final RectF layoutRectRotated = tempRectF2;
    layoutRect.set(0, 0, right - left, bottom - top);
    rotateMatrix.setRotate(angle, layoutRect.centerX(), layoutRect.centerY());
    rotateMatrix.postScale(-1, 1);
    rotateMatrix.mapRect(layoutRectRotated, layoutRect);
    layoutRectRotated.round(viewRectRotated);
    final View view = getView();
    if (view != null) {
        view.layout(viewRectRotated.left, viewRectRotated.top, viewRectRotated.right,
                viewRectRotated.bottom);
    }
}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:16,代码来源:RotatedViewGroup.java

示例2: computeFocusAreaFromMotionEvent

import android.graphics.RectF; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:jonathan68,项目名称:react-native-camera,代码行数:61,代码来源:RCTCameraUtils.java


注:本文中的android.graphics.RectF.round方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。