Code example for Matrix

Methods: postRotate, postTranslate, setScale

0
        } 
 
        if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS)
                || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
            Paint p = new Paint();
            Matrix matrix = new Matrix();
            // use use a height of 1, and then wack the matrix each time we 
            // actually use it. 
            Shader fade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
            // PULL OUT THIS CONSTANT 
 
            p.setShader(fade);
 
            // draw the fade effect 
            boolean drawTop = false;
            boolean drawBottom = false;
            boolean drawLeft = false;
            boolean drawRight = false;
 
            float topFadeStrength = 0.0f;
            float bottomFadeStrength = 0.0f;
            float leftFadeStrength = 0.0f;
            float rightFadeStrength = 0.0f;
 
            final float fadeHeight = mFadingEdgeLength;
            int length = (int) fadeHeight;
 
            // clip the fade length if top and bottom fades overlap 
            // overlapping fades produce odd-looking artifacts 
            if (mIsVertical && (top + length > bottom - length)) {
                length = (bottom - top) / 2;
            } 
 
            // also clip horizontal fades if necessary 
            if (!mIsVertical && (left + length > right - length)) {
                length = (right - left) / 2;
            } 
 
            if (mIsVertical) {
                topFadeStrength = Math.max(0.0f, Math.min(1.0f, topFadingEdgeStrength));
                drawTop = topFadeStrength * fadeHeight > 1.0f;
                bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, bottomFadingEdgeStrength));
                drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
            } 
 
            if (!mIsVertical) {
                leftFadeStrength = Math.max(0.0f, Math.min(1.0f, leftFadingEdgeStrength));
                drawLeft = leftFadeStrength * fadeHeight > 1.0f;
                rightFadeStrength = Math.max(0.0f, Math.min(1.0f, rightFadingEdgeStrength));
                drawRight = rightFadeStrength * fadeHeight > 1.0f;
            } 
 
            if (drawTop) {
                matrix.setScale(1, fadeHeight * topFadeStrength);
                matrix.postTranslate(left, top);
                fade.setLocalMatrix(matrix);
                canvas.drawRect(left, top, right, top + length, p);
            } 
 
            if (drawBottom) {
                matrix.setScale(1, fadeHeight * bottomFadeStrength);
                matrix.postRotate(180);
                matrix.postTranslate(left, bottom);
                fade.setLocalMatrix(matrix);
                canvas.drawRect(left, bottom - length, right, bottom, p);
            } 
 
            if (drawLeft) {
                matrix.setScale(1, fadeHeight * leftFadeStrength);
                matrix.postRotate(-90);
                matrix.postTranslate(left, top);
                fade.setLocalMatrix(matrix);
                canvas.drawRect(left, top, left + length, bottom, p);
            } 
 
            if (drawRight) {
                matrix.setScale(1, fadeHeight * rightFadeStrength);
                matrix.postRotate(90);
                matrix.postTranslate(right, top);
                fade.setLocalMatrix(matrix);
                canvas.drawRect(right - length, top, right, bottom, p);
            } 
        } 
    }