private void drawCircle(Canvas canvas, int leftX, int topY,
                            boolean partOfPattern) {
        Bitmap outerCircle;
        Bitmap innerCircle;

        if (!partOfPattern
                || (inStealthMode && patternDisplayMode == DisplayMode.Correct)
                || (inErrorStealthMode && patternDisplayMode == DisplayMode.Wrong)) {
            // unselected circle
            outerCircle = bitmapCircleDefault;
            innerCircle = bitmapBtnDefault;
        } else if (patternInProgress) {
            // user is in middle of drawing a pattern
            outerCircle = bitmapCircleSelected;
            innerCircle = bitmapBtnTouched;
        } else if (patternDisplayMode == DisplayMode.Wrong) {
            // the pattern is wrong
            outerCircle = bitmapCircleRed;
            innerCircle = bitmapBtnDefault;
        } else if (patternDisplayMode == DisplayMode.Correct
                || patternDisplayMode == DisplayMode.Animate) {
            // the pattern is correct
            outerCircle = bitmapCircleSelected;
            innerCircle = bitmapBtnDefault;
        } else {
            throw new IllegalStateException("unknown display mode "
                    + patternDisplayMode);
        }

        final int width = bitmapWidth;
        final int height = bitmapHeight;

        final float squareWidth = this.squareWidth;
        final float squareHeight = this.squareHeight;

        int offsetX = (int) ((squareWidth - width) / 2f);
        int offsetY = (int) ((squareHeight - height) / 2f);

        // Allow circles to shrink if the view is too small to hold them.
        float sx = Math.min(this.squareWidth / bitmapWidth, 1.0f);
        float sy = Math.min(this.squareHeight / bitmapHeight, 1.0f);

        circleMatrix.setTranslate(leftX + offsetX, topY + offsetY);
        circleMatrix.preTranslate(bitmapWidth / 2, bitmapHeight / 2);
        circleMatrix.preScale(sx, sy);
        circleMatrix.preTranslate(-bitmapWidth / 2, -bitmapHeight / 2);

        canvas.drawBitmap(outerCircle, circleMatrix, circlePaint);
        canvas.drawBitmap(innerCircle, circleMatrix, dotPaint);
    }
@param canvas
@param leftX
@param topY
@param partOfPattern Whether this circle is part of the pattern.
android-patternview/src/main/java/com/eftimoff/patternview/PatternView.java