Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

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

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.ruesga.rview.widget.TagEditTextView.java

private Bitmap createTagChip(Tag tag) {
    // Create the tag string (prepend/append spaces to better ux). Create a clickable
    // area for deleting the tag in non-readonly mode
    String tagText = String.format(" %s " + (mReadOnly || !isEnabled() ? "" : CHIP_REMOVE_TEXT), tag.mTag);

    // Create a new color for the tag if necessary
    if (tag.mColor == 0) {
        if (mChipBackgroundColor == 0) {
            tag.mColor = newRandomColor();
        } else {//  w  w  w . j  a v a2  s .c  om
            tag.mColor = mChipBackgroundColor;
        }
    }
    mChipBgPaint.setColor((isEnabled()) ? tag.mColor : Color.LTGRAY);

    // Measure the chip rect
    Rect bounds = new Rect();
    mChipFgPaint.getTextBounds("|", 0, 1, bounds);
    int minHeight = bounds.height();
    mChipFgPaint.getTextBounds(tagText, 0, tagText.length(), bounds);
    int padding = (int) ONE_PIXEL * 2;
    int w = (int) (mChipFgPaint.measureText(tagText) + (padding * 2));
    int h = Math.max(bounds.height() + (padding * 4), minHeight + (padding * 4));
    float baseline = h / 2 + bounds.height() / 2;

    // Create the bitmap
    Bitmap bitmap = Bitmap.createBitmap(w + padding, h + padding, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // Draw the bitmap
    canvas.drawRoundRect(new RectF(0, (padding / 2), w, h), 6, 6, mChipBgPaint);
    canvas.drawText(tagText, (padding / 2), baseline, mChipFgPaint);
    return bitmap;
}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*from ww  w. j a  v  a 2 s. c o m*/
 * 
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = imageView.getWidth();
    final float viewHeight = imageView.getHeight();
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:com.jafme.mobile.activity.CropImageActivity.java

private void showCropper() {
    if (rotateBitmap == null)
        return;//from  w  w w . j  a v a 2s.  c  o  m

    HighlightView hv = new HighlightView(imageView);
    final int width = rotateBitmap.getWidth();
    final int height = rotateBitmap.getHeight();

    Rect imageRect = new Rect(0, 0, width, height);

    // Make the default size about 4/5 of the width or height
    int cropWidth = Math.min(width, height) * 4 / 5;
    int cropHeight = cropWidth;

    if (aspectX != 0 && aspectY != 0) {
        if (aspectX > aspectY) {
            cropHeight = cropWidth * aspectY / aspectX;
        } else {
            cropWidth = cropHeight * aspectX / aspectY;
        }
    }

    int x = (width - cropWidth) / 2;
    int y = (height - cropHeight) / 2;

    // FIXME -  ?   ? 

    RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);
    hv.setup(imageView.getUnrotatedMatrix(), imageRect, cropRect, aspectX != 0 && aspectY != 0);
    imageView.add(hv);

    if (imageView.highlightViews.size() == 1) {
        cropView = imageView.highlightViews.get(0);
        cropView.setFocus(true);
    }
}

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`. This
 * method should be called after the camera preview size is determined in setUpCameraOutputs and
 * also the size of `textureView` is fixed.
 *
 * @param viewWidth The width of `textureView`
 * @param viewHeight The height of `textureView`
 *//*from   w ww . j  a v  a 2 s  .  c  om*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private void setUpAlphaRect() {

    if (!mShowAlphaPanel)
        return;//from   w w  w . ja v a2  s  .co m

    final RectF dRect = mDrawingRect;

    final float left = dRect.left + BORDER_WIDTH_PX;
    final float top = dRect.bottom - ALPHA_PANEL_HEIGHT + BORDER_WIDTH_PX;
    final float bottom = dRect.bottom - BORDER_WIDTH_PX;
    final float right = dRect.right - BORDER_WIDTH_PX;

    mAlphaRect = new RectF(left, top, right, bottom);

    mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));
    mAlphaPattern.setBounds(Math.round(mAlphaRect.left), Math.round(mAlphaRect.top),
            Math.round(mAlphaRect.right), Math.round(mAlphaRect.bottom));

}

From source file:com.larvalabs.svgandroid.SVGParser.java

/**
 * Elliptical arc implementation based on the SVG specification notes
 * Adapted from the Batik library (Apache-2 license) by SAU
 *//*from w ww .j  a v  a 2 s .c o  m*/

private static void drawArc(Path path, double x0, double y0, double x, double y, double rx, double ry,
        double angle, boolean largeArcFlag, boolean sweepFlag) {
    double dx2 = (x0 - x) / 2.0;
    double dy2 = (y0 - y) / 2.0;
    angle = Math.toRadians(angle % 360.0);
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    double x1 = (cosAngle * dx2 + sinAngle * dy2);
    double y1 = (-sinAngle * dx2 + cosAngle * dy2);
    rx = Math.abs(rx);
    ry = Math.abs(ry);

    double Prx = rx * rx;
    double Pry = ry * ry;
    double Px1 = x1 * x1;
    double Py1 = y1 * y1;

    // check that radii are large enough
    double radiiCheck = Px1 / Prx + Py1 / Pry;
    if (radiiCheck > 1) {
        rx = Math.sqrt(radiiCheck) * rx;
        ry = Math.sqrt(radiiCheck) * ry;
        Prx = rx * rx;
        Pry = ry * ry;
    }

    // Step 2 : Compute (cx1, cy1)
    double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
    double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1));
    sq = (sq < 0) ? 0 : sq;
    double coef = (sign * Math.sqrt(sq));
    double cx1 = coef * ((rx * y1) / ry);
    double cy1 = coef * -((ry * x1) / rx);

    double sx2 = (x0 + x) / 2.0;
    double sy2 = (y0 + y) / 2.0;
    double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
    double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);

    // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
    double ux = (x1 - cx1) / rx;
    double uy = (y1 - cy1) / ry;
    double vx = (-x1 - cx1) / rx;
    double vy = (-y1 - cy1) / ry;
    double p, n;

    // Compute the angle start
    n = Math.sqrt((ux * ux) + (uy * uy));
    p = ux; // (1 * ux) + (0 * uy)
    sign = (uy < 0) ? -1.0 : 1.0;
    double angleStart = Math.toDegrees(sign * Math.acos(p / n));

    // Compute the angle extent
    n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
    p = ux * vx + uy * vy;
    sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
    double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
    if (!sweepFlag && angleExtent > 0) {
        angleExtent -= 360f;
    } else if (sweepFlag && angleExtent < 0) {
        angleExtent += 360f;
    }
    angleExtent %= 360f;
    angleStart %= 360f;

    RectF oval = new RectF((float) (cx - rx), (float) (cy - ry), (float) (cx + rx), (float) (cy + ry));
    path.addArc(oval, (float) angleStart, (float) angleExtent);
}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private void setUpHueRect() {

    final RectF dRect = mDrawingRect;

    final float left = dRect.right - HUE_PANEL_WIDTH + BORDER_WIDTH_PX;
    final float top = dRect.top + BORDER_WIDTH_PX;
    final float bottom = dRect.bottom - BORDER_WIDTH_PX
            - (mShowAlphaPanel ? PANEL_SPACING + ALPHA_PANEL_HEIGHT : 0);
    final float right = dRect.right - BORDER_WIDTH_PX;

    mHueRect = new RectF(left, top, right, bottom);
}

From source file:com.almalence.util.Util.java

public static Rect convertToDriverCoordinates(Rect rect) {
    RectF rectF = new RectF(rect.left, rect.top, rect.right, rect.bottom);
    mMeteringMatrix.mapRect(rectF);//from   w  ww.  ja  v  a  2s . c o  m
    Util.rectFToRect(rectF, rect);

    if (rect.left < -1000)
        rect.left = -1000;
    if (rect.left > 1000)
        rect.left = 1000;

    if (rect.right < -1000)
        rect.right = -1000;
    if (rect.right > 1000)
        rect.right = 1000;

    if (rect.top < -1000)
        rect.top = -1000;
    if (rect.top > 1000)
        rect.top = 1000;

    if (rect.bottom < -1000)
        rect.bottom = -1000;
    if (rect.bottom > 1000)
        rect.bottom = 1000;

    return rect;
}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private void setUpSatValRect() {

    final RectF dRect = mDrawingRect;
    float panelSide = dRect.height() - BORDER_WIDTH_PX * 2;

    if (mShowAlphaPanel) {
        panelSide -= PANEL_SPACING + ALPHA_PANEL_HEIGHT;
    }/*w  w w  .ja  v  a 2  s  . c o  m*/

    final float left = dRect.left + BORDER_WIDTH_PX;
    final float top = dRect.top + BORDER_WIDTH_PX;
    final float bottom = top + panelSide;
    final float right = left + panelSide;

    mSatValRect = new RectF(left, top, right, bottom);
}

From source file:com.bitflake.counter.HorizontalPicker.java

private void calculateItemSize(int w, int h) {

    int items = sideItems * 2 + 1;
    int totalPadding = ((int) dividerSize * (items - 1));
    itemWidth = (w - totalPadding) / items;

    itemClipBounds = new RectF(0, 0, itemWidth, h);
    itemClipBoundsOffset = new RectF(itemClipBounds);

    scrollToItem(selectedItem);// ww w  .j  a  va2s .c o m

    remakeLayout();
    startMarqueeIfNeeded();

}