package retrobox.themes;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;

/*
 * From http://betaful.com/post/82668809883/programmatic-shapes-in-android
 */

public class CustomShapeDrawable extends ShapeDrawable {
	Paint fillPaint;
	Paint strokePaint;
	private int strokeWidth;

	public CustomShapeDrawable(Shape s, int fillColor, int strokeColor, int strokeWidth) {
		super(s);
        fillPaint = new Paint(this.getPaint());
        fillPaint.setColor(fillColor);
        strokePaint = new Paint(fillPaint);
        strokePaint.setStyle(Paint.Style.STROKE);
        strokePaint.setStrokeWidth(strokeWidth);
        strokePaint.setColor(strokeColor);
        this.strokeWidth = strokeWidth;
	}

	public CustomShapeDrawable(Shape s) {
		this(s, 0, 0, 0);
	}

	@Override
    protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
		canvas.save();
		
		// shape.resize(canvas.getClipBounds().right, canvas.getClipBounds().bottom);
	    shape.draw(canvas, fillPaint);

	    Matrix matrix = new Matrix();
	    matrix.setRectToRect(new RectF(0, 0, 
	    		canvas.getClipBounds().right,
	            canvas.getClipBounds().bottom),
	            new RectF(strokeWidth/2, strokeWidth/2, canvas.getClipBounds().right - strokeWidth/2,
	                    canvas.getClipBounds().bottom - strokeWidth/2),
	            Matrix.ScaleToFit.FILL);
	    
	    canvas.concat(matrix);
	    shape.draw(canvas, strokePaint);
	    
	    canvas.restore();
	}
}

@@ -625,32 +625,73 @@
 lor(fillColor);%0A
+        if (strokeColor != fillColor) %7B%0A%09
         strokePa
@@ -718,16 +718,17 @@
 Paint);%0A
+%09
         
@@ -769,16 +769,17 @@
 TROKE);%0A
+%09
         
@@ -819,16 +819,17 @@
 Width);%0A
+%09
         
@@ -855,32 +855,33 @@
 r(strokeColor);%0A
+%09
         this.str
@@ -904,16 +904,26 @@
 eWidth;%0A
+        %7D%0A
 %09%7D%0A%0A%09pub
@@ -1595,32 +1595,65 @@
 t(matrix);%0A%09    
+if (strokePaint != null) %7B%0A%09    %09
 shape.draw(canva
@@ -1665,24 +1665,31 @@
 rokePaint);%0A
+%09    %7D%0A
 %09    %0A%09    c

Use stroke only if different from fill