當前位置: 首頁>>代碼示例>>Java>>正文


Java RectF.intersect方法代碼示例

本文整理匯總了Java中android.graphics.RectF.intersect方法的典型用法代碼示例。如果您正苦於以下問題:Java RectF.intersect方法的具體用法?Java RectF.intersect怎麽用?Java RectF.intersect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.RectF的用法示例。


在下文中一共展示了RectF.intersect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSensorChanged

import android.graphics.RectF; //導入方法依賴的package包/類
@Override
public void onSensorChanged(SensorEvent pEvent) {
    float x = pEvent.values[0];
    float y = pEvent.values[1];

    if(mBoule != null) {
        // On met à jour les coordonnées de la boule
        RectF hitBox = mBoule.putXAndY(x, y);

        // Pour tous les blocs du labyrinthe
        for(Bloc block : mBlocks) {
            // On crée un nouveau rectangle pour ne pas modifier celui du bloc
            RectF inter = new RectF(block.getRectangle());
            if(inter.intersect(hitBox)) {
                // On agit différement en fonction du type de bloc
                switch(block.getType()) {
                    case TROU:
                        mActivity.showDefeatDialog();
                        break;

                    case DEPART:
                        break;

                    case ARRIVEE:
                        mActivity.showVictoryDialog();
                        break;
                }
                break;
            }
        }
    }
}
 
開發者ID:Gramatiik,項目名稱:sensor-maze,代碼行數:33,代碼來源:MazeEngine.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

示例3: drawGraph

import android.graphics.RectF; //導入方法依賴的package包/類
@Override
protected void drawGraph(ArrayList<EasyPoint> pointList, ArrayList<EasyPoint> rawPointList, RectF rectCanvas, RectF rectGraph,
                         int start, int end, EasyPoint pOriginal, EasyPoint pMin, EasyPoint pMax, float axisWidth,
                         float factorX, float factorY, float animatorValue, Canvas canvas) {
    if (rectCanvas.intersect(rectGraph)) {

        halfFactorWidth = width * factorX / 2;

        EasyPoint p;
        EasyPoint pR;
        RectF r = new RectF();
        String text;
        EasyPoint startP = rawPointList.get(start);
        path.reset();
        path.moveTo(startP.x, startP.y);

        // 繪製矩形
        for (int i = start; i <= end; i++) {
            p = pointList.get(i);
            pR = rawPointList.get(i);
            r.set(pR.x - halfFactorWidth / 2,
                    p.y > 0 ? pOriginal.y + (pR.y - pOriginal.y) * animatorValue : pOriginal.y + axisWidth / 2 + borderWidth / 2,
                    pR.x + halfFactorWidth / 2,
                    p.y > 0 ? pOriginal.y - axisWidth / 2 - borderWidth / 2 : pOriginal.y + (pR.y - pOriginal.y) * animatorValue);

            if (i != selectedIndex) {
                canvas.drawRect(r, rectPaint);
                canvas.drawRect(r, borderPaint);
            } else {
                rectPaint.setColor(rectSelectedColor);
                borderPaint.setColor(borderSelectedColor);
                canvas.drawRect(r, rectPaint);
                canvas.drawRect(r, borderPaint);
                rectPaint.setColor(rectColor);
                borderPaint.setColor(borderColor);
            }

            path.lineTo(pR.x, pR.y);
        }

        // 繪製線條
        pathDst.reset();
        pathDst.rLineTo(0, 0);
        pm.setPath(path, false);
        pm.getSegment(0.0f, pm.getLength() * animatorValue, pathDst, true);
        canvas.drawPath(pathDst, linePaint);

        // 繪製文字
        if (animatorValue >= 0.8f) {
            int alpha = 0;
            for (int i = start; i <= end; i++) {
                p = pointList.get(i);
                pR = rawPointList.get(i);

                text = String.valueOf(p.y);
                float textHeight = fm.bottom - fm.top;
                float textWidth = textPaint.measureText(text);
                float mid = p.y > 0 ?
                        pR.y - textHeight / 2 :
                        pR.y + textHeight / 2;
                float baseLine = mid - (fm.ascent + fm.descent) / 2;

                if (i != selectedIndex) {
                    textPaint.setAlpha((int) (1275 * animatorValue - 1020)); // animatorValue:0.8->1  alpha:0->255
                    canvas.drawText(text, pR.x - textWidth / 2, baseLine, textPaint);
                } else {
                    textPaint.setColor(textSelectedColor);
                    textPaint.setAlpha((int) (1275 * animatorValue - 1020)); // animatorValue:0.8->1  alpha:0->255
                    canvas.drawText(text, pR.x - textWidth / 2, baseLine, textPaint);
                    textPaint.setColor(textColor);
                }
            }
        }
    }
}
 
開發者ID:huzenan,項目名稱:EasyChart,代碼行數:76,代碼來源:EasyGraphHistogram.java


注:本文中的android.graphics.RectF.intersect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。