Code example for Matrix

Methods: preRotate, preScale, preTranslate, setTranslate

0
        final float angle = (float) Math.toDegrees(theta) + 90.0f;
 
        // compose matrix 
        float sx = Math.min(mSquareWidth / mBitmapWidth, 1.0f);
        float sy = Math.min(mSquareHeight / mBitmapHeight, 1.0f);
        mArrowMatrix.setTranslate(leftX + offsetX, topY + offsetY); // transform to cell position
        mArrowMatrix.preTranslate(mBitmapWidth/2, mBitmapHeight/2);
        mArrowMatrix.preScale(sx, sy);
        mArrowMatrix.preTranslate(-mBitmapWidth/2, -mBitmapHeight/2);
        mArrowMatrix.preRotate(angle, cellWidth / 2.0f, cellHeight / 2.0f);  // rotate about cell center
        mArrowMatrix.preTranslate((cellWidth - arrow.getWidth()) / 2.0f, 0.0f); // translate to 12:00 pos
        canvas.drawBitmap(arrow, mArrowMatrix, mPaint);
    } 
 
    /** 
     * @param canvas 
     * @param leftX 
     * @param topY 
     * @param partOfPattern Whether this circle is part of the pattern. 
     */ 
    private void drawCircle(Canvas canvas, int leftX, int topY, boolean partOfPattern) {