Example usage for android.graphics RectF height

List of usage examples for android.graphics RectF height

Introduction

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

Prototype

public final float height() 

Source Link

Usage

From source file:Main.java

public static void drawTextCenter(Canvas canvas, RectF rectf, String s, Paint paint) {
    Rect rect = new Rect();
    paint.getTextBounds(s, 0, s.length(), rect);
    canvas.drawText(s, rectf.left + (rectf.width() - (float) rect.width()) / 2.0F,
            rectf.top + (rectf.height() + (float) rect.height()) / 2.0F, paint);
}

From source file:org.mozilla.gecko.gfx.RectUtils.java

public static RectF scale(RectF rect, float scale) {
    float x = rect.left * scale;
    float y = rect.top * scale;
    return new RectF(x, y, x + (rect.width() * scale), y + (rect.height() * scale));
}

From source file:Main.java

public static void drawRuleOfThird(Canvas canvas, RectF bounds) {
    Paint p = new Paint();
    p.setStyle(Paint.Style.STROKE);
    p.setColor(Color.argb(128, 255, 255, 255));
    p.setStrokeWidth(2);//  w  w w . java2s.com
    float stepX = bounds.width() / 3.0f;
    float stepY = bounds.height() / 3.0f;
    float x = bounds.left + stepX;
    float y = bounds.top + stepY;
    for (int i = 0; i < 2; i++) {
        canvas.drawLine(x, bounds.top, x, bounds.bottom, p);
        x += stepX;
    }
    for (int j = 0; j < 2; j++) {
        canvas.drawLine(bounds.left, y, bounds.right, y, p);
        y += stepY;
    }
}

From source file:Main.java

public static void drawTextCenter(Canvas canvas, RectF rectf, String s, String s1, Paint paint, Paint paint1) {
    Rect rect = new Rect();
    paint.getTextBounds(s, 0, s.length(), rect);
    float f = rectf.left + (rectf.width() - (float) rect.width()) / 2.0F;
    float f1 = rectf.top + (rectf.height() + (float) rect.height()) / 2.0F;
    canvas.drawText(s, f, f1, paint);//from w  ww .ja  v  a2  s . c om
    Rect rect1 = new Rect();
    paint1.getTextBounds(s, 0, s.length(), rect1);
    canvas.drawText(s1, 6F + (f + (float) rect.width()), (f1 - (float) rect.height()) + (float) rect1.height(),
            paint1);
}

From source file:android.support.wear.widget.util.ArcSwipe.java

public ArcSwipe(Gesture gesture, RectF bounds) {
    Preconditions.checkArgument(bounds.height() == bounds.width());
    mGesture = gesture;
    mBounds = bounds;
}

From source file:com.iped.ipcam.bitmapfun.ImageDetailFragment.java

protected void center(boolean horizontal, boolean vertical) {

    Matrix m = new Matrix();
    m.set(matrix);/*from  ww w  .  j a  v  a 2 s .  c o  m*/
    RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    m.mapRect(rect);
    float height = rect.height();
    float width = rect.width();
    float deltaX = 0, deltaY = 0;

    if (vertical) {
        int screenHeight = dm.heightPixels;
        if (height <= screenHeight) {
            deltaY = (screenHeight - height) / 2 - rect.top;
        } else if (rect.top > 0) {
            deltaY = -rect.top;
        } else if (rect.bottom < screenHeight) {
            deltaY = screenHeight - rect.bottom;
        }
    }

    if (horizontal) {
        int screenWidth = dm.widthPixels;
        if (width <= screenWidth) {
            deltaX = (screenWidth - width) / 2 - rect.left;
        } else if (rect.left > 0) {
            deltaX = -rect.left;
        } else if (rect.right < screenWidth) {
            deltaX = screenWidth - rect.right;
        }
    }
    matrix.postTranslate(deltaX, deltaY);
}

From source file:org.mozilla.gecko.gfx.ViewportMetrics.java

public PointF getOptimumViewportOffset(IntSize displayportSize) {
    /* XXX Until bug #524925 is fixed, changing the viewport origin will
     *     cause unnecessary relayouts. This may cause rendering time to
     *     increase and should be considered.
     *///from   w  w  w. j  a  v  a 2s. c o  m
    RectF viewport = getClampedViewport();

    FloatSize bufferSpace = new FloatSize(displayportSize.width - viewport.width(),
            displayportSize.height - viewport.height());
    PointF optimumOffset = new PointF(bufferSpace.width * ((mViewportBias.x + 1.0f) / 2.0f),
            bufferSpace.height * ((mViewportBias.y + 1.0f) / 2.0f));

    // Make sure this offset won't cause wasted pixels in the displayport
    // (i.e. make sure the resultant displayport intersects with the page
    //  as much as possible)
    if (viewport.left - optimumOffset.x < 0)
        optimumOffset.x = viewport.left;
    else if ((bufferSpace.width - optimumOffset.x) + viewport.right > mPageSize.width)
        optimumOffset.x = bufferSpace.width - (mPageSize.width - viewport.right);

    if (viewport.top - optimumOffset.y < 0)
        optimumOffset.y = viewport.top;
    else if ((bufferSpace.height - optimumOffset.y) + viewport.bottom > mPageSize.height)
        optimumOffset.y = bufferSpace.height - (mPageSize.height - viewport.bottom);

    return new PointF(Math.round(optimumOffset.x), Math.round(optimumOffset.y));
}

From source file:com.android.camera.HighlightView.java

private void growBy(float dx, float dy) {
    if (mMaintainAspectRatio) {
        if (dx != 0) {
            dy = dx / mInitialAspectRatio;
        } else if (dy != 0) {
            dx = dy * mInitialAspectRatio;
        }/* ww w  . j  ava  2s.  com*/
    }

    // Don't let the cropping rectangle grow too fast.
    // Grow at most half of the difference between the image rectangle and
    // the cropping rectangle.
    RectF r = new RectF(mCropRect);
    if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
        dx = (mImageRect.width() - r.width()) / 2F;
        if (mMaintainAspectRatio) {
            dy = dx / mInitialAspectRatio;
        }
    }
    if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
        dy = (mImageRect.height() - r.height()) / 2F;
        if (mMaintainAspectRatio) {
            dx = dy * mInitialAspectRatio;
        }
    }

    r.inset(-dx, -dy);

    // Don't let the cropping rectangle shrink too fast.
    final float widthCap = 25F;
    if (r.width() < widthCap) {
        r.inset(-(widthCap - r.width()) / 2F, 0F);
    }
    float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio) : widthCap;
    if (r.height() < heightCap) {
        r.inset(0F, -(heightCap - r.height()) / 2F);
    }

    // Put the cropping rectangle inside the image rectangle.
    if (r.left < mImageRect.left) {
        r.offset(mImageRect.left - r.left, 0F);
    } else if (r.right > mImageRect.right) {
        r.offset(-(r.right - mImageRect.right), 0);
    }
    if (r.top < mImageRect.top) {
        r.offset(0F, mImageRect.top - r.top);
    } else if (r.bottom > mImageRect.bottom) {
        r.offset(0F, -(r.bottom - mImageRect.bottom));
    }

    mCropRect.set(r);
    mDrawRect = computeLayout();
    mContext.invalidate();
}

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

/**
 * Given the source bitmap and a canvas, draws the bitmap through a circular
 * mask. Only draws a circle with diameter equal to the destination width.
 *
 * @param bitmap The source bitmap to draw.
 * @param canvas The canvas to draw it on.
 * @param source The source bound of the bitmap.
 * @param dest   The destination bound on the canvas.
 *///  w ww .j ava2s  .co m
public void drawBitmapWithCircleOnCanvas(Bitmap bitmap, Canvas canvas, RectF source, @NonNull RectF dest) {
    if (bitmap == null) {
        if (getStyle() == SHAPE_CIRCLE) {
            canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f,
                    mSolidColorPaint);
        } else {
            final float cornerRadius = getCalculatedCornerRadius();
            canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mSolidColorPaint);
        }
        return;
    }
    // Draw bitmap through shader first.
    final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mMatrix.reset();

    switch (getScaleType()) {
    case CENTER_CROP: {
        final float srcRatio = source.width() / source.height();
        final float dstRatio = dest.width() / dest.height();
        if (srcRatio > dstRatio) {
            // Source is wider than destination, fit height
            mTempDestination.top = dest.top;
            mTempDestination.bottom = dest.bottom;
            final float dstWidth = dest.height() * srcRatio;
            mTempDestination.left = dest.centerX() - dstWidth / 2;
            mTempDestination.right = dest.centerX() + dstWidth / 2;
        } else if (srcRatio < dstRatio) {
            mTempDestination.left = dest.left;
            mTempDestination.right = dest.right;
            final float dstHeight = dest.width() / srcRatio;
            mTempDestination.top = dest.centerY() - dstHeight / 2;
            mTempDestination.bottom = dest.centerY() + dstHeight / 2;
        } else {
            mTempDestination.set(dest);
        }
        break;
    }
    default: {
        mTempDestination.set(dest);
        break;
    }
    }

    // Fit bitmap to bounds.
    mMatrix.setRectToRect(source, mTempDestination, ScaleToFit.CENTER);

    shader.setLocalMatrix(mMatrix);
    mBitmapPaint.setShader(shader);

    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f,
                mBitmapPaint);
    } else {
        final float cornerRadius = getCalculatedCornerRadius();
        canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint);
    }
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

/**
 * Given the source bitmap and a canvas, draws the bitmap through a circular
 * mask. Only draws a circle with diameter equal to the destination width.
 *
 * @param bitmap The source bitmap to draw.
 * @param canvas The canvas to draw it on.
 * @param source The source bound of the bitmap.
 * @param dest   The destination bound on the canvas.
 *///w  w w  .ja  v a2s  .c  om
public void drawBitmapWithCircleOnCanvas(Bitmap bitmap, Canvas canvas, RectF source, @NonNull RectF dest) {
    if (bitmap == null) {
        if (getStyle() == SHAPE_CIRCLE) {
            canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f,
                    mSolidColorPaint);
        } else {
            final float cornerRadius = getCalculatedCornerRadius();
            canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mSolidColorPaint);
        }
        return;
    }
    // Draw bitmap through shader first.
    final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mMatrix.reset();

    switch (getScaleType()) {
    case CENTER_CROP: {
        final float srcRatio = source.width() / source.height();
        final float dstRatio = dest.width() / dest.height();
        if (srcRatio > dstRatio) {
            // Source is wider than destination, fit height
            mTempDestination.top = dest.top;
            mTempDestination.bottom = dest.bottom;
            final float dstWidth = dest.height() * srcRatio;
            mTempDestination.left = dest.centerX() - dstWidth / 2;
            mTempDestination.right = dest.centerX() + dstWidth / 2;
        } else if (srcRatio < dstRatio) {
            mTempDestination.left = dest.left;
            mTempDestination.right = dest.right;
            final float dstHeight = dest.width() / srcRatio;
            mTempDestination.top = dest.centerY() - dstHeight / 2;
            mTempDestination.bottom = dest.centerY() + dstHeight / 2;
        } else {
            mTempDestination.set(dest);
        }
        break;
    }
    default: {
        mTempDestination.set(dest);
        break;
    }
    }

    // Fit bitmap to bounds.
    mMatrix.setRectToRect(source, mTempDestination, ScaleToFit.CENTER);

    shader.setLocalMatrix(mMatrix);
    mBitmapPaint.setShader(shader);

    if (mBorderEnabled) {
        final float inset = mBorderPaint.getStrokeWidth() / 2;
        if (getStyle() == SHAPE_CIRCLE) {
            final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - inset / 2;
            canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint);
        } else {
            final float cornerRadius = getCalculatedCornerRadius();
            dest.inset(inset, inset);
            canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint);
            dest.inset(-inset, -inset);
        }
    } else {
        if (getStyle() == SHAPE_CIRCLE) {
            final float circleRadius = Math.min(dest.width(), dest.height()) / 2f;
            canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint);
        } else {
            final float cornerRadius = getCalculatedCornerRadius();
            canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint);
        }
    }

}