Skip to content

Commit

Permalink
Removed handling state saving across screen rotation to prevent Trans…
Browse files Browse the repository at this point in the history
…actionTooLargeException, Added support for JitPack
  • Loading branch information
RationalRank committed Dec 5, 2020
1 parent b5cd30e commit 75e1d37
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 180 deletions.
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
Android Signature Pad
====================

Android Signature Pad is an Android library for drawing smooth signatures. It uses variable width Bézier curve interpolation based on [Smoother Signatures](http://corner.squareup.com/2012/07/smoother-signatures.html) post by [Square](https://squareup.com).

![Screenshot](https://github.com/gcacace/android-signaturepad/raw/master/header.png)

## Features
* Bézier implementation for a smoother line
* Variable point size based on velocity
* Customizable pen color and size
* Bitmap and SVG support
* Data Binding
This fork just addresses the [TransactionTooLarge Exception issue](https://github.com/gcacace/android-signaturepad/issues/153). This fork just prevents saving state, thus leading to state loss. Feature introductions aren't guaranteed.

## Installation

Expand All @@ -21,24 +12,12 @@ Latest version of the library can be found on Maven Central.
Open your `build.gradle` and make sure that Maven Central repository is declared into `repositories` section:
```gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
```
Then, include the library as dependency:
```gradle
compile 'com.github.gcacace:signature-pad:1.3.1'
```

### For Maven users

Add this dependency to your `pom.xml`:
```xml
<dependency>
<groupId>com.github.gcacace</groupId>
<artifactId>signature-pad</artifactId>
<version>1.3.1</version>
<type>aar</type>
</dependency>
compile 'com.github.ZupersoftSolutions:signature-pad:1.3.2'
```

## Usage
Expand Down
10 changes: 5 additions & 5 deletions SignaturePad-Example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
compileSdkVersion 29

defaultConfig {
minSdkVersion 14
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionName project.VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
targetSdkVersion 29
versionName "1.3.2"
versionCode 132
}

signingConfigs { release }
Expand All @@ -21,5 +21,5 @@ android {

dependencies {
implementation project(":signature-pad")
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
}
12 changes: 2 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

plugins {
id 'com.jfrog.bintray' version '1.8.4'
id 'maven-publish'
}

allprojects {
version = VERSION_NAME
group = GROUP

repositories {
google()
jcenter()
Expand Down
18 changes: 0 additions & 18 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ org.gradle.jvmargs=-Xmx1536m

VERSION_NAME=1.3.1
VERSION_CODE=130
GROUP=com.github.gcacace

POM_NAME=Signature Pad
POM_ARTIFACT_ID=android-signaturepad
POM_DESCRIPTION=A custom Android View to capture signatures
POM_URL=https://github.com/gcacace/android-signaturepad
POM_SCM_URL=https://github.com/gcacace/android-signaturepad
POM_SCM_CONNECTION=scm:[email protected]:gcacace/android-signaturepad.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:gcacace/android-signaturepad.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=gcacace
POM_DEVELOPER_NAME=Gianluca Cacace
POM_DEVELOPER_EMAIL=[email protected]

ANDROID_BUILD_TARGET_SDK_VERSION=29
ANDROID_BUILD_SDK_VERSION=29

android.useAndroidX=true
android.enableJetifier=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 08 11:36:01 SGT 2017
#Sat Dec 05 12:10:23 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
89 changes: 8 additions & 81 deletions signature-pad/build.gradle
Original file line number Diff line number Diff line change
@@ -1,94 +1,21 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

Properties properties = new Properties()
final def bintrayPropertiesFile = project.rootProject.file('bintray.properties')
if (bintrayPropertiesFile.exists()) properties.load(bintrayPropertiesFile.newDataInputStream())
group = 'com.github.ZupersoftSolutions'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
compileSdkVersion 29

defaultConfig {
minSdkVersion 14
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
targetSdkVersion 29
versionCode 132
versionName "1.3.2"
consumerProguardFiles 'proguard-rules-consumer.pro'
}

dataBinding {
enabled = true
}
}

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
publications = ['aar']
pkg {
repo = "maven"
name = project.POM_ARTIFACT_ID
desc = project.POM_DESCRIPTION
websiteUrl = project.POM_URL
vcsUrl = project.POM_SCM_URL
licenses = ["Apache-2.0"]
publish = true

version {
gpg {
sign = true
passphrase = properties.getProperty("bintray.gpg.passphrase")
}
mavenCentralSync {
sync = true
user = properties.getProperty("oss.userToken")
password = properties.getProperty("oss.userTokenValue")
close = '1'
}
}
}
}

project.ext {
mavDevelopers = ["Fe": "Federico"]
mavSiteUrl = "https://github.com/sky-uk/gradle-maven-plugin"
mavGitUrl = mavSiteUrl + '.git'
mavProjectName = 'GradleMavenizer'
mavPublishToInternalRepo = true
mavRepoInternalUrl = "path/to/internal/repo"
mavLibraryLicenses = ["Apache-2.0": 'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "A simple description of the project"
}

publishing {
publications {
aar(MavenPublication) {
pom {
packaging = 'aar'
name = project.POM_NAME
description = project.POM_DESCRIPTION
url = project.POM_URL
licenses {
license {
name = project.POM_LICENCE_NAME
url = project.POM_LICENCE_URL
}
}
developers {
developer {
id = project.POM_DEVELOPER_ID
name = project.POM_DEVELOPER_NAME
email = project.POM_DEVELOPER_EMAIL
}
}
scm {
connection = project.POM_SCM_URL
developerConnection = project.POM_SCM_CONNECTION
url = project.POM_URL
}
}
}
buildFeatures {
dataBinding true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.GestureDetector;
Expand All @@ -32,13 +31,11 @@ public class SignaturePad extends View {
//View state
private List<TimedPoint> mPoints;
private boolean mIsEmpty;
private Boolean mHasEditState;
private float mLastTouchX;
private float mLastTouchY;
private float mLastVelocity;
private float mLastWidth;
private RectF mDirtyRect;
private Bitmap mBitmapSavedState;

private final SvgBuilder mSvgBuilder = new SvgBuilder();

Expand Down Expand Up @@ -72,9 +69,9 @@ public SignaturePad(Context context, AttributeSet attrs) {
super(context, attrs);

TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.SignaturePad,
0, 0);
attrs,
R.styleable.SignaturePad,
0, 0);

//Configurable parameters
try {
Expand Down Expand Up @@ -106,29 +103,6 @@ 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();
}
bundle.putParcelable("signatureBitmap", this.mBitmapSavedState);
return bundle;
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
this.setSignatureBitmap((Bitmap) bundle.getParcelable("signatureBitmap"));
this.mBitmapSavedState = bundle.getParcelable("signatureBitmap");
state = bundle.getParcelable("superState");
}
this.mHasEditState = false;
super.onRestoreInstanceState(state);
}

/**
* Set the pen color from a given resource.
* If the resource is not found, {@link android.graphics.Color#BLACK} is assumed.
Expand Down Expand Up @@ -197,7 +171,6 @@ public void clearView() {

public void clear() {
this.clearView();
this.mHasEditState = true;
}

@Override
Expand Down Expand Up @@ -236,10 +209,10 @@ public boolean onTouchEvent(MotionEvent event) {

//invalidate();
invalidate(
(int) (mDirtyRect.left - mMaxWidth),
(int) (mDirtyRect.top - mMaxWidth),
(int) (mDirtyRect.right + mMaxWidth),
(int) (mDirtyRect.bottom + mMaxWidth));
(int) (mDirtyRect.left - mMaxWidth),
(int) (mDirtyRect.top - mMaxWidth),
(int) (mDirtyRect.right + mMaxWidth),
(int) (mDirtyRect.bottom + mMaxWidth));

return true;
}
Expand Down Expand Up @@ -334,9 +307,9 @@ public Bitmap getTransparentSignatureBitmap(boolean trimBlankSpace) {
int backgroundColor = Color.TRANSPARENT;

int xMin = Integer.MAX_VALUE,
xMax = Integer.MIN_VALUE,
yMin = Integer.MAX_VALUE,
yMax = Integer.MIN_VALUE;
xMax = Integer.MIN_VALUE,
yMin = Integer.MAX_VALUE,
yMax = Integer.MIN_VALUE;

boolean foundPixel = false;

Expand Down Expand Up @@ -453,7 +426,7 @@ private void addPoint(TimedPoint newPoint) {
velocity = Float.isNaN(velocity) ? 0.0f : velocity;

velocity = mVelocityFilterWeight * velocity
+ (1 - mVelocityFilterWeight) * mLastVelocity;
+ (1 - mVelocityFilterWeight) * mLastVelocity;

// The new width is a function of the velocity. Higher velocities
// correspond to thinner strokes.
Expand Down Expand Up @@ -481,7 +454,6 @@ private void addPoint(TimedPoint newPoint) {
TimedPoint firstPoint = mPoints.get(0);
mPoints.add(getNewPoint(firstPoint.x, firstPoint.y));
}
this.mHasEditState = true;
}

private void addBezier(Bezier curve, float startWidth, float endWidth) {
Expand Down Expand Up @@ -599,7 +571,7 @@ private void setIsEmpty(boolean newValue) {
private void ensureSignatureBitmap() {
if (mSignatureBitmap == null) {
mSignatureBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
Bitmap.Config.ARGB_8888);
Bitmap.Config.ARGB_8888);
mSignatureBitmapCanvas = new Canvas(mSignatureBitmap);
}
}
Expand Down

0 comments on commit 75e1d37

Please sign in to comment.