package org.hogel.android.simplepainting.model;

import android.graphics.Color;
import android.graphics.Path;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class Line implements Serializable {
    private final int color;

    private final List<Point> points = new ArrayList<Point>();

    private final Path path = new Path();

    public Line() {
        this(Color.BLACK);
    }

    public Line(int color) {
        this.color = color;
    }

    public void addPoint(Point point) {
        if (points.isEmpty()) {
            path.moveTo(point.getX(), point.getY());
            points.add(point);
        } else {
            points.add(point);
            supplementPoints();
        }
    }

    private void supplementPoints() {
        final int size = points.size();
        if (size < 3) {
            return;
        }
        final Point point1 = points.get(size - 3);
        final Point point2 = points.get(size - 2);
        final Point point3 = points.get(size - 1);

        point2.x = (point1.x + point2.x + point3.x) / 3;
        point2.y = (point1.y + point2.y + point3.y) / 3;
        path.lineTo(point2.x, point2.y);
    }
}

@@ -124,16 +124,78 @@
 .Data;%0A%0A
+import java.io.IOException;%0Aimport java.io.ObjectInputStream;%0A
 import j
@@ -215,16 +215,16 @@
 izable;%0A
-
 import j
@@ -423,21 +423,25 @@
 private 
-final
+transient
  Path pa
@@ -569,23 +569,466 @@
  color;%0A
-
     %7D%0A%0A
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException %7B%0A%09%09stream.defaultReadObject();%0A%0A        path = new Path();%0A        for (int i = 0; i %3C points.size(); i++) %7B%0A            final Point point = points.get(i);%0A            if (i == 0) %7B%0A                path.moveTo(point.getX(), point.getY());%0A            %7D else %7B%0A                path.lineTo(point.getX(), point.getY());%0A            %7D%0A        %7D%0A%09%7D%0A%0A
     publ

Fix serializable line