At first glance I see the following problems:
- By adding your empty
Path
topaths
as soon as you make it, you’re going to have a problem as soon as you undo: you’re popping that emptyPath
first, making the first undo not seem to work. Then if you draw into thatPath
, it’s not added topaths
. The solution is to add the completedPath
to paths intouch_up()
before creating a new one.
That is, remove
paths.add(mPath);
from the constructor, and in touch_up()
, change
mPath = new Path();
paths.add(mPath);
to
paths.add(mPath);
mPath = new Path();
You’ll also want to add
canvas.drawPath(mPath, mPaint);
after your for
loop in onDraw()
in order to draw the in-progress Path
.
- You’re not emptying
undonePaths
when the user starts drawing again.