RiccardoMoro / FreeDrawView

A View on which you can freely draw, customizing paint width, alpha and color, and take a screenshot of the content. Useful for note apps, signatures or free hand writing.
650 stars 116 forks source link

getCurrentViewStateAsSerializable() returns soft copy (dynamic mutable state) #15

Open lenhuy2106 opened 7 years ago

lenhuy2106 commented 7 years ago

Hello RiccardoMoro!

FreeDrawSerializableState#getCurrentViewStateAsSerializable()

returns

new FreeDrawSerializableState(mCanceledPaths, mPaths, getPaintColor(),
                getPaintAlpha(), getPaintWidth(), getResizeBehaviour(),
                mLastDimensionW, mLastDimensionH);

with mCanceledPaths, mPaths as pointers to respective arraylists, such that changes are represented both on the original and the copy. If thats not intended behaviour, i would suggest returning hard copies.

Thanks for the hard work! Much love. Huy

lenhuy2106 commented 7 years ago

I see there are lots of nested references.

Anyways, here's a hacky way to do it with gson-serialization:

    FreeDrawSerializableState copy(FreeDrawSerializableState state) {
        Gson gson = new Gson();
        return gson.fromJson(gson.toJson(state), FreeDrawSerializableState.class);
    }