I am trying to add points to the Path
and drawing line between them, but nothing appear.
I have custom view:
public class BreakDownBar extends View {
private List<Point> points = new ArrayList<>();
private Path path = new Path();
private Paint p = new Paint();
public BreakDownBar(Context context) {
super(context);
}
public BreakDownBar(Context context, AttributeSet attrs) {
super(context, attrs);
p.setStrokeWidth(5);
p.setStyle(Paint.Style.STROKE);
}
public void addPoint(Point point) {
points.add(point);
path.rewind();
reDraw();
}
public void startPoint(Point point) {
points.add(point);
}
private void reDraw() {
Canvas canvas = new Canvas();
path.moveTo(points.getFirst().getX(), points.getFirst().getY());
for (int i = 1; i < points.size(); i++) {
path.lineTo(points.get(i).getX(), points.get(i).getY());
}
canvas.drawPath(path, p);
canvas.drawColor(Color.BLACK);
draw(canvas);
invalidate();
}
}
Point class
:
public class Point {
private float x, y;
...getters and setters
}
While adding new points to the List
I can see thought the expected result in the log, but nothing happen on the screen.
What I missed to make line appear on the screen?