Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attr for not saving state. #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -53,6 +53,7 @@ public class SignaturePad extends View {
private float mVelocityFilterWeight;
private OnSignedListener mOnSignedListener;
private boolean mClearOnDoubleClick;
private boolean mSaveState;

//Double click detector
private GestureDetector mGestureDetector;
Expand All @@ -63,6 +64,7 @@ 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_SAVE_STATE = true;

private Paint mPaint = new Paint();
private Bitmap mSignatureBitmap = null;
Expand All @@ -83,6 +85,7 @@ public SignaturePad(Context context, AttributeSet attrs) {
mPaint.setColor(a.getColor(R.styleable.SignaturePad_penColor, DEFAULT_ATTR_PEN_COLOR));
mVelocityFilterWeight = a.getFloat(R.styleable.SignaturePad_velocityFilterWeight, DEFAULT_ATTR_VELOCITY_FILTER_WEIGHT);
mClearOnDoubleClick = a.getBoolean(R.styleable.SignaturePad_clearOnDoubleClick, DEFAULT_ATTR_CLEAR_ON_DOUBLE_CLICK);
mSaveState = a.getBoolean(R.styleable.SignaturePad_saveState, DEFAULT_ATTR_SAVE_STATE);
} finally {
a.recycle();
}
Expand All @@ -108,13 +111,17 @@ public boolean onDoubleTap(MotionEvent e) {

@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("superState", super.onSaveInstanceState());
if (this.mHasEditState == null || this.mHasEditState) {
this.mBitmapSavedState = this.getTransparentSignatureBitmap();
if (mSaveState) {
Bundle bundle = new Bundle();
bundle.putParcelable("superState", super.onSaveInstanceState());
if (this.mHasEditState == null || this.mHasEditState) {
this.mBitmapSavedState = this.getTransparentSignatureBitmap();
}
bundle.putParcelable("signatureBitmap", this.mBitmapSavedState);
return bundle;
} else {
return super.onSaveInstanceState();
}
bundle.putParcelable("signatureBitmap", this.mBitmapSavedState);
return bundle;
}

@Override
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="saveState" format="boolean" />
</declare-styleable>
</resources>