Explore canvas + part solution.
This commit is contained in:
parent
389796649f
commit
bc33baca27
@ -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<Part> 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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user