public class CustomBorderDrawable extends ShapeDrawable { private Paint fillpaint, strokepaint; private static final int WIDTH = 3; public CustomBorderDrawable(Shape s) { super(s); fillpaint = this.getPaint(); strokepaint = new Paint(fillpaint); strokepaint.setStyle(Paint.Style.STROKE); strokepaint.setStrokeWidth(WIDTH); strokepaint.setARGB(255, 0, 0, 0); } @Override protected void onDraw(Shape shape, Canvas canvas, Paint fillpaint) { shape.draw(canvas, fillpaint); shape.draw(canvas, strokepaint); } public void setFillColour(int c){ fillpaint.setColor(c); } }
public ShapeAssert hasHeight(float height) { isNotNull(); float actualHeight = actual.getHeight(); assertThat(actualHeight) // .overridingErrorMessage("Expected height <%s> but was <%s>.", height, actualHeight) // .isEqualTo(height); return this; }
public ShapeAssert hasWidth(float width) { isNotNull(); float actualHeight = actual.getWidth(); assertThat(actualHeight) // .overridingErrorMessage("Expected width <%s> but was <%s>.", width, actualHeight) // .isEqualTo(width); return this; }
@Override public void onBoundsChange(Rect bounds){ if(mDrawingContent != null){ mDrawingContent.setBounds(0, 0, bounds.width(), bounds.height()); } if(mMask != null){ mMask.resize(bounds.width(), bounds.height()); } recreateBitmap(); }
void drawAll() { for (Shape s : heterogeneousCollection) { s.draw(); // common function present in Shape also s.doSomethingSpecific(); // specific to each implementation } }
public ShapeAssert hasAlpha() { isNotNull(); assertThat(actual.hasAlpha()) // .overridingErrorMessage("Expected to have alpha but did not.") // .isTrue(); return this; }
public void resizeShape(final float width,final float height){ shape.getShape().resize(width,height); } public ShapeHolder(ShapeDrawable s) {
public ShapeAssert hasNoAlpha() { isNotNull(); assertThat(actual.hasAlpha()) // .overridingErrorMessage("Expected to not have alpha but did.") // .isFalse(); return this; } }
public static void main(String[] args){ int x = getFromPropertyFile(); Shape shape = getShape(x); // Shape obtained from a factory method shape.draw(); //Runtime polymorphism }
public void setMask(Shape mask){ mMask = mask; mMask.resize(getBounds().width(), getBounds().height()); recreateBitmap(); invalidateSelf(); }
public float getWidth() { return shape.getShape().getWidth(); } public void setWidth(float width) {
public float getHeight() { return shape.getShape().getHeight(); } public void setHeight(float height) {
public ShapeAssert hasAlpha() { isNotNull(); assertThat(actual.hasAlpha()) // .overridingErrorMessage("Expected to have alpha but did not.") // .isTrue(); return this; }