Example usage for android.graphics RectF isEmpty

List of usage examples for android.graphics RectF isEmpty

Introduction

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

Prototype

public final boolean isEmpty() 

Source Link

Document

Returns true if the rectangle is empty (left >= right or top >= bottom)

Usage

From source file:Main.java

/**
 * Gets the proper scale value that scales down the content and keeps its aspect ratio to
 * display inside the view.//from  w w w . jav a 2  s . c o  m
 */
public static float getDisplayScale(RectF contentBounds, View view) {
    if (contentBounds.isEmpty()) {
        return 1;
    }

    float scale = Math.min(view.getWidth() / contentBounds.width(), view.getHeight() / contentBounds.height());
    // Avoid scaling up the content.
    return Math.min(scale, 1);
}

From source file:Main.java

/**
 * Gets straighten matrix for the given bounds and degrees.
 *//*from  w  w  w  .ja  v  a2  s.c  o m*/
public static void getStraightenMatrix(RectF bounds, float degrees, Matrix matrix) {
    matrix.reset();
    if ((degrees != 0) && !bounds.isEmpty()) {
        float w = bounds.width() / 2;
        float h = bounds.height() / 2;
        float adjustAngle;
        if ((degrees < 0 && w > h) || (degrees > 0 && w <= h)) {
            // The top left point is the boundary.
            adjustAngle = (float) Math.atan(h / -w) + MATH_PI + degrees * DEGREES_TO_RADIAN;
        } else {
            // The top right point is the boundary.
            adjustAngle = (float) Math.atan(h / w) - MATH_PI + degrees * DEGREES_TO_RADIAN;
        }
        float radius = (float) Math.hypot(w, h);
        float scaleX = (float) Math.abs(radius * Math.cos(adjustAngle)) / w;
        float scaleY = (float) Math.abs(radius * Math.sin(adjustAngle)) / h;
        float scale = Math.max(scaleX, scaleY);

        postRotateMatrix(degrees, new RectF(bounds), matrix);
        matrix.postScale(scale, scale);
    }
}

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

private void adjustScale() {
    final int iWidth = mImageWidth;
    final int iHeight = mImageHeight;
    if (iWidth <= 0 || iHeight <= 0) {
        return;/*  w  w w.j  ava 2  s .c om*/
    }
    final RectF dst = mDst;
    if (dst.isEmpty()) {
        return;
    }

    final float oldScale = mScale;
    mScale = clamp(oldScale, mMinScale, mMaxScale);
    if (oldScale == mScale) {
        return;
    }

    dst.right = dst.left + mScale * iWidth;
    dst.bottom = dst.top + mScale * iHeight;
    mRectDirty = true;
}

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

private void fling(float velocityX, float velocityY) {
    final int wWidth = mWindowWidth;
    final int wHeight = mWindowHeight;
    if (wWidth <= 0 || wHeight <= 0) {
        return;//  w w w .  j a va2 s . c  o m
    }
    final RectF dst = mDst;
    if (dst.isEmpty()) {
        return;
    }

    final float minX, maxX;
    final float minY, maxY;

    minX = (dst.right > wWidth) ? (wWidth - dst.right) : 0;
    maxX = dst.left < 0 ? -dst.left : 0;
    minY = (dst.bottom > wHeight) ? (wHeight - dst.bottom) : 0;
    maxY = dst.top < 0 ? -dst.top : 0;

    if (mImageFling == null) {
        mImageFling = new ImageFling(this);
    }
    mImageFling.startFling(velocityX, minX, maxX, velocityY, minY, maxY);
}

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

public void renderBitmap() {
    Log.d("RenderBitmap", "Rendering bitmap!!!");
    ImageView iv = getImageView();
    if (iv != null) {
        RectF rect = getDisplayRect();
        if (rect == null || rect.isEmpty()) {
            rect = new RectF(0, 0, originalBitmapSize.x, originalBitmapSize.y);
        }//from  www.j a va  2 s . c  o  m

        float ratioX = originalBitmapSize.x / (float) iv.getWidth();
        float ratioY = originalBitmapSize.y / (float) iv.getHeight();

        rect.set(rect.left * ratioX, rect.top * ratioY, rect.right * ratioX, rect.bottom * ratioY);
        Rect bounds = new Rect();
        rect.round(bounds);

        Bitmap bitmap = Bitmap.createBitmap(originalBitmapSize.x, originalBitmapSize.y,
                Bitmap.Config.ARGB_8888);
        pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageIndex, bounds.left, bounds.top, bounds.width(),
                bounds.height());
        iv.setImageBitmap(bitmap);
    }
}