├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── whosmyqueen
│ │ │ └── signdemo
│ │ │ ├── MainActivity.java
│ │ │ └── view
│ │ │ ├── SignatureView.java
│ │ │ └── SignView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── whosmyqueen
│ │ │ └── signdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── whosmyqueen
│ │ └── signdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── signpad
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── whosmyqueen
│ │ │ └── signpad
│ │ │ ├── utils
│ │ │ ├── ControlTimedPoints.java
│ │ │ ├── TimedPoint.java
│ │ │ ├── Bezier.java
│ │ │ ├── SvgPoint.java
│ │ │ ├── SvgBuilder.java
│ │ │ └── SvgPathBuilder.java
│ │ │ ├── view
│ │ │ ├── ViewTreeObserverCompat.java
│ │ │ └── ViewCompat.java
│ │ │ └── views
│ │ │ └── SignaturePad.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── whosmyqueen
│ │ │ └── signpad
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── whosmyqueen
│ │ └── signpad
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/signpad/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':signpad'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SignDemo
3 |
4 |
--------------------------------------------------------------------------------
/signpad/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SignPad
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whosmyqueen/signature-panel/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .idea
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 29 13:34:29 CST 2020
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-6.7.1-all.zip
7 |
--------------------------------------------------------------------------------
/signpad/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/whosmyqueen/signdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/signpad/src/test/java/com/whosmyqueen/signpad/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/ControlTimedPoints.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 | /**
4 | * Created by whosmyqueen on 28/02/14.
5 | */
6 | public class ControlTimedPoints {
7 |
8 | public TimedPoint c1;
9 | public TimedPoint c2;
10 |
11 | public ControlTimedPoints set(TimedPoint c1, TimedPoint c2) {
12 | this.c1 = c1;
13 | this.c2 = c2;
14 | return this;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/whosmyqueen/signdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/signpad/src/androidTest/java/com/whosmyqueen/signpad/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/signpad/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SignDemo
2 | 用于公司的合同签名
3 |
4 | [](https://jitpack.io/#whosmyqueen/SignPad)
5 |
6 | Step 1. Add the JitPack repository to your build file
7 | Add it in your root build.gradle at the end of repositories:
8 |
9 | allprojects {
10 | repositories {
11 | ...
12 | maven { url 'https://jitpack.io' }
13 | }
14 | }
15 | Step 2. Add the dependency
16 |
17 | dependencies {
18 | implementation 'com.github.whosmyqueen:SignPad:1.0.0'
19 | }
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Android\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/signpad/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Android\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/TimedPoint.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 | public class TimedPoint {
4 | public float x;
5 | public float y;
6 | public long timestamp;
7 |
8 | public TimedPoint set(float x, float y) {
9 | this.x = x;
10 | this.y = y;
11 | this.timestamp = System.currentTimeMillis();
12 | return this;
13 | }
14 |
15 | public float velocityFrom(TimedPoint start) {
16 | float velocity = distanceTo(start) / (this.timestamp - start.timestamp);
17 | if (velocity != velocity) return 0f;
18 | return velocity;
19 | }
20 |
21 | public float distanceTo(TimedPoint point) {
22 | return (float) Math.sqrt(Math.pow(point.x - this.x, 2) + Math.pow(point.y - this.y, 2));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/signpad/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven' //添加这两行
3 | group = 'com.github.whosmyqueen' //GitHub昵称
4 | android {
5 | compileSdkVersion 28
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility JavaVersion.VERSION_1_8
21 | targetCompatibility JavaVersion.VERSION_1_8
22 | }
23 | }
24 |
25 | dependencies {
26 | api fileTree(dir: 'libs', include: ['*.jar'])
27 | api 'androidx.appcompat:appcompat:1.2.0'
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/view/ViewTreeObserverCompat.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.view;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Build;
5 | import android.view.ViewTreeObserver;
6 |
7 | public class ViewTreeObserverCompat {
8 | /**
9 | * Remove a previously installed global layout callback.
10 | * @param observer the view observer
11 | * @param victim the victim
12 | */
13 | @SuppressLint("NewApi")
14 | @SuppressWarnings("deprecation")
15 | public static void removeOnGlobalLayoutListener(ViewTreeObserver observer, ViewTreeObserver.OnGlobalLayoutListener victim) {
16 | // Future (API16+)...
17 | if (Build.VERSION.SDK_INT >= 16) {
18 | observer.removeOnGlobalLayoutListener(victim);
19 | }
20 | // Legacy...
21 | else {
22 | observer.removeGlobalOnLayoutListener(victim);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/view/ViewCompat.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.view;
2 |
3 | import android.os.Build;
4 | import android.view.View;
5 |
6 | public class ViewCompat {
7 | /**
8 | * Returns true if {@code view} has been through at least one layout since it
9 | * was last attached to or detached from a window.
10 | *
11 | * See http://developer.android.com/reference/android/support/v4/view/ViewCompat.html#isLaidOut%28android.view.View%29
12 | *
13 | * @param view the view
14 | * @return true if this view has been through at least one layout since it was last attached to or detached from a window.
15 | */
16 | public static boolean isLaidOut(View view) {
17 | // Future (API19+)...
18 | if (Build.VERSION.SDK_INT >= 19) {
19 | return view.isLaidOut();
20 | }
21 | // Legacy...
22 | return view.getWidth() > 0 && view.getHeight() > 0;
23 | }
24 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.enableJetifier=true
20 | android.useAndroidX=true
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | android {
3 | compileSdkVersion 28
4 |
5 | defaultConfig {
6 | applicationId "com.whosmyqueen.signdemo"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | compileOptions {
19 | sourceCompatibility JavaVersion.VERSION_1_8
20 | targetCompatibility JavaVersion.VERSION_1_8
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(include: ['*.jar'], dir: 'libs')
26 | implementation 'androidx.appcompat:appcompat:1.2.0'
27 | implementation 'com.jakewharton:butterknife:10.2.3'
28 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
29 | implementation project(':signpad')
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #f00
9 | #fff
10 | #0f0
11 | #0000ff
12 | #000
13 | #33b5e5
14 | #0099cc
15 | #aa66cc
16 | #9933cc
17 | #99cc00
18 | #669900
19 | #ffbb33
20 | #ff8800
21 | #ff4444
22 | #cc0000
23 | #fefefe
24 |
25 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/Bezier.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 | public class Bezier {
4 |
5 | public TimedPoint startPoint;
6 | public TimedPoint control1;
7 | public TimedPoint control2;
8 | public TimedPoint endPoint;
9 |
10 | public Bezier set(TimedPoint startPoint, TimedPoint control1,
11 | TimedPoint control2, TimedPoint endPoint) {
12 | this.startPoint = startPoint;
13 | this.control1 = control1;
14 | this.control2 = control2;
15 | this.endPoint = endPoint;
16 | return this;
17 | }
18 |
19 | public float length() {
20 | int steps = 10;
21 | float length = 0;
22 | double cx, cy, px = 0, py = 0, xDiff, yDiff;
23 |
24 | for (int i = 0; i <= steps; i++) {
25 | float t = (float) i / steps;
26 | cx = point(t, this.startPoint.x, this.control1.x,
27 | this.control2.x, this.endPoint.x);
28 | cy = point(t, this.startPoint.y, this.control1.y,
29 | this.control2.y, this.endPoint.y);
30 | if (i > 0) {
31 | xDiff = cx - px;
32 | yDiff = cy - py;
33 | length += Math.sqrt(xDiff * xDiff + yDiff * yDiff);
34 | }
35 | px = cx;
36 | py = cy;
37 | }
38 | return length;
39 |
40 | }
41 |
42 | public double point(float t, float start, float c1, float c2, float end) {
43 | return start * (1.0 - t) * (1.0 - t) * (1.0 - t)
44 | + 3.0 * c1 * (1.0 - t) * (1.0 - t) * t
45 | + 3.0 * c2 * (1.0 - t) * t * t
46 | + end * t * t * t;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/SvgPoint.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 | /**
4 | * Represent a point as it would be in the generated SVG document.
5 | */
6 | class SvgPoint {
7 |
8 | final Integer x, y;
9 |
10 | public SvgPoint(TimedPoint point) {
11 | // one optimisation is to get rid of decimals as they are mostly non-significant in the
12 | // produced SVG image
13 | x = Math.round(point.x);
14 | y = Math.round(point.y);
15 | }
16 |
17 | public SvgPoint(int x, int y) {
18 | this.x = x;
19 | this.y = y;
20 | }
21 |
22 | public String toAbsoluteCoordinates() {
23 | StringBuilder stringBuilder = new StringBuilder();
24 | stringBuilder.append(x);
25 | if (y >= 0) {
26 | stringBuilder.append(" ");
27 | }
28 | stringBuilder.append(y);
29 | return stringBuilder.toString();
30 | }
31 |
32 | public String toRelativeCoordinates(final SvgPoint referencePoint) {
33 | return (new SvgPoint(x - referencePoint.x, y - referencePoint.y)).toString();
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return toAbsoluteCoordinates();
39 | }
40 |
41 | @Override
42 | public boolean equals(Object o) {
43 | if (this == o) return true;
44 | if (o == null || getClass() != o.getClass()) return false;
45 |
46 | SvgPoint svgPoint = (SvgPoint) o;
47 |
48 | if (!x.equals(svgPoint.x)) return false;
49 | return y.equals(svgPoint.y);
50 |
51 | }
52 |
53 | @Override
54 | public int hashCode() {
55 | int result = x.hashCode();
56 | result = 31 * result + y.hashCode();
57 | return result;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
27 |
28 |
32 |
33 |
34 |
40 |
41 |
48 |
49 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/whosmyqueen/signdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signdemo;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.os.Environment;
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.whosmyqueen.signpad.views.SignaturePad;
11 |
12 | import java.io.File;
13 | import java.io.FileNotFoundException;
14 | import java.io.FileOutputStream;
15 | import java.io.IOException;
16 | import java.io.OutputStream;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | @BindView(R.id.btn_clear)
24 | Button btn_clear;
25 | @BindView(R.id.btn_save)
26 | Button btn_save;
27 | @BindView(R.id.signature_pad)
28 | SignaturePad paintView;
29 |
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | ButterKnife.bind(this);
35 | btn_save.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View view) {
38 | Bitmap bitmap = paintView.getTransparentSignatureBitmap(true);
39 | if (bitmap == null)
40 | return;
41 | try {
42 | OutputStream outputStream = new FileOutputStream(new File(Environment.getExternalStorageDirectory
43 | (), "1.png"));
44 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
45 | outputStream.flush();
46 | outputStream.close();
47 | } catch (FileNotFoundException e) {
48 | e.printStackTrace();
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 | });
54 | btn_clear.setOnClickListener(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View view) {
57 | paintView.clear();
58 | }
59 | });
60 | // getSignatureBitmap() - A signature bitmap with a white background.
61 | // getTransparentSignatureBitmap() - A signature bitmap with a transparent background.
62 | // getSignatureSvg() - A signature Scalable Vector Graphics document.
63 | paintView.setMinWidth(10f);
64 | paintView.setOnSignedListener(new SignaturePad.OnSignedListener() {
65 | @Override
66 | public void onStartSigning() {
67 |
68 | }
69 |
70 | @Override
71 | public void onSigned() {
72 |
73 | }
74 |
75 | @Override
76 | public void onClear() {
77 |
78 | }
79 | });
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/SvgBuilder.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 | public class SvgBuilder {
4 |
5 | private final StringBuilder mSvgPathsBuilder = new StringBuilder();
6 | private SvgPathBuilder mCurrentPathBuilder = null;
7 |
8 | public SvgBuilder() {
9 | }
10 |
11 | public void clear() {
12 | mSvgPathsBuilder.setLength(0);
13 | mCurrentPathBuilder = null;
14 | }
15 |
16 | public String build(final int width, final int height) {
17 | if (isPathStarted()) {
18 | appendCurrentPath();
19 | }
20 | return (new StringBuilder())
21 | .append("\n")
22 | .append("")
38 | .toString();
39 | }
40 |
41 | public SvgBuilder append(final Bezier curve, final float strokeWidth) {
42 | final Integer roundedStrokeWidth = Math.round(strokeWidth);
43 | final SvgPoint curveStartSvgPoint = new SvgPoint(curve.startPoint);
44 | final SvgPoint curveControlSvgPoint1 = new SvgPoint(curve.control1);
45 | final SvgPoint curveControlSvgPoint2 = new SvgPoint(curve.control2);
46 | final SvgPoint curveEndSvgPoint = new SvgPoint(curve.endPoint);
47 |
48 | if (!isPathStarted()) {
49 | startNewPath(roundedStrokeWidth, curveStartSvgPoint);
50 | }
51 |
52 | if (!curveStartSvgPoint.equals(mCurrentPathBuilder.getLastPoint())
53 | || !roundedStrokeWidth.equals(mCurrentPathBuilder.getStrokeWidth())) {
54 | appendCurrentPath();
55 | startNewPath(roundedStrokeWidth, curveStartSvgPoint);
56 | }
57 |
58 | mCurrentPathBuilder.append(curveControlSvgPoint1, curveControlSvgPoint2, curveEndSvgPoint);
59 | return this;
60 | }
61 |
62 | private void startNewPath(Integer roundedStrokeWidth, SvgPoint curveStartSvgPoint) {
63 | mCurrentPathBuilder = new SvgPathBuilder(curveStartSvgPoint, roundedStrokeWidth);
64 | }
65 |
66 | private void appendCurrentPath() {
67 | mSvgPathsBuilder.append(mCurrentPathBuilder);
68 | }
69 |
70 | private boolean isPathStarted() {
71 | return mCurrentPathBuilder != null;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/utils/SvgPathBuilder.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.utils;
2 |
3 |
4 | /**
5 | * Build a SVG path as a string.
6 | *
7 | * https://www.w3.org/TR/SVGTiny12/paths.html
8 | */
9 | public class SvgPathBuilder {
10 |
11 | public static final Character SVG_RELATIVE_CUBIC_BEZIER_CURVE = 'c';
12 | public static final Character SVG_MOVE = 'M';
13 | private final StringBuilder mStringBuilder;
14 | private final Integer mStrokeWidth;
15 | private final SvgPoint mStartPoint;
16 | private SvgPoint mLastPoint;
17 | private Character mLastSvgCommand;
18 |
19 | public SvgPathBuilder(final SvgPoint startPoint, final Integer strokeWidth) {
20 | mStrokeWidth = strokeWidth;
21 | mStartPoint = startPoint;
22 | mLastPoint = startPoint;
23 | mLastSvgCommand = null;
24 | mStringBuilder = new StringBuilder();
25 | }
26 |
27 | public final Integer getStrokeWidth() {
28 | return mStrokeWidth;
29 | }
30 |
31 | public final SvgPoint getLastPoint() {
32 | return mLastPoint;
33 | }
34 |
35 | public SvgPathBuilder append(final SvgPoint controlPoint1, final SvgPoint controlPoint2, final SvgPoint endPoint) {
36 | mStringBuilder.append(makeRelativeCubicBezierCurve(controlPoint1, controlPoint2, endPoint));
37 | mLastSvgCommand = SVG_RELATIVE_CUBIC_BEZIER_CURVE;
38 | mLastPoint = endPoint;
39 | return this;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return (new StringBuilder())
45 | .append("")
54 | .toString();
55 | }
56 |
57 | private String makeRelativeCubicBezierCurve(final SvgPoint controlPoint1, final SvgPoint controlPoint2, final SvgPoint endPoint) {
58 | final String sControlPoint1 = controlPoint1.toRelativeCoordinates(mLastPoint);
59 | final String sControlPoint2 = controlPoint2.toRelativeCoordinates(mLastPoint);
60 | final String sEndPoint = endPoint.toRelativeCoordinates(mLastPoint);
61 |
62 | final StringBuilder sb = new StringBuilder();
63 | if (!SVG_RELATIVE_CUBIC_BEZIER_CURVE.equals(mLastSvgCommand)) {
64 | sb.append(SVG_RELATIVE_CUBIC_BEZIER_CURVE);
65 | sb.append(sControlPoint1);
66 | } else {
67 | if (!sControlPoint1.startsWith("-")) {
68 | sb.append(" ");
69 | }
70 | sb.append(sControlPoint1);
71 | }
72 |
73 | if (!sControlPoint2.startsWith("-")) {
74 | sb.append(" ");
75 | }
76 | sb.append(sControlPoint2);
77 |
78 | if (!sEndPoint.startsWith("-")) {
79 | sb.append(" ");
80 | }
81 | sb.append(sEndPoint);
82 |
83 | // discard zero curve
84 | final String svg = sb.toString();
85 | if ("c0 0 0 0 0 0".equals(svg)) {
86 | return "";
87 | } else {
88 | return svg;
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/whosmyqueen/signdemo/view/SignatureView.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signdemo.view;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.os.Build;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 |
15 | /**
16 | * Created by 郑志辉 on 2016/9/3.
17 | */
18 | public class SignatureView extends View {
19 |
20 | private Paint paint = new Paint();
21 | private Path path = new Path();
22 | private Canvas mCanvas;
23 | private Bitmap drawBitmap;
24 |
25 | public SignatureView(Context context) {
26 | super(context);
27 | init();
28 | }
29 |
30 | public SignatureView(Context context, AttributeSet attrs) {
31 | super(context, attrs);
32 | init();
33 | }
34 |
35 | public SignatureView(Context context, AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | init();
38 | }
39 |
40 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
41 | public SignatureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
42 | super(context, attrs, defStyleAttr, defStyleRes);
43 | init();
44 | }
45 |
46 | public void init() {
47 | paint.setAntiAlias(true);
48 | paint.setColor(Color.BLACK);
49 | paint.setStyle(Paint.Style.STROKE);
50 | paint.setStrokeJoin(Paint.Join.ROUND);
51 | paint.setStrokeWidth(5f);
52 | }
53 |
54 | @Override
55 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
56 | super.onSizeChanged(w, h, oldw, oldh);
57 | drawBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
58 | mCanvas = new Canvas(drawBitmap);
59 | }
60 |
61 | @Override
62 | protected void onDraw(Canvas canvas) {
63 | super.onDraw(canvas);
64 | mCanvas.drawBitmap(drawBitmap,0,0,paint);
65 | mCanvas.drawPath(path, paint);
66 | }
67 |
68 | @Override
69 | public boolean onTouchEvent(MotionEvent event) {
70 | float eventX = event.getX();
71 | float eventY = event.getY();
72 | switch (event.getAction()) {
73 | case MotionEvent.ACTION_DOWN:
74 | path.moveTo(eventX, eventY);
75 | invalidate();
76 | return true;
77 | case MotionEvent.ACTION_MOVE:
78 | case MotionEvent.ACTION_UP:
79 | path.lineTo(eventX, eventY);
80 | invalidate();
81 | break;
82 | default:
83 | return false;
84 | }
85 |
86 | switch (event.getAction()) {
87 | case MotionEvent.ACTION_MOVE:
88 | case MotionEvent.ACTION_UP:
89 | // When the hardware tracks events faster than they are delivered,
90 | // the event will contain a history of those skipped points.
91 | int historySize = event.getHistorySize();
92 | for (int i = 0; i < historySize; i++) {
93 | float historicalX = event.getHistoricalX(i);
94 | float historicalY = event.getHistoricalY(i);
95 | path.lineTo(historicalX, historicalY);
96 | }
97 |
98 | // After replaying history, connect the line to the touch point.
99 | path.lineTo(eventX, eventY);
100 | invalidate();
101 | break;
102 | }
103 | // Schedules a repaint.
104 |
105 | return true;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/whosmyqueen/signdemo/view/SignView.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signdemo.view;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.os.Build;
12 | import android.util.AttributeSet;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 |
16 | import com.whosmyqueen.signdemo.R;
17 |
18 |
19 | /**
20 | * Created by 郑志辉 on 2016/9/3.
21 | */
22 | public class SignView extends View {
23 | public SignView(Context context) {
24 | super(context);
25 | initialize();
26 | }
27 |
28 | public SignView(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | initialize();
31 | }
32 |
33 | public SignView(Context context, AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | initialize();
36 | }
37 |
38 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
39 | public SignView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
40 | super(context, attrs, defStyleAttr, defStyleRes);
41 | initialize();
42 | }
43 |
44 | private Resources myResources;
45 |
46 | // 画笔,定义绘制属性
47 | private Paint myPaint;
48 | private Paint mBitmapPaint;
49 |
50 | // 绘制路径
51 | private Path myPath;
52 |
53 | // 画布及其底层位图
54 | private Bitmap myBitmap;
55 | private Canvas myCanvas;
56 |
57 | private float mX, mY;
58 | private static final float TOUCH_TOLERANCE = 4;
59 |
60 | // 记录宽度和高度
61 | private int mWidth;
62 | private int mHeight;
63 |
64 |
65 | /**
66 | * 初始化工作
67 | */
68 | private void initialize() {
69 | // 获取一个资源引用
70 | myResources = getResources();
71 |
72 | // 绘制自由曲线用的画笔
73 | myPaint = new Paint();
74 | myPaint.setAntiAlias(true);
75 | myPaint.setDither(true);
76 | myPaint.setColor(myResources.getColor(R.color.black));
77 | myPaint.setStyle(Paint.Style.STROKE);
78 | myPaint.setStrokeJoin(Paint.Join.ROUND);
79 | myPaint.setStrokeCap(Paint.Cap.ROUND);
80 | myPaint.setStrokeWidth(12);
81 |
82 | myPath = new Path();
83 |
84 | mBitmapPaint = new Paint(Paint.DITHER_FLAG);
85 |
86 | }
87 |
88 | @Override
89 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
90 | super.onSizeChanged(w, h, oldw, oldh);
91 | mWidth = w;
92 | mHeight = h;
93 | myBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
94 | myCanvas = new Canvas(myBitmap);
95 | }
96 |
97 | @Override
98 | public boolean onTouchEvent(MotionEvent event) {
99 | float x = event.getX();
100 | float y = event.getY();
101 |
102 | switch (event.getAction()) {
103 | case MotionEvent.ACTION_DOWN:
104 | touch_start(x, y);
105 | invalidate();
106 | break;
107 | case MotionEvent.ACTION_MOVE:
108 | touch_move(x, y);
109 | invalidate();
110 | break;
111 | case MotionEvent.ACTION_UP:
112 | touch_up();
113 | invalidate();
114 | break;
115 | }
116 | return true;
117 | }
118 |
119 | @Override
120 | protected void onDraw(Canvas canvas) {
121 | super.onDraw(canvas);
122 |
123 | // 背景颜色
124 | // canvas.drawColor(getResources().getColor(R.color.blue_dark));
125 |
126 | // 如果不调用这个方法,绘制结束后画布将清空
127 | canvas.drawBitmap(myBitmap, 0, 0, mBitmapPaint);
128 |
129 | // 绘制路径
130 | canvas.drawPath(myPath, myPaint);
131 |
132 | }
133 |
134 | private void touch_start(float x, float y) {
135 | myPath.reset();
136 | myPath.moveTo(x, y);
137 | mX = x;
138 | mY = y;
139 | }
140 |
141 | private void touch_move(float x, float y) {
142 | float dx = Math.abs(x - mX);
143 | float dy = Math.abs(y - mY);
144 | if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
145 | myPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
146 | mX = x;
147 | mY = y;
148 | }
149 | }
150 |
151 | private void touch_up() {
152 | myPath.lineTo(mX, mY);
153 | // commit the path to our offscreen
154 | // 如果少了这一句,笔触抬起时myPath重置,那么绘制的线将消失
155 | myCanvas.drawPath(myPath, myPaint);
156 | // kill this so we don't double draw
157 | myPath.reset();
158 | }
159 |
160 | /**
161 | * 清除整个图像
162 | */
163 | public void clear() {
164 | // 清除方法1:重新生成位图
165 | // myBitmap = Bitmap
166 | // .createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
167 | // myCanvas = new Canvas(myBitmap);
168 | // 清除方法2:将位图清除为白色
169 | myBitmap.eraseColor(Color.TRANSPARENT);
170 | // 两种清除方法都必须加上后面这两步:
171 | // 路径重置
172 | myPath.reset();
173 | // 刷新绘制
174 | invalidate();
175 | }
176 |
177 | public Bitmap getImage() {
178 | return myBitmap;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/signpad/src/main/java/com/whosmyqueen/signpad/views/SignaturePad.java:
--------------------------------------------------------------------------------
1 | package com.whosmyqueen.signpad.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.RectF;
12 | import android.util.AttributeSet;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.ViewTreeObserver;
16 |
17 | import com.whosmyqueen.signpad.R;
18 | import com.whosmyqueen.signpad.utils.Bezier;
19 | import com.whosmyqueen.signpad.utils.ControlTimedPoints;
20 | import com.whosmyqueen.signpad.utils.SvgBuilder;
21 | import com.whosmyqueen.signpad.utils.TimedPoint;
22 | import com.whosmyqueen.signpad.view.ViewCompat;
23 | import com.whosmyqueen.signpad.view.ViewTreeObserverCompat;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | public class SignaturePad extends View {
29 | //View state
30 | private List mPoints;
31 | private boolean mIsEmpty;
32 | private float mLastTouchX;
33 | private float mLastTouchY;
34 | private float mLastVelocity;
35 | private float mLastWidth;
36 | private RectF mDirtyRect;
37 |
38 | private final SvgBuilder mSvgBuilder = new SvgBuilder();
39 |
40 | // Cache
41 | private List mPointsCache = new ArrayList<>();
42 | private ControlTimedPoints mControlTimedPointsCached = new ControlTimedPoints();
43 | private Bezier mBezierCached = new Bezier();
44 |
45 | //Configurable parameters
46 | private int mMinWidth;
47 | private int mMaxWidth;
48 | private float mVelocityFilterWeight;
49 | private OnSignedListener mOnSignedListener;
50 | private boolean mClearOnDoubleClick;
51 |
52 | //Click values
53 | private long mFirstClick;
54 | private int mCountClick;
55 | private static final int DOUBLE_CLICK_DELAY_MS = 200;
56 |
57 | //Default attribute values
58 | private final int DEFAULT_ATTR_PEN_MIN_WIDTH_PX = 3;
59 | private final int DEFAULT_ATTR_PEN_MAX_WIDTH_PX = 7;
60 | private final int DEFAULT_ATTR_PEN_COLOR = Color.BLACK;
61 | private final float DEFAULT_ATTR_VELOCITY_FILTER_WEIGHT = 0.9f;
62 | private final boolean DEFAULT_ATTR_CLEAR_ON_DOUBLE_CLICK = false;
63 |
64 | private Paint mPaint = new Paint();
65 | private Bitmap mSignatureBitmap = null;
66 | private Canvas mSignatureBitmapCanvas = null;
67 |
68 | public SignaturePad(Context context, AttributeSet attrs) {
69 | super(context, attrs);
70 |
71 | TypedArray a = context.getTheme().obtainStyledAttributes(
72 | attrs,
73 | R.styleable.SignaturePad,
74 | 0, 0);
75 |
76 | //Configurable parameters
77 | try {
78 | mMinWidth = a.getDimensionPixelSize(R.styleable.SignaturePad_penMinWidth, convertDpToPx(DEFAULT_ATTR_PEN_MIN_WIDTH_PX));
79 | mMaxWidth = a.getDimensionPixelSize(R.styleable.SignaturePad_penMaxWidth, convertDpToPx(DEFAULT_ATTR_PEN_MAX_WIDTH_PX));
80 | mPaint.setColor(a.getColor(R.styleable.SignaturePad_penColor, DEFAULT_ATTR_PEN_COLOR));
81 | mVelocityFilterWeight = a.getFloat(R.styleable.SignaturePad_velocityFilterWeight, DEFAULT_ATTR_VELOCITY_FILTER_WEIGHT);
82 | mClearOnDoubleClick = a.getBoolean(R.styleable.SignaturePad_clearOnDoubleClick, DEFAULT_ATTR_CLEAR_ON_DOUBLE_CLICK);
83 | } finally {
84 | a.recycle();
85 | }
86 |
87 | //Fixed parameters
88 | mPaint.setAntiAlias(true);
89 | mPaint.setStyle(Paint.Style.STROKE);
90 | mPaint.setStrokeCap(Paint.Cap.ROUND);
91 | mPaint.setStrokeJoin(Paint.Join.ROUND);
92 |
93 | //Dirty rectangle to update only the changed portion of the view
94 | mDirtyRect = new RectF();
95 |
96 | clear();
97 | }
98 |
99 | /**
100 | * Set the pen color from a given resource.
101 | * If the resource is not found, {@link Color#BLACK} is assumed.
102 | *
103 | * @param colorRes the color resource.
104 | */
105 | public void setPenColorRes(int colorRes) {
106 | try {
107 | setPenColor(getResources().getColor(colorRes));
108 | } catch (Resources.NotFoundException ex) {
109 | setPenColor(Color.parseColor("#000000"));
110 | }
111 | }
112 |
113 | /**
114 | * Set the pen color from a given color.
115 | *
116 | * @param color the color.
117 | */
118 | public void setPenColor(int color) {
119 | mPaint.setColor(color);
120 | }
121 |
122 | /**
123 | * Set the minimum width of the stroke in pixel.
124 | *
125 | * @param minWidth the width in dp.
126 | */
127 | public void setMinWidth(float minWidth) {
128 | mMinWidth = convertDpToPx(minWidth);
129 | }
130 |
131 | /**
132 | * Set the maximum width of the stroke in pixel.
133 | *
134 | * @param maxWidth the width in dp.
135 | */
136 | public void setMaxWidth(float maxWidth) {
137 | mMaxWidth = convertDpToPx(maxWidth);
138 | }
139 |
140 | /**
141 | * Set the velocity filter weight.
142 | *
143 | * @param velocityFilterWeight the weight.
144 | */
145 | public void setVelocityFilterWeight(float velocityFilterWeight) {
146 | mVelocityFilterWeight = velocityFilterWeight;
147 | }
148 |
149 | public void clear() {
150 | mSvgBuilder.clear();
151 | mPoints = new ArrayList<>();
152 | mLastVelocity = 0;
153 | mLastWidth = (mMinWidth + mMaxWidth) / 2;
154 |
155 | if (mSignatureBitmap != null) {
156 | mSignatureBitmap = null;
157 | ensureSignatureBitmap();
158 | }
159 |
160 | setIsEmpty(true);
161 |
162 | invalidate();
163 | }
164 |
165 | @Override
166 | public boolean onTouchEvent(MotionEvent event) {
167 | if (!isEnabled())
168 | return false;
169 |
170 | float eventX = event.getX();
171 | float eventY = event.getY();
172 |
173 | switch (event.getAction()) {
174 | case MotionEvent.ACTION_DOWN:
175 | getParent().requestDisallowInterceptTouchEvent(true);
176 | mPoints.clear();
177 | if (isDoubleClick()) break;
178 | mLastTouchX = eventX;
179 | mLastTouchY = eventY;
180 | addPoint(getNewPoint(eventX, eventY));
181 | if(mOnSignedListener != null) mOnSignedListener.onStartSigning();
182 |
183 | case MotionEvent.ACTION_MOVE:
184 | resetDirtyRect(eventX, eventY);
185 | addPoint(getNewPoint(eventX, eventY));
186 | break;
187 |
188 | case MotionEvent.ACTION_UP:
189 | resetDirtyRect(eventX, eventY);
190 | addPoint(getNewPoint(eventX, eventY));
191 | getParent().requestDisallowInterceptTouchEvent(true);
192 | setIsEmpty(false);
193 | break;
194 |
195 | default:
196 | return false;
197 | }
198 |
199 | //invalidate();
200 | invalidate(
201 | (int) (mDirtyRect.left - mMaxWidth),
202 | (int) (mDirtyRect.top - mMaxWidth),
203 | (int) (mDirtyRect.right + mMaxWidth),
204 | (int) (mDirtyRect.bottom + mMaxWidth));
205 |
206 | return true;
207 | }
208 |
209 | @Override
210 | protected void onDraw(Canvas canvas) {
211 | if (mSignatureBitmap != null) {
212 | canvas.drawBitmap(mSignatureBitmap, 0, 0, mPaint);
213 | }
214 | }
215 |
216 | public void setOnSignedListener(OnSignedListener listener) {
217 | mOnSignedListener = listener;
218 | }
219 |
220 | public boolean isEmpty() {
221 | return mIsEmpty;
222 | }
223 |
224 | public String getSignatureSvg() {
225 | int width = getTransparentSignatureBitmap().getWidth();
226 | int height = getTransparentSignatureBitmap().getHeight();
227 | return mSvgBuilder.build(width, height);
228 | }
229 |
230 | public Bitmap getSignatureBitmap() {
231 | Bitmap originalBitmap = getTransparentSignatureBitmap();
232 | Bitmap whiteBgBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
233 | Canvas canvas = new Canvas(whiteBgBitmap);
234 | canvas.drawColor(Color.WHITE);
235 | canvas.drawBitmap(originalBitmap, 0, 0, null);
236 | return whiteBgBitmap;
237 | }
238 |
239 | public void setSignatureBitmap(final Bitmap signature) {
240 | // View was laid out...
241 | if (ViewCompat.isLaidOut(this)) {
242 | clear();
243 | ensureSignatureBitmap();
244 |
245 | RectF tempSrc = new RectF();
246 | RectF tempDst = new RectF();
247 |
248 | int dWidth = signature.getWidth();
249 | int dHeight = signature.getHeight();
250 | int vWidth = getWidth();
251 | int vHeight = getHeight();
252 |
253 | // Generate the required transform.
254 | tempSrc.set(0, 0, dWidth, dHeight);
255 | tempDst.set(0, 0, vWidth, vHeight);
256 |
257 | Matrix drawMatrix = new Matrix();
258 | drawMatrix.setRectToRect(tempSrc, tempDst, Matrix.ScaleToFit.CENTER);
259 |
260 | Canvas canvas = new Canvas(mSignatureBitmap);
261 | canvas.drawBitmap(signature, drawMatrix, null);
262 | setIsEmpty(false);
263 | invalidate();
264 | }
265 | // View not laid out yet e.g. called from onCreate(), onRestoreInstanceState()...
266 | else {
267 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
268 | @Override
269 | public void onGlobalLayout() {
270 | // Remove layout listener...
271 | ViewTreeObserverCompat.removeOnGlobalLayoutListener(getViewTreeObserver(), this);
272 |
273 | // Signature bitmap...
274 | setSignatureBitmap(signature);
275 | }
276 | });
277 | }
278 | }
279 |
280 | public Bitmap getTransparentSignatureBitmap() {
281 | ensureSignatureBitmap();
282 | return mSignatureBitmap;
283 | }
284 |
285 | public Bitmap getTransparentSignatureBitmap(boolean trimBlankSpace) {
286 |
287 | if (!trimBlankSpace) {
288 | return getTransparentSignatureBitmap();
289 | }
290 |
291 | ensureSignatureBitmap();
292 |
293 | int imgHeight = mSignatureBitmap.getHeight();
294 | int imgWidth = mSignatureBitmap.getWidth();
295 |
296 | int backgroundColor = Color.TRANSPARENT;
297 |
298 | int xMin = Integer.MAX_VALUE,
299 | xMax = Integer.MIN_VALUE,
300 | yMin = Integer.MAX_VALUE,
301 | yMax = Integer.MIN_VALUE;
302 |
303 | boolean foundPixel = false;
304 |
305 | // Find xMin
306 | for (int x = 0; x < imgWidth; x++) {
307 | boolean stop = false;
308 | for (int y = 0; y < imgHeight; y++) {
309 | if (mSignatureBitmap.getPixel(x, y) != backgroundColor) {
310 | xMin = x;
311 | stop = true;
312 | foundPixel = true;
313 | break;
314 | }
315 | }
316 | if (stop)
317 | break;
318 | }
319 |
320 | // Image is empty...
321 | if (!foundPixel)
322 | return null;
323 |
324 | // Find yMin
325 | for (int y = 0; y < imgHeight; y++) {
326 | boolean stop = false;
327 | for (int x = xMin; x < imgWidth; x++) {
328 | if (mSignatureBitmap.getPixel(x, y) != backgroundColor) {
329 | yMin = y;
330 | stop = true;
331 | break;
332 | }
333 | }
334 | if (stop)
335 | break;
336 | }
337 |
338 | // Find xMax
339 | for (int x = imgWidth - 1; x >= xMin; x--) {
340 | boolean stop = false;
341 | for (int y = yMin; y < imgHeight; y++) {
342 | if (mSignatureBitmap.getPixel(x, y) != backgroundColor) {
343 | xMax = x;
344 | stop = true;
345 | break;
346 | }
347 | }
348 | if (stop)
349 | break;
350 | }
351 |
352 | // Find yMax
353 | for (int y = imgHeight - 1; y >= yMin; y--) {
354 | boolean stop = false;
355 | for (int x = xMin; x <= xMax; x++) {
356 | if (mSignatureBitmap.getPixel(x, y) != backgroundColor) {
357 | yMax = y;
358 | stop = true;
359 | break;
360 | }
361 | }
362 | if (stop)
363 | break;
364 | }
365 |
366 | return Bitmap.createBitmap(mSignatureBitmap, xMin, yMin, xMax - xMin, yMax - yMin);
367 | }
368 |
369 | private boolean isDoubleClick() {
370 | if (mClearOnDoubleClick) {
371 | if (mFirstClick != 0 && System.currentTimeMillis() - mFirstClick > DOUBLE_CLICK_DELAY_MS) {
372 | mCountClick = 0;
373 | }
374 | mCountClick++;
375 | if (mCountClick == 1) {
376 | mFirstClick = System.currentTimeMillis();
377 | } else if (mCountClick == 2) {
378 | long lastClick = System.currentTimeMillis();
379 | if (lastClick - mFirstClick < DOUBLE_CLICK_DELAY_MS) {
380 | this.clear();
381 | return true;
382 | }
383 | }
384 | }
385 | return false;
386 | }
387 |
388 | private TimedPoint getNewPoint(float x, float y) {
389 | int mCacheSize = mPointsCache.size();
390 | TimedPoint timedPoint;
391 | if (mCacheSize == 0) {
392 | // Cache is empty, create a new point
393 | timedPoint = new TimedPoint();
394 | } else {
395 | // Get point from cache
396 | timedPoint = mPointsCache.remove(mCacheSize-1);
397 | }
398 |
399 | return timedPoint.set(x, y);
400 | }
401 |
402 | private void recyclePoint(TimedPoint point) {
403 | mPointsCache.add(point);
404 | }
405 |
406 | private void addPoint(TimedPoint newPoint) {
407 | mPoints.add(newPoint);
408 |
409 | int pointsCount = mPoints.size();
410 | if (pointsCount > 3) {
411 |
412 | ControlTimedPoints tmp = calculateCurveControlPoints(mPoints.get(0), mPoints.get(1), mPoints.get(2));
413 | TimedPoint c2 = tmp.c2;
414 | recyclePoint(tmp.c1);
415 |
416 | tmp = calculateCurveControlPoints(mPoints.get(1), mPoints.get(2), mPoints.get(3));
417 | TimedPoint c3 = tmp.c1;
418 | recyclePoint(tmp.c2);
419 |
420 | Bezier curve = mBezierCached.set(mPoints.get(1), c2, c3, mPoints.get(2));
421 |
422 | TimedPoint startPoint = curve.startPoint;
423 | TimedPoint endPoint = curve.endPoint;
424 |
425 | float velocity = endPoint.velocityFrom(startPoint);
426 | velocity = Float.isNaN(velocity) ? 0.0f : velocity;
427 |
428 | velocity = mVelocityFilterWeight * velocity
429 | + (1 - mVelocityFilterWeight) * mLastVelocity;
430 |
431 | // The new width is a function of the velocity. Higher velocities
432 | // correspond to thinner strokes.
433 | float newWidth = strokeWidth(velocity);
434 |
435 | // The Bezier's width starts out as last curve's final width, and
436 | // gradually changes to the stroke width just calculated. The new
437 | // width calculation is based on the velocity between the Bezier's
438 | // start and end mPoints.
439 | addBezier(curve, mLastWidth, newWidth);
440 |
441 | mLastVelocity = velocity;
442 | mLastWidth = newWidth;
443 |
444 | // Remove the first element from the list,
445 | // so that we always have no more than 4 mPoints in mPoints array.
446 | recyclePoint(mPoints.remove(0));
447 |
448 | recyclePoint(c2);
449 | recyclePoint(c3);
450 |
451 | } else if (pointsCount == 1) {
452 | // To reduce the initial lag make it work with 3 mPoints
453 | // by duplicating the first point
454 | TimedPoint firstPoint = mPoints.get(0);
455 | mPoints.add(getNewPoint(firstPoint.x, firstPoint.y));
456 | }
457 | }
458 |
459 | private void addBezier(Bezier curve, float startWidth, float endWidth) {
460 | mSvgBuilder.append(curve, (startWidth + endWidth) / 2);
461 | ensureSignatureBitmap();
462 | float originalWidth = mPaint.getStrokeWidth();
463 | float widthDelta = endWidth - startWidth;
464 | float drawSteps = (float) Math.floor(curve.length());
465 |
466 | for (int i = 0; i < drawSteps; i++) {
467 | // Calculate the Bezier (x, y) coordinate for this step.
468 | float t = ((float) i) / drawSteps;
469 | float tt = t * t;
470 | float ttt = tt * t;
471 | float u = 1 - t;
472 | float uu = u * u;
473 | float uuu = uu * u;
474 |
475 | float x = uuu * curve.startPoint.x;
476 | x += 3 * uu * t * curve.control1.x;
477 | x += 3 * u * tt * curve.control2.x;
478 | x += ttt * curve.endPoint.x;
479 |
480 | float y = uuu * curve.startPoint.y;
481 | y += 3 * uu * t * curve.control1.y;
482 | y += 3 * u * tt * curve.control2.y;
483 | y += ttt * curve.endPoint.y;
484 |
485 | // Set the incremental stroke width and draw.
486 | mPaint.setStrokeWidth(startWidth + ttt * widthDelta);
487 | mSignatureBitmapCanvas.drawPoint(x, y, mPaint);
488 | expandDirtyRect(x, y);
489 | }
490 |
491 | mPaint.setStrokeWidth(originalWidth);
492 | }
493 |
494 | private ControlTimedPoints calculateCurveControlPoints(TimedPoint s1, TimedPoint s2, TimedPoint s3) {
495 | float dx1 = s1.x - s2.x;
496 | float dy1 = s1.y - s2.y;
497 | float dx2 = s2.x - s3.x;
498 | float dy2 = s2.y - s3.y;
499 |
500 | float m1X = (s1.x + s2.x) / 2.0f;
501 | float m1Y = (s1.y + s2.y) / 2.0f;
502 | float m2X = (s2.x + s3.x) / 2.0f;
503 | float m2Y = (s2.y + s3.y) / 2.0f;
504 |
505 | float l1 = (float) Math.sqrt(dx1 * dx1 + dy1 * dy1);
506 | float l2 = (float) Math.sqrt(dx2 * dx2 + dy2 * dy2);
507 |
508 | float dxm = (m1X - m2X);
509 | float dym = (m1Y - m2Y);
510 | float k = l2 / (l1 + l2);
511 | if (Float.isNaN(k)) k = 0.0f;
512 | float cmX = m2X + dxm * k;
513 | float cmY = m2Y + dym * k;
514 |
515 | float tx = s2.x - cmX;
516 | float ty = s2.y - cmY;
517 |
518 | return mControlTimedPointsCached.set(getNewPoint(m1X + tx, m1Y + ty), getNewPoint(m2X + tx, m2Y + ty));
519 | }
520 |
521 | private float strokeWidth(float velocity) {
522 | return Math.max(mMaxWidth / (velocity + 1), mMinWidth);
523 | }
524 |
525 | /**
526 | * Called when replaying history to ensure the dirty region includes all
527 | * mPoints.
528 | *
529 | * @param historicalX the previous x coordinate.
530 | * @param historicalY the previous y coordinate.
531 | */
532 | private void expandDirtyRect(float historicalX, float historicalY) {
533 | if (historicalX < mDirtyRect.left) {
534 | mDirtyRect.left = historicalX;
535 | } else if (historicalX > mDirtyRect.right) {
536 | mDirtyRect.right = historicalX;
537 | }
538 | if (historicalY < mDirtyRect.top) {
539 | mDirtyRect.top = historicalY;
540 | } else if (historicalY > mDirtyRect.bottom) {
541 | mDirtyRect.bottom = historicalY;
542 | }
543 | }
544 |
545 | /**
546 | * Resets the dirty region when the motion event occurs.
547 | *
548 | * @param eventX the event x coordinate.
549 | * @param eventY the event y coordinate.
550 | */
551 | private void resetDirtyRect(float eventX, float eventY) {
552 |
553 | // The mLastTouchX and mLastTouchY were set when the ACTION_DOWN motion event occurred.
554 | mDirtyRect.left = Math.min(mLastTouchX, eventX);
555 | mDirtyRect.right = Math.max(mLastTouchX, eventX);
556 | mDirtyRect.top = Math.min(mLastTouchY, eventY);
557 | mDirtyRect.bottom = Math.max(mLastTouchY, eventY);
558 | }
559 |
560 | private void setIsEmpty(boolean newValue) {
561 | mIsEmpty = newValue;
562 | if (mOnSignedListener != null) {
563 | if (mIsEmpty) {
564 | mOnSignedListener.onClear();
565 | } else {
566 | mOnSignedListener.onSigned();
567 | }
568 | }
569 | }
570 |
571 | private void ensureSignatureBitmap() {
572 | if (mSignatureBitmap == null) {
573 | mSignatureBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
574 | Bitmap.Config.ARGB_8888);
575 | mSignatureBitmapCanvas = new Canvas(mSignatureBitmap);
576 | }
577 | }
578 |
579 | private int convertDpToPx(float dp){
580 | return Math.round(getContext().getResources().getDisplayMetrics().density * dp);
581 | }
582 |
583 | public interface OnSignedListener {
584 | void onStartSigning();
585 | void onSigned();
586 | void onClear();
587 | }
588 | }
589 |
--------------------------------------------------------------------------------