Skip to content

Commit 1aeec1b

Browse files
committed
Add Data Binding
1 parent 990462a commit 1aeec1b

File tree

7 files changed

+110
-21
lines changed

7 files changed

+110
-21
lines changed

README.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Android Signature Pad is an Android library for drawing smooth signatures. It us
1010
* Variable point size based on velocity
1111
* Customizable pen color and size
1212
* Bitmap and SVG support
13+
* Data Binding
1314

1415
##Installation
1516

@@ -25,7 +26,7 @@ Open your `build.gradle` and make sure that Maven Central repository is declared
2526
```
2627
Then, include the library as dependency:
2728
```gradle
28-
compile 'com.github.gcacace:signature-pad:1.2.0'
29+
compile 'com.github.gcacace:signature-pad:1.2.1'
2930
```
3031

3132
### For Maven users
@@ -35,7 +36,7 @@ Add this dependency to your `pom.xml`:
3536
<dependency>
3637
<groupId>com.github.gcacace</groupId>
3738
<artifactId>signature-pad</artifactId>
38-
<version>1.2.0</version>
39+
<version>1.2.1</version>
3940
<type>aar</type>
4041
</dependency>
4142
```
@@ -45,8 +46,7 @@ Add this dependency to your `pom.xml`:
4546
*Please see the `/SignaturePad-Example` app for a more detailed code example of how to use the library.*
4647

4748
1. Add the `SignaturePad` view to the layout you want to show.
48-
```xml
49-
49+
```xml
5050
<com.github.gcacace.signaturepad.views.SignaturePad
5151
xmlns:android="http://schemas.android.com/apk/res/android"
5252
xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -55,7 +55,8 @@ Add this dependency to your `pom.xml`:
5555
android:layout_height="match_parent"
5656
app:penColor="@android:color/black"
5757
/>
58-
```
58+
```
59+
5960
2. Configure attributes.
6061
* `penMinWidth` - The minimum width of the stroke (default: 3dp).
6162
* `penMaxWidth` - The maximum width of the stroke (default: 7dp).
@@ -66,10 +67,16 @@ Add this dependency to your `pom.xml`:
6667
3. Configure signature events listener
6768

6869
An `OnSignedListener` can be set on the view:
69-
```java
70+
```java
7071

7172
mSignaturePad = (SignaturePad) findViewById(R.id.signature_pad);
7273
mSignaturePad.setOnSignedListener(new SignaturePad.OnSignedListener() {
74+
75+
@Override
76+
public void onStartSigning() {
77+
//Event triggered when the pad is touched
78+
}
79+
7380
@Override
7481
public void onSigned() {
7582
//Event triggered when the pad is signed
@@ -80,13 +87,29 @@ Add this dependency to your `pom.xml`:
8087
//Event triggered when the pad is cleared
8188
}
8289
});
83-
```
90+
```
8491

8592
4. Get signature data
8693
* `getSignatureBitmap()` - A signature bitmap with a white background.
8794
* `getTransparentSignatureBitmap()` - A signature bitmap with a transparent background.
8895
* `getSignatureSvg()` - A signature Scalable Vector Graphics document.
8996

97+
## Data Binding
98+
99+
The `SignaturePad` view has custom Data Binding attribute setters for all the listener events:
100+
101+
```xml
102+
<com.github.gcacace.signaturepad.views.SignaturePad
103+
xmlns:android="http://schemas.android.com/apk/res/android"
104+
xmlns:bind="http://schemas.android.com/apk/res-auto"
105+
android:id="@+id/signature_pad"
106+
android:layout_width="match_parent"
107+
android:layout_height="match_parent"
108+
bind:onStartSigning="@{activity.onStartSigning}"
109+
bind:onSigned="@{activity.onSigned}"
110+
bind:onClear="@{activity.onClear}" />
111+
```
112+
90113
## Cordova Plugin
91114

92115
Thanks to [netinhoteixeira](https://github.com/netinhoteixeira/), there is a Cordova plugin using that library.

SignaturePad-Example/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
66

77
defaultConfig {
8-
minSdkVersion 8
8+
minSdkVersion 9
99
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
1010
versionName project.VERSION_NAME
1111
versionCode Integer.parseInt(project.VERSION_CODE)

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ buildscript {
44
}
55

66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.1.2'
8-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
9-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
7+
classpath 'com.android.tools.build:gradle:2.2.3'
8+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
9+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
1010
}
1111
}
1212

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
VERSION_NAME=1.2.0
2-
VERSION_CODE=120
1+
VERSION_NAME=1.2.1
2+
VERSION_CODE=121
33
GROUP=com.github.gcacace
44

55
POM_NAME=Signature Pad
@@ -16,5 +16,5 @@ POM_DEVELOPER_ID=gcacace
1616
POM_DEVELOPER_NAME=Gianluca Cacace
1717

1818
ANDROID_BUILD_TARGET_SDK_VERSION=23
19-
ANDROID_BUILD_TOOLS_VERSION=23.0.3
19+
ANDROID_BUILD_TOOLS_VERSION=25.0.1
2020
ANDROID_BUILD_SDK_VERSION=23
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue May 10 18:06:39 EEST 2016
2-
distributionBase=GRADLE_USER_HOME
3-
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
1+
#Thu Dec 29 19:36:38 GMT 2016
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

signature-pad/build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ android {
1515
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
1616

1717
defaultConfig {
18-
minSdkVersion 4
18+
minSdkVersion 9
1919
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
2020
}
21+
22+
dataBinding {
23+
enabled = true
24+
}
2125
}
2226

2327
bintray {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.github.gcacace.signaturepad.utils;
2+
3+
import android.databinding.BindingAdapter;
4+
5+
import com.github.gcacace.signaturepad.views.SignaturePad;
6+
7+
public final class SignaturePadBindingAdapter {
8+
9+
@BindingAdapter("onStartSigning")
10+
public static void setOnSignedListener(SignaturePad view, final OnStartSigningListener onStartSigningListener) {
11+
setOnSignedListener(view, onStartSigningListener, null, null);
12+
}
13+
14+
@BindingAdapter("onSigned")
15+
public static void setOnSignedListener(SignaturePad view, final OnSignedListener onSignedListener) {
16+
setOnSignedListener(view, null, onSignedListener, null);
17+
}
18+
19+
@BindingAdapter("onClear")
20+
public static void setOnSignedListener(SignaturePad view, final OnClearListener onClearListener) {
21+
setOnSignedListener(view, null, null, onClearListener);
22+
}
23+
24+
@BindingAdapter(value = {"onStartSigning", "onSigned", "onClear"}, requireAll = false)
25+
public static void setOnSignedListener(SignaturePad view, final OnStartSigningListener onStartSigningListener, final OnSignedListener onSignedListener, final OnClearListener onClearListener) {
26+
view.setOnSignedListener(new SignaturePad.OnSignedListener() {
27+
@Override
28+
public void onStartSigning() {
29+
if (onStartSigningListener != null) {
30+
onStartSigningListener.onStartSigning();
31+
}
32+
}
33+
34+
@Override
35+
public void onSigned() {
36+
if (onSignedListener != null) {
37+
onSignedListener.onSigned();
38+
}
39+
}
40+
41+
@Override
42+
public void onClear() {
43+
if (onClearListener != null) {
44+
onClearListener.onClear();
45+
}
46+
}
47+
});
48+
}
49+
50+
public interface OnStartSigningListener {
51+
void onStartSigning();
52+
}
53+
54+
public interface OnSignedListener {
55+
void onSigned();
56+
}
57+
58+
public interface OnClearListener {
59+
void onClear();
60+
}
61+
62+
}

0 commit comments

Comments
 (0)