Example usage for android.graphics Matrix isIdentity

List of usage examples for android.graphics Matrix isIdentity

Introduction

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

Prototype

public boolean isIdentity() 

Source Link

Document

Returns true if the matrix is identity.

Usage

From source file:Main.java

/**
 * Creates a mutable bitmap from subset of source bitmap, transformed by the optional matrix.
 *//*ww  w . j a v  a2s .c o m*/
private static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m) {
    // Re-implement Bitmap createBitmap() to always return a mutable bitmap.
    Canvas canvas = new Canvas();

    Bitmap bitmap;
    Paint paint;
    if ((m == null) || m.isIdentity()) {
        bitmap = Bitmap.createBitmap(width, height, source.getConfig());
        paint = null;
    } else {
        RectF rect = new RectF(0, 0, width, height);
        m.mapRect(rect);
        bitmap = Bitmap.createBitmap(Math.round(rect.width()), Math.round(rect.height()), source.getConfig());

        canvas.translate(-rect.left, -rect.top);
        canvas.concat(m);

        paint = new Paint(Paint.FILTER_BITMAP_FLAG);
        if (!m.rectStaysRect()) {
            paint.setAntiAlias(true);
        }
    }
    bitmap.setDensity(source.getDensity());
    canvas.setBitmap(bitmap);

    Rect srcBounds = new Rect(x, y, x + width, y + height);
    RectF dstBounds = new RectF(0, 0, width, height);
    canvas.drawBitmap(source, srcBounds, dstBounds, paint);
    return bitmap;
}

From source file:Main.java

private static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, float offset,
        boolean clipShadow, Paint paint) {

    int scaledWidth = width;
    int scaledHeight = height;

    final Canvas canvas = new Canvas();
    canvas.translate(offset / 2.0f, offset / 2.0f);

    Bitmap bitmap;/*from   w  w  w.  j a v  a2  s . c  om*/

    final Rect from = new Rect(x, y, x + width, y + height);
    final RectF to = new RectF(0, 0, width, height);

    if (m == null || m.isIdentity()) {
        bitmap = Bitmap.createBitmap(scaledWidth + (int) offset,
                scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset), Bitmap.Config.ARGB_8888);
        paint = null;
    } else {
        RectF mapped = new RectF();
        m.mapRect(mapped, to);

        scaledWidth = Math.round(mapped.width());
        scaledHeight = Math.round(mapped.height());

        bitmap = Bitmap.createBitmap(scaledWidth + (int) offset,
                scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset), Bitmap.Config.ARGB_8888);
        canvas.translate(-mapped.left, -mapped.top);
        canvas.concat(m);
    }

    canvas.setBitmap(bitmap);
    canvas.drawRect(0.0f, 0.0f, width, height, paint);
    canvas.drawBitmap(source, from, to, SCALE_PAINT);

    return bitmap;
}

From source file:android.support.transition.ChangeTransform.java

private void captureValues(TransitionValues transitionValues) {
    View view = transitionValues.view;
    if (view.getVisibility() == View.GONE) {
        return;//from  ww  w .j  a  va2 s . c om
    }
    transitionValues.values.put(PROPNAME_PARENT, view.getParent());
    Transforms transforms = new Transforms(view);
    transitionValues.values.put(PROPNAME_TRANSFORMS, transforms);
    Matrix matrix = view.getMatrix();
    if (matrix == null || matrix.isIdentity()) {
        matrix = null;
    } else {
        matrix = new Matrix(matrix);
    }
    transitionValues.values.put(PROPNAME_MATRIX, matrix);
    if (mReparent) {
        Matrix parentMatrix = new Matrix();
        ViewGroup parent = (ViewGroup) view.getParent();
        ViewUtils.transformMatrixToGlobal(parent, parentMatrix);
        parentMatrix.preTranslate(-parent.getScrollX(), -parent.getScrollY());
        transitionValues.values.put(PROPNAME_PARENT_MATRIX, parentMatrix);
        transitionValues.values.put(PROPNAME_INTERMEDIATE_MATRIX, view.getTag(R.id.transition_transform));
        transitionValues.values.put(PROPNAME_INTERMEDIATE_PARENT_MATRIX, view.getTag(R.id.parent_matrix));
    }
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

public void setImageMatrix(Matrix m) {
    if (m != null && m.isIdentity()) {
        m = null;/*w w  w . java2  s  . c o  m*/
    }

    // don't invalidate unless we're actually changing our matrix
    if (m == null && !this.mMatrix.isIdentity() || m != null && !this.mMatrix.equals(m)) {
        this.mMatrix.set(m);
        invalidate();
    }
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

@Override
public void setImageMatrix(Matrix matrix) {
    Matrix current = getImageMatrix();
    boolean needUpdate = false;

    if (matrix == null && !current.isIdentity() || matrix != null && !current.equals(matrix)) {
        needUpdate = true;//from  www.  j a  va2 s . c om
    }

    super.setImageMatrix(matrix);
    if (needUpdate) {
        onImageMatrixChanged();
    }
}

From source file:com.pdftron.pdf.tools.Tool.java

public void onDraw(Canvas canvas, android.graphics.Matrix tfm) {
    // Draw page number
    if (mShowPageNum && mPageNumberIndicatorVisible) {
        int width = mPDFView.getWidth();
        int height = mPDFView.getHeight();
        int page_num = mPDFView.getCurrentPage();
        boolean restore = false;
        float yOffset = 0;

        try {//from ww w. jav a2 s  .  c om
            // During page sliding, PDFViewCtrl might apply extra transformation
            // matrix to Canvas for animation. However, page number should not
            // move; hence applying the inverse to offset it.
            if (!tfm.isIdentity()) {
                canvas.save();
                restore = true;
                tfm.invert(mTempMtx1);
                canvas.getMatrix(mTempMtx2);
                mTempMtx2.postConcat(mTempMtx1);
                canvas.setMatrix(mTempMtx2);

                // Workaround for bug found in Android > ICS with hardware acceleration turned
                // ON. See http://code.google.com/p/android/issues/detail?id=24517 for more info
                if (Build.VERSION.SDK_INT >= 14
                        /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ && mPDFView.isHardwareAccelerated()) {
                    Rect rectangle = new Rect();
                    ((android.app.Activity) mPDFView.getContext()).getWindow().getDecorView()
                            .getWindowVisibleDisplayFrame(rectangle);
                    yOffset = rectangle.top;
                }
            }

            int page_count = mPDFView.getDoc().getPageCount();
            String str = String.format(getStringFromResId(R.string.tools_misc_pagerange), page_num, page_count);

            Rect r = new Rect();
            mPaint4PageNum.getTextBounds(str, 0, str.length(), r);
            float str_width = r.width();
            float str_height = r.height();

            float margin = str_height / 1.5f;
            float left = width - str_width * 1.5f - margin + mPDFView.getScrollX();

            float top = mPDFView.getScrollY() + height - mPageNumPosAdjust - str_height * 3.0f + yOffset;

            float right = left + str_width + margin * 2;
            float bottom = top + str_height + margin * 2;

            mTempPageDrawingRectF.set(left, top, right, bottom);
            mPaint4PageNum.setColor(
                    mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_background));
            canvas.drawRoundRect(mTempPageDrawingRectF, margin, margin, mPaint4PageNum);

            mPaint4PageNum
                    .setColor(mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_text));
            left += margin;
            top += str_height / 2 + margin + mPaint4PageNum.descent();

            canvas.drawText(str, left, top - 0.5f, mPaint4PageNum);

        } catch (Exception e) {

        } finally {
            if (restore) {
                canvas.restore();
            }
        }
    }
}