diff --git a/signature-pad/src/main/java/com/github/gcacace/signaturepad/views/SignaturePad.java b/signature-pad/src/main/java/com/github/gcacace/signaturepad/views/SignaturePad.java index 9e89096..15fbbdf 100644 --- a/signature-pad/src/main/java/com/github/gcacace/signaturepad/views/SignaturePad.java +++ b/signature-pad/src/main/java/com/github/gcacace/signaturepad/views/SignaturePad.java @@ -66,6 +66,8 @@ public class SignaturePad extends View { private final int DEFAULT_ATTR_PEN_COLOR = Color.BLACK; private final float DEFAULT_ATTR_VELOCITY_FILTER_WEIGHT = 0.9f; private final boolean DEFAULT_ATTR_CLEAR_ON_DOUBLE_CLICK = false; + private final boolean DEFAULT_ATTR_PRESERVE = true; + private boolean mPreserve; private Paint mPaint = new Paint(); private Bitmap mSignatureBitmap = null; @@ -81,6 +83,7 @@ public SignaturePad(Context context, AttributeSet attrs) { //Configurable parameters try { + mPreserve = a.getBoolean(R.styleable.SignaturePad_preserve, DEFAULT_ATTR_PRESERVE); mMinWidth = a.getDimensionPixelSize(R.styleable.SignaturePad_penMinWidth, convertDpToPx(DEFAULT_ATTR_PEN_MIN_WIDTH_PX)); mMaxWidth = a.getDimensionPixelSize(R.styleable.SignaturePad_penMaxWidth, convertDpToPx(DEFAULT_ATTR_PEN_MAX_WIDTH_PX)); mPaint.setColor(a.getColor(R.styleable.SignaturePad_penColor, DEFAULT_ATTR_PEN_COLOR)); @@ -111,6 +114,7 @@ public boolean onDoubleTap(MotionEvent e) { @Override protected Parcelable onSaveInstanceState() { + if (!mPreserve) return super.onSaveInstanceState(); try { Bundle bundle = new Bundle(); bundle.putParcelable("superState", super.onSaveInstanceState()); @@ -127,6 +131,10 @@ protected Parcelable onSaveInstanceState() { @Override protected void onRestoreInstanceState(Parcelable state) { + if (!mPreserve) { + super.onRestoreInstanceState(state); + return; + } if (state instanceof Bundle) { Bundle bundle = (Bundle) state; this.setSignatureBitmap((Bitmap) bundle.getParcelable("signatureBitmap")); @@ -151,6 +159,15 @@ public void setPenColorRes(int colorRes) { } } + /** + * Set flag preserve true or false + * + * @param shouldPreserve if signature should be preserved when activity is destroyed. + */ + public void setPreserve(boolean shouldPreserve) { + mPreserve = shouldPreserve; + } + /** * Set the pen color from a given color. * diff --git a/signature-pad/src/main/res/values/attrs.xml b/signature-pad/src/main/res/values/attrs.xml index d1d107b..9092c39 100644 --- a/signature-pad/src/main/res/values/attrs.xml +++ b/signature-pad/src/main/res/values/attrs.xml @@ -6,5 +6,6 @@ +