Example usage for android.graphics RectF intersect

List of usage examples for android.graphics RectF intersect

Introduction

In this page you can find the example usage for android.graphics RectF intersect.

Prototype

public boolean intersect(RectF r) 

Source Link

Document

If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.

Usage

From source file:Main.java

public static boolean checkBoundsIntersect(RectF r, RectF tst) {// tests that tst in within the bounds of r
    if (tst != null) {
        return r.intersect(tst);
    } else {//from w  w w  . ja v a 2 s .co m
        return false;
    }
}

From source file:Main.java

/**
 * 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./*w  w  w . j  a  v  a  2 s  .c  o  m*/
 *
 * @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);
}

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;/*  w  w w  .j  av a 2  s . co m*/
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}

From source file:com.pdftron.pdf.tools.Tool.java

public boolean showMenu(List<MenuEntry> menu_titles, RectF anchor_rect, List<MenuEntry> overflow_menu_titles) {
    if (anchor_rect == null) {
        return false;
    }//w  w  w. ja va2  s.co m

    int menu_sz = menu_titles.size();
    if (menu_sz > 0) {
        if (mQuickMenu != null) {
            closeMenu();
            mQuickMenu = null;
        }

        RectF client_r = new RectF(0, 0, mPDFView.getWidth(), mPDFView.getHeight());
        if (!client_r.intersect(anchor_rect)) {
            return false;
        }

        View anchor = new View(mPDFView.getContext());
        anchor.setVisibility(View.INVISIBLE);

        RectF anchorRect = calculateQMAnchor(anchor_rect);
        int atop = (int) anchorRect.top;
        int abottom = (int) anchorRect.bottom;
        int aright = (int) anchorRect.right;
        int aleft = (int) anchorRect.left;

        anchor.layout(aleft, atop, aright, abottom);

        ToolManager toolManager = (ToolManager) mPDFView.getToolManager();

        toolManager.setQuickMenuJustClosed(false);

        mQuickMenu = new QuickMenu(anchor, atop, aleft, abottom, aright, menu_titles, overflow_menu_titles,
                toolManager, new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        if (mPDFView.getToolManager() instanceof ToolManager) {
                            ((ToolManager) mPDFView.getToolManager()).setQuickMenuJustClosed(true);
                        }
                        // When dismissed, trigger the menu-clicked call-back function.
                        mMenuShown = false;
                        if (mQuickMenu != null) {
                            int selected = mQuickMenu.getSelectedId();
                            if (selected >= 0) {
                                com.pdftron.pdf.utils.AnalyticsHandlerAdapter.getInstance().sendEvent(
                                        AnalyticsHandlerAdapter.CATEGORY_QUICKTOOL,
                                        mQuickMenu.getSelectedType() + " selected");

                                onQuickMenuClicked(selected, mQuickMenu.getSelectedType());
                            }
                        }
                    }
                }, mPDFView.isHardwareAccelerated());
        //adriaan
        if (!ToolManager.isPenMarkActive && !ToolManager.isRedHighlight && !ToolManager.isGreenHighlight) {
            mQuickMenu.show();
            mMenuShown = true;
            return true;
        } else {
            ToolManager.isRedHighlight = false;
            ToolManager.isGreenHighlight = false;
            return false;
        }
    }
    return false;
}