package gram_zico.artist;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;

import java.util.LinkedList;


/**
 * Created by dsm2017 on 2017-09-15.
 */


public class DrawView extends View {

    private LinkedList<DrawClass> linkedList = new LinkedList<>();

    private Paint paint = new Paint();
    private Path path;

    private Bitmap bitmap;

    public DrawView(Context context) {
        super(context);
    }

    public void changeColor(int color){
        linkedList.add(new DrawClass(path, paint));
        paint.setColor(color);
        path = new Path();
    }

    public void changeWidth(int size){
        linkedList.add(new DrawClass(path, paint));
        paint.setStrokeWidth(size);
        path = new Path();
    }

    protected void onDraw(Canvas canvas) {
        if (bitmap == null){
            paint.setStrokeWidth(10);
            paint.setColor(Color.BLACK);
            paint.setStyle(Paint.Style.STROKE);
            bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
        }

        canvas.setBitmap(bitmap);
        for(DrawClass drawClass : linkedList){
            canvas.drawPath(drawClass.path, drawClass.paint);
        }

        canvas.drawPath(path, paint);
    }

    class DrawClass{
        private Path path;
        private Paint paint;

        public DrawClass(Path path, Paint paint) {
            this.path = path;
            this.paint = paint;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        float x = event.getX();
        float y = event.getY();

        switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                path.moveTo(x, y);
                break;
            case MotionEvent.ACTION_MOVE:
                x = event.getX();
                y = event.getY();
                path.lineTo(x, y);
                break;
            case MotionEvent.ACTION_UP:
                break;
        }

        invalidate();

        return true;
    }

}


@@ -208,16 +208,94 @@
 s.Path;%0A
+import android.support.annotation.Nullable;%0Aimport android.util.AttributeSet;%0A
 import a
@@ -590,16 +590,29 @@
 ath path
+ = new Path()
 ;%0A%0A    p
@@ -696,32 +696,139 @@
 ontext);%0A    %7D%0A%0A
+    public DrawView(Context context, @Nullable AttributeSet attrs) %7B%0A        super(context, attrs);%0A    %7D%0A%0A
     public void 
@@ -886,37 +886,82 @@
 DrawClass(path, 
-paint
+getPaint(paint.getColor(), paint.getStrokeWidth())
 ));%0A        pain
@@ -1095,21 +1095,66 @@
 s(path, 
-paint
+getPaint(paint.getColor(), paint.getStrokeWidth())
 ));%0A    
@@ -1215,24 +1215,252 @@
 h();%0A    %7D%0A%0A
+    private Paint getPaint(int color, float width)%7B%0A        Paint paint = new Paint();%0A        paint.setColor(color);%0A        paint.setStrokeWidth(width);%0A        paint.setStyle(Paint.Style.STROKE);%0A        return paint;%0A    %7D%0A%0A
     protecte
@@ -1767,24 +1767,26 @@
  %7D%0A%0A        
+//
 canvas.setBi

set color width