Example usage for android.graphics RectF set

List of usage examples for android.graphics RectF set

Introduction

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

Prototype

public void set(Rect src) 

Source Link

Document

Copy the coordinates from src into this rectangle.

Usage

From source file:Main.java

static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();/*from  w  w w  .j a  va  2  s. co  m*/
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.set(IDENTITY);
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:Main.java

public static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();//  w  ww.j ava 2  s . co  m
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.set(IDENTITY);
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:Main.java

public static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();/*  w w w.  jav  a 2 s.  c om*/
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.reset();
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
        sRectF.set(rectF);
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.CircularBorderDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mInvalidateShader) {
        mPaint.setShader(createGradientShader());
        mInvalidateShader = false;/* w w w  .j a  v a  2  s .co  m*/
    }

    final float halfBorderWidth = mPaint.getStrokeWidth() / 2f;
    final RectF rectF = mRectF;

    // We need to inset the oval bounds by half the border width. This is because stroke draws
    // the center of the border on the dimension. Whereas we want the stroke on the inside.
    copyBounds(mRect);
    rectF.set(mRect);
    rectF.left += halfBorderWidth;
    rectF.top += halfBorderWidth;
    rectF.right -= halfBorderWidth;
    rectF.bottom -= halfBorderWidth;

    // Draw the oval
    canvas.drawOval(rectF, mPaint);
}

From source file:android.support.design.widget.CircularBorderDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mInvalidateShader) {
        mPaint.setShader(createGradientShader());
        mInvalidateShader = false;/*from  www.  j a  va2 s  . co m*/
    }

    final float halfBorderWidth = mPaint.getStrokeWidth() / 2f;
    final RectF rectF = mRectF;

    // We need to inset the oval bounds by half the border width. This is because stroke draws
    // the center of the border on the dimension. Whereas we want the stroke on the inside.
    copyBounds(mRect);
    rectF.set(mRect);
    rectF.left += halfBorderWidth;
    rectF.top += halfBorderWidth;
    rectF.right -= halfBorderWidth;
    rectF.bottom -= halfBorderWidth;

    canvas.save();
    canvas.rotate(mRotation, rectF.centerX(), rectF.centerY());
    // Draw the oval
    canvas.drawOval(rectF, mPaint);
    canvas.restore();
}

From source file:com.example.waitou.rxjava.LoadingView.java

/**
 * draw the ring/*  w ww.j a v  a2s . c o  m*/
 *
 * @param canvas to draw the Ring
 * @param bounds the ring's rect
 */
private void drawRing(Canvas canvas, Rect bounds) {
    final RectF arcBounds = mTempBounds;
    final Ring ring = mRing;
    arcBounds.set(bounds);
    arcBounds.inset(ring.strokeInset, ring.strokeInset);
    canvas.drawArc(arcBounds, ring.start, ring.sweep, false, mPaint);
}

From source file:com.example.android.camera.CameraActivity.java

private List<Rect> getFaces() {
    List<Rect> found = new ArrayList<Rect>();

    for (Face face : mPreview.faces) {
        if (face.score < 100)
            continue;

        Rect rect = new Rect();
        RectF rectf = new RectF();

        rectf.set(face.rect);
        mViewFinderView.dumpRect(rectf, "before");
        matrix.mapRect(rectf);//from  w  ww .ja  v a 2  s.c  o  m
        mViewFinderView.dumpRect(rectf, "after");

        float adj = (rectf.bottom - rectf.top - rectf.right + rectf.left) / 2;
        rectf.set(rectf.left - adj, rectf.top, rectf.right + adj, rectf.bottom);
        mViewFinderView.dumpRect(rectf, "Squared");

        if (rectf.left < 0) {
            rectf.set(0, rectf.top, rectf.right - rectf.left, rectf.bottom);
            Log.d("face Adjust", "Left");
        } else if (rectf.right > pWidth) {
            rectf.set(rectf.left - rectf.right + pWidth, rectf.top, pWidth, rectf.bottom);
            Log.d("face Adjust", "Right");
        }

        if (rectf.top < 0) {
            rectf.set(rectf.left, 0, rectf.right, rectf.bottom - rectf.top);
            Log.d("face Adjust", "Top");
        } else if (rectf.bottom > pHeight) {
            rectf.set(rectf.left, rectf.top - rectf.bottom + pHeight, rectf.right, pHeight);
            Log.d("face Adjust", "Bottom");
        }

        mViewFinderView.dumpRect(rectf, "Shift Adjusted");
        rectf.round(rect);
        found.add(rect);
    }

    return found;
}

From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java

private boolean checkMatrixBounds() {
    final RectF rect = getVisibleRect();
    if (rect == null) {
        return false;
    }/*from  w  ww.  j a v a2 s .  co m*/

    RectF src = new RectF();
    src.set(rect);
    final float h = rect.height(), w = rect.width();
    float deltaX = 0, deltaY = 0;
    View parent = (View) mImageView.getParent();

    final int viewHeight = parent.getHeight();//getImageViewHeight(mImageView);
    final int viewWidth = parent.getWidth();//getImageViewWidth(mImageView);
    System.out.println("===============================================width:" + viewWidth + "/" + viewHeight);
    System.out
            .println("+++++++++rect.left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom);

    float scale = getScale();
    float centerX = rect.centerX();
    float centerY = rect.centerY();
    float targetW = w * scale;
    float targetH = h * scale;
    RectF targetRect = new RectF(centerX - targetW / 2, centerY - targetH / 2, centerX + targetW / 2,
            centerY + targetH / 2);

    rect.set(targetRect);
    final float height = rect.height(), width = rect.width();

    if (height <= viewHeight) {
        deltaY = (viewHeight - height) / 2 - rect.top;
    } else if (rect.top > 0) {
        deltaY = -rect.top;
    } else if (rect.bottom < viewHeight) {
        deltaY = viewHeight - rect.bottom;
    }

    if (width <= viewWidth) {
        deltaX = (viewWidth - width) / 2 - rect.left;
        mScrollEdge = EDGE_BOTH;
    } else if (rect.left > 0) {
        mScrollEdge = EDGE_LEFT;
        deltaX = -rect.left;
    } else if (rect.right < viewWidth) {
        deltaX = viewWidth - rect.right;
        mScrollEdge = EDGE_RIGHT;
    } else {
        mScrollEdge = EDGE_NONE;
    }

    // Finally actually translate the matrix
    if (!mStable) {
        System.out.println("+++++++++++deltaX:" + deltaX + "/deltaY:" + deltaY + "---" + getScale());
        postTranslate(deltaX, deltaY);
    }
    return true;
}

From source file:com.appunite.scroll.ScaleImageView.java

private void getImageRect(RectF rect) {
    rect.set(mSrcRect);
    final float width = Math.max(mSrcRect.width() * mScale, mContentRect.width() - mMarginLeft - mMarginRight);
    final float height = Math.max(mSrcRect.height() * mScale,
            mContentRect.height() - mMarginTop - mMarginBottom);

    final float width2 = width / 2;
    final float height2 = height / 2;

    if (mUsedAlignType == ALIGN_BOTTOM) {
        rect.set(-width2, -height, width2, 0);
    } else if (mUsedAlignType == ALIGN_TOP) {
        rect.set(-width2, 0, width2, height);
    } else if (mUsedAlignType == ALIGN_CENTER_VERTICAL || mUsedAlignType == ALIGN_CENTER_HORIZONTAL) {
        rect.set(-width2, -height2, width2, height2);
    } else if (mUsedAlignType == ALIGN_LEFT) {
        rect.set(0, -height2, width, height2);
    } else if (mUsedAlignType == ALIGN_RIGHT) {
        rect.set(-width, -height2, 0, height2);
    }//w  ww.  j a  va  2 s.  c o m
    getRealTranslation(mTranslation, mRealTranslation);
    rect.offset(mRealTranslation.x, mRealTranslation.y);
}

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);
    if (dstActual.intersect(0, 0, mWindowWidth, mWindowHeight)) {
        if (dst.equals(dstActual)) {
            // Still dst
            srcActual.set(0, 0, mImageWidth, mImageHeight);
        } else {/* w  ww .ja va2  s  . c om*/
            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;
}