├── 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/v/whosmyqueen/SignPad.svg)](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 |