2

I'm trying to create an application similar to Finger Paint example from Android SDK. I was trying to implement Undo/Redo functionality to my test app and used the accepted answer in this question : Android FingerPaint Undo/Redo implementation.

The example there is working, but there is a strange things which I've noticed. If I select eraser mode for example on some button click, the default implementation acts like a eraser, but using onDraw() as in the question mentioned above is not doing this. Instead of it's acting like a normal brush and drawing with a black stroke (depending on the given color).

If I try to add another effects to the current brush, for example I drew 15 lines and after that select add blur option, after I draw the new one, all lines before get blurred too.

            if (mPaint.getMaskFilter() != mBlur) {
                mPaint.setMaskFilter(mBlur);
            } else {
                mPaint.setMaskFilter(null);
            }
            return true;

So my question is..any ideas how can I separate old lines from new ones and setting effects only for them and using clear mode as it should be?

Thanks for any kind of help!

Community
  • 1
  • 1
Android-Droid
  • 14,365
  • 41
  • 114
  • 185

1 Answers1

0

You would rather hold history in an object like the following one than just holding the path objects..

class pathInfo {
    Path mPath;
    int  mStyle;
    boolean mbAntiAlias; 
    ....
}

Then while drawing each path pick each corresponding info from these objects

protected void onDraw(Canvas canvas) {            

    for (PathInfo p : pathsInfo){
        mPaint.setStyle(p.mStyle);
        ....
        canvas.drawPath(p.mPath, mPaint);
    }

}
Ron
  • 24,175
  • 8
  • 56
  • 97