DrawView.java
public class DrawView extends View implements OnTouchListener {
private Canvas mCanvas;
private Path mPath;
public Paint mPaint;
ArrayList
To do this, you'd have to create a new Paint
for every object drawn. This is because when the Canvas
redraws, it references that same Paint
object every time, so all paths will use this paint.
Firstly, I would change your paths
array to contain both a Paint
and a Path
. You can achieve this using the Android type Pair
.
ArrayList<Pair<Path, Paint>> paths = new ArrayList<Pair<Path, Paint>>();
You will also have to convert your undonePaths
variable in this manner.
Then, in your touch_up()
method, you need to add this new Paint
object.
Paint newPaint = new Paint(mPaint); // Clones the mPaint object
paths.add(new Pair<Path, Paint>(mPath, newPaint));
Lastly, your loop has to be adjusted for this as well:
for (Pair<Path, Paint> p : paths) {
canvas.drawPath(p.first, p.second);
}
This is quite memory intensive, so you will have to take good care to reset these items when they're no longer in use, but to have so many different colors, you must have all of these different Paint
objects.