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

Source Link

Document

Set the rectangle's coordinates to the specified values.

Usage

From source file:com.android.tabletcustomui.views.LeftCircleContainer.java

private void addCircle(int position, final int value, float diff, double ratio) {
    final int radius = value / 2;
    final RectF mOval = new RectF();
    mOval.set(0 + diff, 0 + diff, value - diff, value - diff);

    final Paint mPaintClip = new Paint();
    mPaintClip.setStyle(Paint.Style.FILL);
    mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
    mPaintClip.setAntiAlias(true);/*from  w  w w.j  a v  a  2s  .c o m*/

    final PointF pointF = new PointF(mOval.centerX(), mOval.centerY());
    final Path clipPath = new Path();
    clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW);

    View circleView;
    if (position == 0) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 10, true, mPaintClip);
                canvas.drawArc(mOval, 342, 20, true, mPaintClip);
                canvas.drawArc(mOval, 4, 10, true, mPaintClip);

                canvas.drawArc(mOval, 240, 10, true, mPaintClip);
                canvas.drawArc(mOval, 252, 20, true, mPaintClip);
                canvas.drawArc(mOval, 275, 10, true, mPaintClip);

                canvas.drawArc(mOval, 150, 10, true, mPaintClip);
                canvas.drawArc(mOval, 162, 20, true, mPaintClip);
                canvas.drawArc(mOval, 185, 10, true, mPaintClip);

                canvas.drawArc(mOval, 60, 10, true, mPaintClip);
                canvas.drawArc(mOval, 72, 20, true, mPaintClip);
                canvas.drawArc(mOval, 95, 10, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 1) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 2) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 55, 190, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 3) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 240, 190, true, mPaintClip);
                canvas.drawArc(mOval, 80, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 4) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 335, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 180, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 5) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 6) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 290, 5, true, mPaintClip);
                canvas.drawArc(mOval, 297, 20, true, mPaintClip);
                canvas.drawArc(mOval, 319, 20, true, mPaintClip);

                canvas.drawArc(mOval, 60, 15, true, mPaintClip);
                canvas.drawArc(mOval, 77, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 7) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

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

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 160, 10, true, mPaintClip);
                canvas.drawArc(mOval, 172, 30, true, mPaintClip);
                canvas.drawArc(mOval, 204, 30, true, mPaintClip);
                canvas.drawArc(mOval, 236, 10, true, mPaintClip);

                canvas.drawArc(mOval, 20, 20, true, mPaintClip);
                canvas.drawArc(mOval, 42, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateAntiClockWise(circleView);
    }
}

From source file:org.stockchart.core.Legend.java

public RectF getSize() {
    RectF r = new RectF();

    fIterator.reset();//from  w  w w. j  a  va  2 s. co m

    float fMaxWidthOrHeight = 0f;

    while (fIterator.hasNext()) {
        Tuple<LegendItem, RectF> item = fIterator.getNext();

        float v = isVertical() ? item.x.getSize().width : item.x.getSize().height;

        if (v > fMaxWidthOrHeight)
            fMaxWidthOrHeight = v;
    }

    float right = isVertical() ? fMaxWidthOrHeight : fIterator.getPosition();
    float bottom = isVertical() ? fIterator.getPosition() : fMaxWidthOrHeight;

    r.set(0f, 0f, right, bottom);

    return r;

}

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

/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @return RectF - Displayed Rectangle//from  w w  w  .ja  v a  2  s  . c  o  m
 */
private RectF getVisibleRect() {
    /*View parent = (View) mImageView.getParent();
    RectF mDisplayRect = new RectF();
    Rect mResult = new Rect();
    //parent.getGlobalVisibleRect(mResult);
    parent.getLocalVisibleRect(mResult);
    mDisplayRect.set(mResult);*/
    RectF mDisplayRect = new RectF();
    float tx = mImageView.getTranslationX();
    float ty = mImageView.getTranslationY();
    mDisplayRect.set(tx, ty, tx + mImageView.getWidth(), ty + mImageView.getHeight());
    return mDisplayRect;
}

From source file:com.android.fastergallery.ui.TileImageView.java

public void drawTile(GLCanvas canvas, int tx, int ty, int level, float x, float y, float length) {
    RectF source = mSourceRect;/*from w w w  .  ja  v  a 2s. co m*/
    RectF target = mTargetRect;
    target.set(x, y, x + length, y + length);
    source.set(0, 0, sTileSize, sTileSize);

    Tile tile = getTile(tx, ty, level);
    if (tile != null) {
        if (!tile.isContentValid()) {
            if (tile.mTileState == STATE_DECODED) {
                if (mUploadQuota > 0) {
                    --mUploadQuota;
                    tile.updateContent(canvas);
                } else {
                    mRenderComplete = false;
                }
            } else if (tile.mTileState != STATE_DECODE_FAIL) {
                mRenderComplete = false;
                queueForDecode(tile);
            }
        }
        if (drawTile(tile, canvas, source, target))
            return;
    }
    if (mScreenNail != null) {
        int size = sTileSize << level;
        float scaleX = (float) mScreenNail.getWidth() / mImageWidth;
        float scaleY = (float) mScreenNail.getHeight() / mImageHeight;
        source.set(tx * scaleX, ty * scaleY, (tx + size) * scaleX, (ty + size) * scaleY);
        mScreenNail.draw(canvas, source, target);
    }
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw card boarder and white background
 * @param rectf four float rectangle// www . j a v  a  2s  . c  o  m
 * @param canvas canvas to draw on
 * @param cardBorderPaint paint styled for card boarder
 * @param cardFrontPaint paint styled for card front
 */
private void drawCardBackground(final RectF rectf, final Canvas canvas, final Paint cardBorderPaint,
        final Paint cardFrontPaint) {
    rectf.set(0, 0, Card.WIDTH, Card.HEIGHT);
    canvas.drawRoundRect(rectf, mSuitsSizeHalf, mSuitsSizeHalf, cardBorderPaint);
    rectf.set(1, 1, Card.WIDTH - 1, Card.HEIGHT - 1);
    canvas.drawRoundRect(rectf, mSuitsSizeHalf, mSuitsSizeHalf, cardFrontPaint);
}

From source file:com.aidy.launcher3.photos.views.TiledImageRenderer.java

private void drawTile(GLCanvas canvas, int tx, int ty, int level, float x, float y, float length) {
    RectF source = mSourceRect;/* w  ww . j  a  v  a 2s  .co m*/
    RectF target = mTargetRect;
    target.set(x, y, x + length, y + length);
    source.set(0, 0, mTileSize, mTileSize);

    Tile tile = getTile(tx, ty, level);
    if (tile != null) {
        if (!tile.isContentValid()) {
            if (tile.mTileState == STATE_DECODED) {
                if (mUploadQuota > 0) {
                    --mUploadQuota;
                    tile.updateContent(canvas);
                } else {
                    mRenderComplete = false;
                }
            } else if (tile.mTileState != STATE_DECODE_FAIL) {
                mRenderComplete = false;
                queueForDecode(tile);
            }
        }
        if (drawTile(tile, canvas, source, target)) {
            return;
        }
    }
    if (mPreview != null) {
        int size = mTileSize << level;
        float scaleX = (float) mPreview.getWidth() / mImageWidth;
        float scaleY = (float) mPreview.getHeight() / mImageHeight;
        source.set(tx * scaleX, ty * scaleY, (tx + size) * scaleX, (ty + size) * scaleY);
        canvas.drawTexture(mPreview, source, target);
    }
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();/*from   w w w.j a  v  a  2  s.c  o  m*/
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[] { halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize,
            cornerSize };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java

private RectF getRealPoint(float x, float y, float width, float height) {
    float panX = spenSurfaceView.getPan().x;
    float panY = spenSurfaceView.getPan().y;
    float zoom = spenSurfaceView.getZoomRatio();
    width *= zoom;/*from  ww  w .ja va  2s .c  om*/
    height *= zoom;
    RectF realRect = new RectF();
    realRect.set((x - width / 2) / zoom + panX, (y - height / 2) / zoom + panY, (x + width / 2) / zoom + panX,
            (y + height / 2) / zoom + panY);
    return realRect;
}

From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java

private void getLocationOnScreen(View view, RectF rectF) {
    final int[] location = new int[2];
    view.getLocationOnScreen(location);//  w  w  w. j a  va  2  s.c  o  m
    rectF.set(location[0], location[1], location[0] + view.getWidth(), location[1] + view.getHeight());
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

/**
 * ???l,r,t,b//from  w  w  w .  j a va  2  s .  co m
 *
 * @return
 */
private RectF getMatrixRectF() {

    Matrix matrix = mScaleMatrix;
    RectF rectF = new RectF();
    Drawable d = getDrawable();

    if (d != null) {

        rectF.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(rectF);
    }
    return rectF;
}