Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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());
Expand All @@ -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"));
Expand All @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions signature-pad/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<attr name="penColor" format="color" />
<attr name="velocityFilterWeight" format="float" />
<attr name="clearOnDoubleClick" format="boolean"/>
<attr name="preserve" format="boolean"/>
</declare-styleable>
</resources>