mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
store the paths in an arraylist
This commit is contained in:
@ -9,9 +9,12 @@ import android.util.AttributeSet;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MyCanvas extends View {
|
public class MyCanvas extends View {
|
||||||
private Paint paint;
|
private Paint paint;
|
||||||
private Path path;
|
private Path path;
|
||||||
|
private ArrayList<Path> paths;
|
||||||
private float curX;
|
private float curX;
|
||||||
private float curY;
|
private float curY;
|
||||||
private float startX;
|
private float startX;
|
||||||
@ -28,15 +31,21 @@ public class MyCanvas extends View {
|
|||||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
paint.setStrokeWidth(5f);
|
paint.setStrokeWidth(5f);
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
|
||||||
|
paths = new ArrayList<>();
|
||||||
|
paths.add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
canvas.drawPath(path, paint);
|
for (Path p : paths) {
|
||||||
|
canvas.drawPath(p, paint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionDown(float x, float y) {
|
private void actionDown(float x, float y) {
|
||||||
|
path.reset();
|
||||||
path.moveTo(x, y);
|
path.moveTo(x, y);
|
||||||
curX = x;
|
curX = x;
|
||||||
curY = y;
|
curY = y;
|
||||||
@ -57,6 +66,9 @@ public class MyCanvas extends View {
|
|||||||
path.lineTo(curX + 1, curY + 2);
|
path.lineTo(curX + 1, curY + 2);
|
||||||
path.lineTo(curX + 1, curY);
|
path.lineTo(curX + 1, curY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path = new Path();
|
||||||
|
paths.add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user