Code example for Matrix

Methods: mapRect, postScale, postTranslate, reset

0
 
        // use a rectangle at 0,0 to make sure we don't run into issues with scaling 
        r.set(0, 0, w, h);
 
        final Matrix m = mTempMatrix;
        m.reset();
        transformMatrix(m, view);
        mTempMatrix.mapRect(r);
 
        r.offset(view.getLeft(), view.getTop());
 
        // Straighten coords if rotations flipped them 
        if (r.right < r.left) {
            final float f = r.right;
            r.right = r.left;
            r.left = f;
        } 
        if (r.bottom < r.top) {
            final float f = r.top;
            r.top = r.bottom;
            r.bottom = f;
        } 
    } 
 
    private void transformMatrix(Matrix m, View view) {
        final float w = view.getWidth();
        final float h = view.getHeight();
 
        final float sX = mScaleX;
        final float sY = mScaleY;
        if ((sX != 1.0f) || (sY != 1.0f)) {
            final float deltaSX = ((sX * w) - w) / 2f;
            final float deltaSY = ((sY * h) - h) / 2f;
            m.postScale(sX, sY);
            m.postTranslate(-deltaSX, -deltaSY);
        } 
        m.postTranslate(mTranslationX, mTranslationY);
    } 
 
    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        View view = mView.get();