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(float left, float top, float right, float bottom) 

Source Link

Document

If the rectangle specified by left,top,right,bottom 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, float margin) {// tests that tst in within the bounds of r
    if (tst != null) {
        return r.intersect(tst.left - margin, tst.top - margin, tst.right + margin, tst.bottom + margin);
    } else {//w  w w .j a va2s .  c  o  m
        return false;
    }
}

From source file:com.lovejjfg.blogdemo.ui.indicator.RectPageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
        return;//from  w  ww .j a  v a 2  s. c  o  m
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }

    int longSize;
    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    if (mOrientation == HORIZONTAL) {
        longSize = getWidth();
        longPaddingBefore = getPaddingLeft();
        longPaddingAfter = getPaddingRight();
        shortPaddingBefore = getPaddingTop();
    } else {
        longSize = getHeight();
        longPaddingBefore = getPaddingTop();
        longPaddingAfter = getPaddingBottom();
        shortPaddingBefore = getPaddingLeft();
    }

    final float mHalfRectWidth = mRectWidth / 2.0f;
    final float rectOffset = mRectWidth * mRadiusRatio;
    final float shortOffset = shortPaddingBefore + mHalfRectWidth;
    float longOffset = longPaddingBefore + mHalfRectWidth;
    if (mCentered) {
        longOffset += (longSize - longPaddingBefore - longPaddingAfter - (count * mRectWidth)
                - (count - 1) * rectOffset) / 2.0f;
    }

    float dX;
    float dY;

    float pageFillRadius = mHalfRectWidth;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * (mRectWidth + rectOffset));
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        RectF rectF = new RectF(dX - pageFillRadius, dY - pageFillRadius, dX + pageFillRadius,
                dY + pageFillRadius);
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            //                canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
            canvas.drawRoundRect(rectF, 2, 2, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mHalfRectWidth) {
            rectF.intersect(dX - mHalfRectWidth, dY - mHalfRectWidth, dX + mHalfRectWidth, dY + mHalfRectWidth);
            canvas.drawRoundRect(rectF, 2, 2, mPaintPageFill);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * (rectOffset + mRectWidth);
    if (!mSnap) {
        cx += mPageOffset * (rectOffset + mRectWidth);
    }
    if (mOrientation == HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }
    RectF rectF = new RectF(dX - mHalfRectWidth, dY - mHalfRectWidth, dX + mHalfRectWidth, dY + mHalfRectWidth);
    canvas.drawRoundRect(rectF, 2, 2, mPaintFill);
}

From source file:com.hippo.largeimageview.LargeImageView.java

private void applyRectInWindow() {
    final RectF dst = mDst;
    final RectF dstActual = mDstActual;
    final RectF srcActual = mSrcActual;

    dstActual.set(dst);//from  w  ww .j a  va2s.c  o  m
    if (dstActual.intersect(0, 0, mWindowWidth, mWindowHeight)) {
        if (dst.equals(dstActual)) {
            // Still dst
            srcActual.set(0, 0, mImageWidth, mImageHeight);
        } else {
            srcActual.left = lerp(0.0f, mImageWidth, norm(dst.left, dst.right, dstActual.left));
            srcActual.right = lerp(0.0f, mImageWidth, norm(dst.left, dst.right, dstActual.right));
            srcActual.top = lerp(0.0f, mImageHeight, norm(dst.top, dst.bottom, dstActual.top));
            srcActual.bottom = lerp(0.0f, mImageHeight, norm(dst.top, dst.bottom, dstActual.bottom));
        }
    } else {
        // Can't be seen, set src and dst empty
        srcActual.setEmpty();
        dstActual.setEmpty();
    }

    mRectDirty = false;
}