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.ycl.framework.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*w  ww.java  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 = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    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:dev.dworks.libs.actionbarplus.widget.PhotoView.java

/**
 * Generates the initial transformation matrix for drawing. Additionally, it sets the
 * minimum and maximum scale values.//from   w  w w  . ja v a 2 s . co  m
 */
private void generateMatrix() {
    final int dwidth = mDrawable.getIntrinsicWidth();
    final int dheight = mDrawable.getIntrinsicHeight();

    final int vwidth = mAllowCrop ? sCropSize : getWidth();
    final int vheight = mAllowCrop ? sCropSize : getHeight();

    final boolean fits = (dwidth < 0 || vwidth == dwidth) && (dheight < 0 || vheight == dheight);

    if (fits && !mAllowCrop) {
        mMatrix.reset();
    } else {
        // Generate the required transforms for the photo
        mTempSrc.set(0, 0, dwidth, dheight);
        if (mAllowCrop) {
            mTempDst.set(mCropRect);
        } else {
            mTempDst.set(0, 0, vwidth, vheight);
        }
        RectF scaledDestination = new RectF((vwidth / 2) - (dwidth * mMaxInitialScaleFactor / 2),
                (vheight / 2) - (dheight * mMaxInitialScaleFactor / 2),
                (vwidth / 2) + (dwidth * mMaxInitialScaleFactor / 2),
                (vheight / 2) + (dheight * mMaxInitialScaleFactor / 2));
        if (mTempDst.contains(scaledDestination)) {
            mMatrix.setRectToRect(mTempSrc, scaledDestination, Matrix.ScaleToFit.CENTER);
        } else {
            mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
        }
    }

    mOriginalMatrix.set(mMatrix);
}

From source file:com.android.volley.ui.PhotoView.java

/**
 * Generates the initial transformation matrix for drawing. Additionally, it sets the
 * minimum and maximum scale values./* www  . j  av  a 2s .c o  m*/
 */
private void generateMatrix() {
    final int dwidth = mDrawable.getIntrinsicWidth();
    final int dheight = mDrawable.getIntrinsicHeight();

    final int vwidth = mAllowCrop ? sCropSize : getWidth();
    final int vheight = mAllowCrop ? sCropSize : getHeight();

    final boolean fits = (dwidth < 0 || vwidth == dwidth) && (dheight < 0 || vheight == dheight);

    if (fits && !mAllowCrop) {
        mMatrix.reset();
    } else {
        // Generate the required transforms for the photo
        mTempSrc.set(0, 0, dwidth, dheight);
        if (mAllowCrop) {
            mTempDst.set(mCropRect);
        } else {
            mTempDst.set(0, 0, vwidth, vheight);
        }
        RectF scaledDestination = new RectF((vwidth / 2) - (dwidth * mMaxInitialScaleFactor / 2),
                (vheight / 2) - (dheight * mMaxInitialScaleFactor / 2),
                (vwidth / 2) + (dwidth * mMaxInitialScaleFactor / 2),
                (vheight / 2) + (dheight * mMaxInitialScaleFactor / 2));
        if (mTempDst.contains(scaledDestination)) {
            mMatrix.setRectToRect(mTempSrc, scaledDestination, Matrix.ScaleToFit.CENTER);
        } else {
            mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
        }
    }
    mOriginalMatrix.set(mMatrix);
}

From source file:com.Yamate.Camera.Camera.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//* w w w.  j  av  a  2  s .  c  om*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = mActivity;
    if (null == mPreviewSize || 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, mPreviewSize.getHeight(), mPreviewSize.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 / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.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);
    }
    //mTextureView.setTransform(matrix);
}

From source file:com.mysampleapp.camera.Camera2BasicFragment.java

/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from www.  j  av a 2s .  c  o m
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || 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, mPreviewSize.getHeight(), mPreviewSize.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 / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.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);
    }
    mTextureView.setTransform(matrix);

}

From source file:com.example.photoviewlib.PhotoViewAttacher.java

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

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    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, 0);

    } 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);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        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.example.jh.zoomlibrary.PhotoViewAttacher.java

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

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    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);
        //?0
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, 0);

    } 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);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        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.zero.pictureselect.Photoview.PhotoViewAttacher.java

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

    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    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);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        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:cl.monsoon.s1next.widget.PhotoView.java

/**
 * Generates the initial transformation matrix for drawing. Additionally, it sets the
 * minimum and maximum scale values.//from   ww w  . j  a  v a2 s .  co m
 */
private void generateMatrix() {
    final int dWidth = mDrawable.getIntrinsicWidth();
    final int dHeight = mDrawable.getIntrinsicHeight();

    final int vWidth = mAllowCrop ? sCropSize : getWidth();
    final int vHeight = mAllowCrop ? sCropSize : getHeight();

    final boolean fits = (dWidth < 0 || vWidth == dWidth) && (dHeight < 0 || vHeight == dHeight);

    if (fits && !mAllowCrop) {
        mMatrix.reset();
    } else {
        // Generate the required transforms for the photo
        mTempSrc.set(0, 0, dWidth, dHeight);
        if (mAllowCrop) {
            mTempDst.set(mCropRect);
        } else {
            mTempDst.set(0, 0, vWidth, vHeight);
        }
        RectF scaledDestination = new RectF((vWidth / 2) - (dWidth * mMaxInitialScaleFactor / 2),
                (vHeight / 2) - (dHeight * mMaxInitialScaleFactor / 2),
                (vWidth / 2) + (dWidth * mMaxInitialScaleFactor / 2),
                (vHeight / 2) + (dHeight * mMaxInitialScaleFactor / 2));
        if (mTempDst.contains(scaledDestination)) {
            mMatrix.setRectToRect(mTempSrc, scaledDestination, Matrix.ScaleToFit.CENTER);
        } else {
            mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
        }
    }
    mOriginalMatrix.set(mMatrix);
}

From source file:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/*from  w  w  w  .j  a va 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 = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    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);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        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();
}