diff --git a/app/src/main/java/com/codigoparallevar/minicards/DrawView.java b/app/src/main/java/com/codigoparallevar/minicards/DrawView.java index c99e47c..5c403cd 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/DrawView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/DrawView.java @@ -4,20 +4,34 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.util.Log; import android.view.View; +import com.codigoparallevar.minicards.parts.Part; +import com.codigoparallevar.minicards.parts.Placeholder; +import com.codigoparallevar.minicards.parts.buttons.RoundButton; + +import java.util.LinkedList; +import java.util.List; + class DrawView extends View { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + List parts = new LinkedList<>(); public DrawView(Context context) { super(context); paint.setColor(Color.RED); + parts.add(new RoundButton(500, 1200, 80, 100)); } @Override public void onDraw(Canvas canvas){ - canvas.drawLine(0, 0, 20, 20, paint); - canvas.drawLine(20, 0, 0, 20, paint); + long time = System.currentTimeMillis(); + for (Part part : parts){ + part.draw(canvas); + } + + Log.d("Render time", System.currentTimeMillis() - time + "ms"); } } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java b/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java new file mode 100644 index 0000000..b4923ac --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/Part.java @@ -0,0 +1,12 @@ +package com.codigoparallevar.minicards.parts; + +import android.graphics.Canvas; + +public interface Part { + public int getLeft(); + public int getRight(); + public int getTop(); + public int getBottom(); + + public void draw(Canvas canvas); +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java b/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java new file mode 100644 index 0000000..1ea1d62 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/Placeholder.java @@ -0,0 +1,58 @@ +package com.codigoparallevar.minicards.parts; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; + +public class Placeholder implements Part { + private final int _left; + private final int _top; + private final int _right; + private final int _bottom; + + public Placeholder(int left, int top, int right, int bottom) { + _left = left; + _top = top; + _right = right; + _bottom = bottom; + } + + @Override + public int getLeft() { + return _left; + } + + @Override + public int getRight() { + return _right; + } + + @Override + public int getTop() { + return _top; + } + + @Override + public int getBottom() { + return _bottom; + } + + @Override + public void draw(Canvas canvas) { + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setColor(Color.WHITE); + + // Top + canvas.drawLine(_left,_top, _right, _top, paint); + // Bottom + canvas.drawLine(_left, _bottom, _right, _bottom, paint); + // Left + canvas.drawLine(_left, _top, _left, _bottom, paint); + // Right + canvas.drawLine(_right, _top, _right, _bottom, paint); + // Cross, top-left, bottom-right + canvas.drawLine(_left, _top, _right, _bottom, paint); + // Cross, top-right, bottom-left + canvas.drawLine(_right, _top, _left, _bottom, paint); + } +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java new file mode 100644 index 0000000..6f95f7e --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java @@ -0,0 +1,57 @@ +package com.codigoparallevar.minicards.parts.buttons; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; + +import com.codigoparallevar.minicards.parts.Part; + +public class RoundButton implements Part { + + + private final int _xCenter; + private final int _yCenter; + private final int _innerRadius; + private final int _outerRadius; + private final int _outerRadiusThickness = 10; + + public RoundButton(int xCenter, int yCenter, int innerRadius, int outerRadius) { + _xCenter = xCenter; + _yCenter = yCenter; + _innerRadius = innerRadius; + _outerRadius = outerRadius; + } + + @Override + public int getLeft() { + return _xCenter - _outerRadius / 2; + } + + @Override + public int getRight() { + return _xCenter + _outerRadius / 2; + } + + @Override + public int getTop() { + return _yCenter - _outerRadius / 2; + } + + @Override + public int getBottom() { + return _yCenter + _outerRadius / 2; + } + + @Override + public void draw(Canvas canvas) { + Paint foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + foregroundPaint.setColor(Color.WHITE); + + Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + backgroundPaint.setColor(Color.BLACK); + + canvas.drawCircle(_xCenter, _yCenter, _outerRadius, foregroundPaint); + canvas.drawCircle(_xCenter, _yCenter, _outerRadius - _outerRadiusThickness, backgroundPaint); + canvas.drawCircle(_xCenter, _yCenter, _innerRadius, foregroundPaint); + } +}