├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── 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
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ ├── button_bg.xml
│ │ │ │ └── edittext_bg.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zhangym
│ │ │ └── verificationcodeview
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zhangym
│ │ │ └── verificationcodeview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zhangym
│ │ └── verificationcodeview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zhangym
│ │ │ └── customview
│ │ │ └── VerificationCodeView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zhangym
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zhangym
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── caches
│ └── build_file_checksums.ser
├── encodings.xml
├── vcs.xml
├── libraries
│ ├── com_squareup_javawriter_2_1_1_jar.xml
│ ├── org_hamcrest_hamcrest_library_1_3_jar.xml
│ ├── com_google_code_findbugs_jsr305_2_0_1_jar.xml
│ ├── org_hamcrest_hamcrest_integration_1_3_jar.xml
│ ├── Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml
│ ├── javax_annotation_javax_annotation_api_1_2_jar.xml
│ ├── com_android_support_support_v4_25_1_0.xml
│ ├── junit_junit_4_12_jar.xml
│ ├── Gradle__com_android_support_support_v4_25_1_0.xml
│ ├── Gradle__junit_junit_4_12_jar.xml
│ ├── javax_inject_javax_inject_1_jar.xml
│ ├── Gradle__javax_inject_javax_inject_1_jar.xml
│ ├── org_hamcrest_hamcrest_core_1_3_jar.xml
│ ├── Gradle__com_squareup_javawriter_2_1_1_jar.xml
│ ├── Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml
│ ├── Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml
│ ├── Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml
│ ├── Gradle__javax_annotation_javax_annotation_api_1_2_jar.xml
│ ├── com_android_support_support_annotations_25_1_0_jar.xml
│ ├── Gradle__com_android_support_support_annotations_25_1_0_jar.xml
│ ├── com_android_support_test_rules_0_5.xml
│ ├── com_android_support_test_runner_0_5.xml
│ ├── Gradle__com_android_support_test_rules_0_5.xml
│ ├── Gradle__com_android_support_test_runner_0_5.xml
│ ├── com_android_support_appcompat_v7_25_1_0.xml
│ ├── Gradle__com_android_support_appcompat_v7_25_1_0.xml
│ ├── com_android_support_support_compat_25_1_0.xml
│ ├── com_android_support_support_core_ui_25_1_0.xml
│ ├── Gradle__com_android_support_support_compat_25_1_0.xml
│ ├── com_android_support_support_fragment_25_1_0.xml
│ ├── Gradle__com_android_support_support_core_ui_25_1_0.xml
│ ├── Gradle__com_android_support_support_fragment_25_1_0.xml
│ ├── com_android_support_support_core_utils_25_1_0.xml
│ ├── com_android_support_test_espresso_espresso_core_2_2_2.xml
│ ├── Gradle__com_android_support_support_core_utils_25_1_0.xml
│ ├── com_android_support_support_media_compat_25_1_0.xml
│ ├── Gradle__com_android_support_test_espresso_espresso_core_2_2_2.xml
│ ├── Gradle__com_android_support_support_media_compat_25_1_0.xml
│ ├── com_android_support_support_vector_drawable_25_1_0.xml
│ ├── com_android_support_animated_vector_drawable_25_1_0.xml
│ ├── Gradle__com_android_support_support_vector_drawable_25_1_0.xml
│ ├── Gradle__com_android_support_animated_vector_drawable_25_1_0.xml
│ ├── com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml
│ ├── Gradle__com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml
│ ├── com_android_support_test_exposed_instrumentation_api_publish_0_5.xml
│ └── Gradle__com_android_support_test_exposed_instrumentation_api_publish_0_5.xml
├── modules.xml
├── checkstyle-idea.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
├── codeStyles
│ └── Project.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VerificationCodeView
3 |
4 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yongming9011/VerificationCodeView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Sep 09 21:44:18 CST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VerificationCodeView
3 | 登 录
4 | 用户名:
5 | 密 码:
6 | 验证码:
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/libraries/com_squareup_javawriter_2_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/org_hamcrest_hamcrest_library_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/com_google_code_findbugs_jsr305_2_0_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/org_hamcrest_hamcrest_integration_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/javax_annotation_javax_annotation_api_1_2_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/test/java/com/zhangym/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangym;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zhangym/verificationcodeview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangym.verificationcodeview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_v4_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/junit_junit_4_12_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_v4_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__junit_junit_4_12_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/javax_inject_javax_inject_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__javax_inject_javax_inject_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/org_hamcrest_hamcrest_core_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_squareup_javawriter_2_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/edittext_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__javax_annotation_javax_annotation_api_1_2_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/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 /Users/zhangyongming/Library/Android/sdk/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 |
--------------------------------------------------------------------------------
/library/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 /Users/zhangyongming/Library/Android/sdk/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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_annotations_25_1_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_annotations_25_1_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_test_rules_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_test_runner_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_test_rules_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_test_runner_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/zhangym/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangym;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zhangym.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_appcompat_v7_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_appcompat_v7_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_compat_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_core_ui_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_compat_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_fragment_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_core_ui_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zhangym/verificationcodeview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangym.verificationcodeview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zhangym.verificationcodeview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_fragment_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_core_utils_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_test_espresso_espresso_core_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_core_utils_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_media_compat_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_test_espresso_espresso_core_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_media_compat_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_support_vector_drawable_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_animated_vector_drawable_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_support_vector_drawable_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_animated_vector_drawable_25_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.yongming9011'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion '26.0.2'
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | compile 'com.android.support:appcompat-v7:25.1.0'
32 | testCompile 'junit:junit:4.12'
33 | }
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/com_android_support_test_exposed_instrumentation_api_publish_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_android_support_test_exposed_instrumentation_api_publish_0_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion '26.0.2'
6 | defaultConfig {
7 | applicationId "com.zhangym.verificationcodeview"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | javaCompileOptions {
14 | annotationProcessorOptions {
15 | includeCompileClasspath = true
16 | }
17 | }
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(include: ['*.jar'], dir: 'libs')
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.1.0'
33 | testCompile 'junit:junit:4.12'
34 | compile project(':library')
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/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/zhangym/verificationcodeview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhangym.verificationcodeview;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.view.Window;
8 | import android.widget.Button;
9 | import android.widget.EditText;
10 | import android.widget.Toast;
11 |
12 | import com.zhangym.customview.VerificationCodeView;
13 |
14 | import java.util.Random;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | private VerificationCodeView mCodeView;
18 | private Random mRandom = new Random();
19 | private EditText etUsername;
20 | private EditText etPassword;
21 | private EditText etVerification;
22 | private Button btnLogin;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
28 | setContentView(R.layout.activity_main);
29 |
30 | initViews();
31 |
32 | login();
33 |
34 | mCodeView.setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | String s = String.valueOf(mRandom.nextInt(10)) +
38 | String.valueOf(mRandom.nextInt(10)) +
39 | String.valueOf(mRandom.nextInt(10)) +
40 | String.valueOf(mRandom.nextInt(10));
41 |
42 | mCodeView.setVerificationText(s);
43 | }
44 | });
45 |
46 | btnLogin.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | login();
50 | }
51 | });
52 | }
53 |
54 | private void login() {
55 | String userName = etUsername.getText().toString().trim();
56 | String password = etPassword.getText().toString().trim();
57 | String verification = etVerification.getText().toString().trim();
58 |
59 | if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(password) || TextUtils.isEmpty(verification)) {
60 | Toast.makeText(this, "请输入完整信息!", Toast.LENGTH_SHORT).show();
61 | } else {
62 | if ("zhangym".equals(userName) && "123".equals(password) && mCodeView.getVerificationText().equals
63 | (verification)) {
64 | Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show();
65 | } else if (!"zhangym".equals(userName)) {
66 | Toast.makeText(this, "用户名错误", Toast.LENGTH_SHORT).show();
67 | } else if (!"123".equals(password)) {
68 | Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
69 | } else if (!mCodeView.getVerificationText().equals(verification)) {
70 | Toast.makeText(this, "验证码错误", Toast.LENGTH_SHORT).show();
71 | }
72 | }
73 | }
74 |
75 | private void initViews() {
76 | mCodeView = (VerificationCodeView) findViewById(R.id.verificationCodeView);
77 | etUsername = (EditText) findViewById(R.id.et_username);
78 | etPassword = (EditText) findViewById(R.id.et_password);
79 | etVerification = (EditText) findViewById(R.id.et_verification);
80 | btnLogin = (Button) findViewById(R.id.btn_login);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
21 |
22 |
32 |
33 |
34 |
35 |
43 |
44 |
48 |
49 |
59 |
60 |
61 |
62 |
70 |
71 |
76 |
77 |
82 |
83 |
94 |
95 |
109 |
110 |
111 |
112 |
113 |
114 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 兄弟们,哥们早从Android脱坑了,入了后台的坑,该项目早已停止维护,要用于生产环境的请慎重!
2 |
3 | # 一、添加依赖
4 |
5 | 1. **Android Studio**:在项目的根目录下build.gradle里的allprojects下添加如下引用:
6 |
7 | ```groovy
8 | allprojects {
9 | repositories {
10 | ...
11 | maven { url 'https://jitpack.io' }
12 | }
13 | }
14 | ```
15 |
16 | 然后在app目录下 build.gradle 下添加依赖
17 |
18 | ```groovy
19 | dependencies {
20 | compile 'com.github.yongming9011:VerificationCodeView:v1.0'
21 | }
22 | ```
23 |
24 |
25 |
26 | 2. **Eclipse**:下载项目,将library里面的VerificationCodeView.java跟res/values/attrs.xml文件拷贝进项目。
27 |
28 | # 二、用法
29 |
30 | - 在布局中集成,注意需要在布局的根节点添加命名`xmlns:zhangym="http://schemas.android.com/apk/res-auto"` 方可使用自定义属性。
31 |
32 | ```xml
33 |
48 | ```
49 |
50 |
51 | - 对应属性说明如下:
52 |
53 | ```xml
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | ```
89 |
90 | 以上属性均有对应的 setter方法,也可以在Java代码中进行设置。
91 |
92 |
93 |
94 | # 三、对应方法的说明
95 |
96 | | 方法 | 说明 |
97 | | :--------------------------------------: | :------------------------: |
98 | | setShowInterferenceLines(boolean showInterferenceLines) | 设置是否显示干扰线条,默认显示 |
99 | | setShowInterferenceCircles(boolean showInterferenceCircles) | 设置是否显示干扰圆点,默认显示 |
100 | | setTextBold(boolean textBold) | 设置验证码文本是否加粗,默认不加粗 |
101 | | setCircleColorRandom(boolean circleColorRandom) | 设置干扰圆点是否为随机颜色,默认为随机 |
102 | | setLineColorRandom(boolean lineColorRandom) | 设置干扰线条颜色是否为随机,默认为随机 |
103 | | setVerificationText(String verificationText) | 设置验证码文本内容 |
104 | | setVerificationCodeBackground(int verificationCodeBackground) | 设置验证码的背景色,默认为灰色 |
105 | | setInterferenceLinesCount(int interferenceLinesCount) | 设置干扰线条的数量,默认为10条 |
106 | | setInterferenceLinesColor(int interferenceLinesColor) | 设置干扰线条的颜色,如果设置了颜色,则颜色不再 |
107 | | setInterferenceLinesWidth(float interferenceLinesWidth) | 设置干扰线条的宽度,默认为3 |
108 | | setInterferenceCirclesCount(int interferenceCirclesCount) | 设置干扰圆点的数量 |
109 | | setInterferenceCirclesColor(int interferenceCirclesColor) | 设置干扰圆点的颜色,如果设置,则不再随机 |
110 | | setInterferenceCirclesRadius(float interferenceCirclesRadius) | 设置干扰圆点的半径,默认为5 |
111 | | setTextColor(int textColor) | 设置验证码文本,默认黑色 |
112 | | setTextSize(int textSize) | 设置验证码文本大小 |
113 | | setUnderLine(boolean underLine) | 设置验证码文本是否有下划线 |
114 | | setTextSkewX(float textSkewX) | 设置验证码文本的倾斜值,正数左斜,负数右斜,默认为0 |
115 | | setStrokeWidth(float strokeWidth) | 设置验证码文本的宽度 |
116 |
117 |
118 |
119 | # 四、效果图
120 |
121 | 
122 |
123 |
124 | # 五、联系方式
125 |
126 | - [我的博客](http://zhangym.xyz/)
127 | - **Gmail**:yongming9011@gmail.com
128 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/library/src/main/java/com/zhangym/customview/VerificationCodeView.java:
--------------------------------------------------------------------------------
1 | package com.zhangym.customview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.Typeface;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.zhangym.R;
14 |
15 | import java.util.Random;
16 |
17 | /**
18 | * 验证码控件
19 | * Created by zhangyongming on 2017/1/14.
20 | */
21 | public class VerificationCodeView extends View {
22 | /**
23 | * 验证码文本
24 | */
25 | private String mVerificationText;
26 |
27 | /**
28 | * 验证码文本的颜色,默认为黑色
29 | */
30 | private int mTextColor = Color.BLACK;
31 |
32 | /**
33 | * 验证码文本大小,默认为16
34 | */
35 | private int mTextSize = 16;
36 |
37 | /**
38 | * 是否有下划线
39 | */
40 | private boolean isUnderLine;
41 |
42 | /**
43 | * 文本是否为粗体
44 | */
45 | private boolean isTextBold;
46 |
47 | /**
48 | * 文本的倾斜度,正数为左斜,负数为右斜,默认0f
49 | */
50 | private float mTextSkewX = 0f;
51 |
52 | // /**
53 | // * 文字风格
54 | // */
55 | // private int mTypeFace;
56 |
57 | /**
58 | * 文字宽度
59 | */
60 | private float mStrokeWidth;
61 |
62 | /**
63 | * 是否显示干扰线条,默认true
64 | */
65 | private boolean isShowInterferenceLines = true;
66 |
67 | /**
68 | * 干扰线条的数量,默认10条
69 | */
70 | private int mInterferenceLinesCount = 10;
71 |
72 | /**
73 | * 干扰线条的颜色,默认为黑色
74 | */
75 | private int mInterferenceLinesColor = Color.BLACK;
76 |
77 | /**
78 | * 干扰线条的宽度,默认3
79 | */
80 | private float mInterferenceLinesWidth = 3f;
81 |
82 | /**
83 | * 是否显示干扰圆点,默认为true
84 | */
85 | private boolean isShowInterferenceCircles = true;
86 |
87 | /**
88 | * 干扰圆点的数量,默认100个
89 | */
90 | private int mInterferenceCirclesCount = 100;
91 |
92 | /**
93 | * 干扰圆点的颜色,默认黑色
94 | */
95 | private int mInterferenceCirclesColor = Color.BLACK;
96 |
97 | /**
98 | * 干扰圆点的半径,默认为5
99 | */
100 | private float mInterferenceCirclesRadius = 5f;
101 |
102 | /**
103 | * 验证码的背景色
104 | */
105 | private int mVerificationCodeBackground = Color.GRAY;
106 |
107 | /**
108 | * 干扰圆点的颜色是否随机,如果手动设置了了mInterferenceCircleColor的值,该值为false
109 | */
110 | private boolean isCircleColorRandom = true;
111 |
112 | /**
113 | * 干扰线的颜色是否随机,如果手动设置了了mInterferenceLinesColor的值,该值为false
114 | */
115 | private boolean isLineColorRandom = true;
116 |
117 | /**
118 | * 画笔
119 | */
120 | private Paint mPaint = new Paint();
121 |
122 | /**
123 | * 随机函数
124 | */
125 | private Random mRandom = new Random();
126 |
127 | /**
128 | * 文本的绘制区域
129 | */
130 | private Rect mTextRect = new Rect();
131 |
132 | /**
133 | * 是否在刷新的时候调用requestLayout()方法重新计算控件宽高,
134 | * 如果首次未设置mVerificationText的值,然后再次设置mVerificationText的值的时候刷新则需要重新计算控件宽高
135 | */
136 | private boolean isNeedRequesLayout = false;
137 |
138 | /**
139 | * 是否显示干扰线条
140 | *
141 | * @return 是否显示干扰线条的boolean值
142 | */
143 | public boolean isShowInterferenceLines() {
144 | return isShowInterferenceLines;
145 | }
146 |
147 | /**
148 | * 设置是否显示干扰线条
149 | *
150 | * @param showInterferenceLines 是否显示干扰线条的boolean值
151 | */
152 | public void setShowInterferenceLines(boolean showInterferenceLines) {
153 | isShowInterferenceLines = showInterferenceLines;
154 | }
155 |
156 | /**
157 | * 是否显示干扰圆点
158 | *
159 | * @return 是否显示干扰圆点的boolean值
160 | */
161 | public boolean isShowInterferenceCircles() {
162 | return isShowInterferenceCircles;
163 | }
164 |
165 | /**
166 | * 设置是否显示干扰圆点
167 | *
168 | * @param showInterferenceCircles 是否显示干扰圆点的boolean值
169 | */
170 | public void setShowInterferenceCircles(boolean showInterferenceCircles) {
171 | isShowInterferenceCircles = showInterferenceCircles;
172 | }
173 |
174 | /**
175 | * 文本是否为粗体
176 | *
177 | * @return 文本是否为粗体的boolean值
178 | */
179 | public boolean isTextBold() {
180 | return isTextBold;
181 | }
182 |
183 | /**
184 | * 设置文本是否为粗体
185 | *
186 | * @param textBold 文本是否为粗体的boolean值
187 | */
188 | public void setTextBold(boolean textBold) {
189 | isTextBold = textBold;
190 | }
191 |
192 | /**
193 | * 获取干扰圆点的颜色是否随机
194 | *
195 | * @return 干扰圆点的颜色是否随机的boolean值
196 | */
197 | public boolean isCircleColorRandom() {
198 | return isCircleColorRandom;
199 | }
200 |
201 | /**
202 | * 设置干扰圆点的颜色是否随机
203 | *
204 | * @param circleColorRandom 干扰圆点的颜色是否随机的boolean值
205 | */
206 | public void setCircleColorRandom(boolean circleColorRandom) {
207 | isCircleColorRandom = circleColorRandom;
208 | }
209 |
210 | /**
211 | * 获取线条颜色是否随机
212 | *
213 | * @return 线条颜色是否随机的boolean
214 | */
215 | public boolean isLineColorRandom() {
216 | return isLineColorRandom;
217 | }
218 |
219 | /**
220 | * 设置线条颜色是否随机
221 | *
222 | * @param lineColorRandom 线条颜色是否随机的boolean
223 | */
224 | public void setLineColorRandom(boolean lineColorRandom) {
225 | isLineColorRandom = lineColorRandom;
226 | }
227 |
228 | /**
229 | * 获取验证码文本
230 | *
231 | * @return 验证码文本的String值
232 | */
233 | public String getVerificationText() {
234 | return mVerificationText;
235 | }
236 |
237 | /**
238 | * 设置验证码文本
239 | *
240 | * @param verificationText 验证码文本的String值
241 | */
242 | public void setVerificationText(String verificationText) {
243 | if (getVerificationText() == null || "".equals(getVerificationText())) {
244 | isNeedRequesLayout = true;
245 | }
246 |
247 | mVerificationText = verificationText;
248 |
249 | // 刷新控件
250 | if (isNeedRequesLayout) {
251 | this.requestLayout();
252 | isNeedRequesLayout = false;
253 | }
254 | postInvalidate();
255 | }
256 |
257 | /**
258 | * 获取控件的背景色
259 | *
260 | * @return int类型的color值
261 | */
262 | public int getVerificationCodeBackground() {
263 | return mVerificationCodeBackground;
264 | }
265 |
266 | /**
267 | * 设置控件的背景色
268 | *
269 | * @param verificationCodeBackground int类型的color值
270 | */
271 | public void setVerificationCodeBackground(int verificationCodeBackground) {
272 | mVerificationCodeBackground = verificationCodeBackground;
273 | }
274 |
275 | /**
276 | * 获取干扰线条的数量
277 | *
278 | * @return 线条数量
279 | */
280 | public int getInterferenceLinesCount() {
281 | return mInterferenceLinesCount;
282 | }
283 |
284 | /**
285 | * 设置干扰线条的数量
286 | *
287 | * @param interferenceLinesCount 线条数量
288 | */
289 | public void setInterferenceLinesCount(int interferenceLinesCount) {
290 | mInterferenceLinesCount = interferenceLinesCount;
291 | }
292 |
293 | /**
294 | * 设置干扰线条的颜色
295 | *
296 | * @param interferenceLinesColor 干扰线条的颜色int值
297 | */
298 | public void setInterferenceLinesColor(int interferenceLinesColor) {
299 | // 关闭颜色随机
300 | isLineColorRandom = false;
301 | mInterferenceLinesColor = interferenceLinesColor;
302 | }
303 |
304 | /**
305 | * 获取干扰线条的宽度
306 | *
307 | * @return 线条的宽度值
308 | */
309 | public float getInterferenceLinesWidth() {
310 | return mInterferenceLinesWidth;
311 | }
312 |
313 | /**
314 | * 设置干扰线条的宽度
315 | *
316 | * @param interferenceLinesWidth 线条的宽度值
317 | */
318 | public void setInterferenceLinesWidth(float interferenceLinesWidth) {
319 | mInterferenceLinesWidth = interferenceLinesWidth;
320 | }
321 |
322 | /**
323 | * 获取干扰圆点的数量
324 | *
325 | * @return 干扰圆点的数量
326 | */
327 | public int getInterferenceCirclesCount() {
328 | return mInterferenceCirclesCount;
329 | }
330 |
331 | /**
332 | * 设置干扰圆点的数量
333 | *
334 | * @param interferenceCirclesCount 干扰圆雕的数量
335 | */
336 | public void setInterferenceCirclesCount(int interferenceCirclesCount) {
337 | mInterferenceCirclesCount = interferenceCirclesCount;
338 | }
339 |
340 | /**
341 | * 设置干扰圆点的颜色
342 | *
343 | * @param interferenceCirclesColor 干扰圆点的颜色
344 | */
345 | public void setInterferenceCirclesColor(int interferenceCirclesColor) {
346 | // 关闭颜色随机
347 | isCircleColorRandom = false;
348 | mInterferenceCirclesColor = interferenceCirclesColor;
349 | }
350 |
351 | /**
352 | * 获取干扰圆点的半径
353 | *
354 | * @return 干扰圆点的半径
355 | */
356 | public float getInterferenceCirclesRadius() {
357 | return mInterferenceCirclesRadius;
358 | }
359 |
360 | /**
361 | * 设置干扰圆点的半径
362 | *
363 | * @param interferenceCirclesRadius 干扰圆点的半径
364 | */
365 | public void setInterferenceCirclesRadius(float interferenceCirclesRadius) {
366 | mInterferenceCirclesRadius = interferenceCirclesRadius;
367 | }
368 |
369 | /**
370 | * 获取验证码文本颜色
371 | *
372 | * @return 验证码文本颜色
373 | */
374 | public int getTextColor() {
375 | return mTextColor;
376 | }
377 |
378 | /**
379 | * 设置验证码文本颜色
380 | *
381 | * @param textColor 验证码文本颜色
382 | */
383 | public void setTextColor(int textColor) {
384 | mTextColor = textColor;
385 | }
386 |
387 | /**
388 | * 获取验证码文本大小
389 | *
390 | * @return 验证码文本大小
391 | */
392 | public int getTextSize() {
393 | return mTextSize;
394 | }
395 |
396 | /**
397 | * 设置验证码文本大小
398 | *
399 | * @param textSize 验证码文本大小
400 | */
401 | public void setTextSize(int textSize) {
402 | mTextSize = textSize;
403 | }
404 |
405 | /**
406 | * 验证码文本是否有下划线
407 | *
408 | * @return 返回是否有下划线的boolean值
409 | */
410 | public boolean isUnderLine() {
411 | return isUnderLine;
412 | }
413 |
414 | /**
415 | * 设置验证码是否有下划线
416 | *
417 | * @param underLine 是否有下划线
418 | */
419 | public void setUnderLine(boolean underLine) {
420 | isUnderLine = underLine;
421 | }
422 |
423 | /**
424 | * 获取文本的倾斜值
425 | *
426 | * @return 返回一个float类型的倾斜值
427 | */
428 | public float getTextSkewX() {
429 | return mTextSkewX;
430 | }
431 |
432 | /**
433 | * 设置文本的倾斜值
434 | *
435 | * @param textSkewX 文本的倾斜值
436 | */
437 | public void setTextSkewX(float textSkewX) {
438 | mTextSkewX = textSkewX;
439 | }
440 |
441 | /**
442 | * 获取文本的宽度值
443 | *
444 | * @return 返回一个float类型的宽度值
445 | */
446 | public float getStrokeWidth() {
447 | return mStrokeWidth;
448 | }
449 |
450 | /**
451 | * 设置文本的宽度
452 | *
453 | * @param strokeWidth 文本的宽度值
454 | */
455 | public void setStrokeWidth(float strokeWidth) {
456 | mStrokeWidth = strokeWidth;
457 | }
458 |
459 | public VerificationCodeView(Context context) {
460 | this(context, null);
461 | }
462 |
463 | public VerificationCodeView(Context context, AttributeSet attrs) {
464 | super(context, attrs);
465 |
466 | TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VerificationCodeView, 0, 0);
467 | for (int i = 0; i < array.getIndexCount(); i++) {
468 | int attr = array.getIndex(i);
469 |
470 | if (attr == R.styleable.VerificationCodeView_verificationText) {
471 | // 验证码文本
472 | mVerificationText = array.getString(attr);
473 |
474 | } else if (attr == R.styleable.VerificationCodeView_isUnderLine) {
475 | // 验证码文字是否具有下划线
476 | isUnderLine = array.getBoolean(attr, false);
477 |
478 | } else if (attr == R.styleable.VerificationCodeView_isTextBold) {
479 | // 文本是否加黑
480 | isTextBold = array.getBoolean(attr, false);
481 |
482 | } else if (attr == R.styleable.VerificationCodeView_strokeWidth) {
483 | // 验证码字体的宽度
484 | mStrokeWidth = array.getFloat(attr, 0);
485 |
486 | } else if (attr == R.styleable.VerificationCodeView_textColor) {
487 | // 验证码文本的颜色,默认为黑色
488 | mTextColor = array.getColor(attr, Color.BLACK);
489 |
490 | } else if (attr == R.styleable.VerificationCodeView_textSize) {
491 | // 验证码文本的大小
492 | mTextSize = array.getDimensionPixelSize(attr, 16);
493 |
494 | } else if (attr == R.styleable.VerificationCodeView_textSkewX) {
495 | // 验证码文本的倾斜度
496 | mTextSkewX = array.getFloat(attr, 0);
497 |
498 | } else if (attr == R.styleable.VerificationCodeView_isShowInterferenceCircles) {
499 | // 是否显示干扰圆点
500 | isShowInterferenceCircles = array.getBoolean(attr, true);
501 |
502 | } else if (attr == R.styleable.VerificationCodeView_interferenceCirclesColor) {
503 | isCircleColorRandom = false;
504 | // 干扰圆点的颜色
505 | mInterferenceCirclesColor = array.getColor(attr, Color.BLACK);
506 |
507 | } else if (attr == R.styleable.VerificationCodeView_interferenceCirclesRadius) {
508 | // 干扰圆点的半径
509 | mInterferenceCirclesRadius = array.getFloat(attr, 5f);
510 |
511 | } else if (attr == R.styleable.VerificationCodeView_interferenceCirclesCount) {
512 | // 干扰圆点的数量
513 | mInterferenceCirclesCount = array.getInt(attr, 100);
514 |
515 | } else if (attr == R.styleable.VerificationCodeView_isShowInterferenceLines) {
516 | // 是否显示干扰线条
517 | isShowInterferenceLines = array.getBoolean(attr, true);
518 |
519 | } else if (attr == R.styleable.VerificationCodeView_interferenceLinesColor) {
520 | isLineColorRandom = false;
521 | // 干扰线条的颜色
522 | mInterferenceLinesColor = array.getColor(attr, Color.BLACK);
523 |
524 | } else if (attr == R.styleable.VerificationCodeView_interferenceLinesCount) {
525 | // 干扰线条的数量
526 | mInterferenceLinesCount = array.getInt(attr, 10);
527 |
528 | } else if (attr == R.styleable.VerificationCodeView_interferenceLinesWidth) {
529 | // 干扰线条的宽度
530 | mInterferenceLinesWidth = array.getFloat(attr, 3f);
531 |
532 | } else if (attr == R.styleable.VerificationCodeView_verificationCodeBackground) {
533 | // 验证码背景色
534 | mVerificationCodeBackground = array.getColor(attr, Color.GRAY);
535 |
536 | }
537 | }
538 |
539 | array.recycle();
540 | }
541 |
542 | @Override
543 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
544 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
545 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
546 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
547 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
548 | int width;
549 | int height;
550 |
551 | // 设置文本大小,此处设置是为了精确测量text的绘制区域
552 | mPaint.setTextSize(mTextSize);
553 |
554 | if (widthMode == MeasureSpec.EXACTLY) {
555 | width = widthSize;
556 | } else {
557 | if (mVerificationText != null) {
558 | // 如果设置了文本,则根据文本的大小确定绘制文本的宽度区域
559 | mPaint.getTextBounds(mVerificationText, 0, mVerificationText.length(), mTextRect);
560 | width = getPaddingLeft() + getPaddingRight() + mTextRect.width();
561 | } else {
562 | // 如果未设置验证码的文本,则默认一个宽
563 | width = 200;
564 | }
565 | }
566 |
567 | if (heightMode == MeasureSpec.EXACTLY) {
568 | height = heightSize;
569 | } else {
570 | if (mVerificationText != null) {
571 | mPaint.getTextBounds(mVerificationText, 0, mVerificationText.length(), mTextRect);
572 | height = getPaddingBottom() + getPaddingTop() + mTextRect.height();
573 | } else {
574 | // 如果未设置验证码的文本,则默认一个高度值
575 | height = 100;
576 | }
577 | }
578 |
579 | setMeasuredDimension(width, height);
580 | }
581 |
582 | @Override
583 | protected void onDraw(Canvas canvas) {
584 | super.onDraw(canvas);
585 | // 画背景色
586 | canvas.drawColor(mVerificationCodeBackground);
587 |
588 | /*
589 | 绘制文本
590 | */
591 | if (mVerificationText != null && mVerificationText.length() > 0) {
592 | mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
593 | // 设置文本是否加粗
594 | if (isTextBold) {
595 | mPaint.setTypeface(Typeface.DEFAULT_BOLD);
596 | }
597 | mPaint.setColor(mTextColor);
598 | // 设置文本的下划线
599 | mPaint.setUnderlineText(isUnderLine);
600 | // 设置文本倾斜度
601 | mPaint.setTextSkewX(mTextSkewX);
602 | canvas.drawText(mVerificationText, getWidth() / 2 - mTextRect.width() / 2 - mTextRect.left, getHeight() /
603 | 2 + mTextRect.height() / 2, mPaint);
604 | }
605 |
606 | /*
607 | 绘制干扰圆点
608 | */
609 | if (isShowInterferenceCircles) {
610 | mPaint.setStyle(Paint.Style.FILL);
611 | if (mInterferenceCirclesCount > 0) {
612 | // 根据控件的长宽,随机获得一个点的坐标进行绘制圆点
613 | for (int i = 0; i < mInterferenceCirclesCount; i++) {
614 | // 干扰圆点的颜色
615 | if (isCircleColorRandom) {
616 | // 颜色随机
617 | mPaint.setColor(Color.parseColor(getRandomColor()));
618 | } else {
619 | mPaint.setColor(mInterferenceCirclesColor);
620 | }
621 | float pointX = mRandom.nextFloat() * getWidth();
622 | float pointY = mRandom.nextFloat() * getHeight();
623 | canvas.drawCircle(pointX, pointY, mInterferenceCirclesRadius, mPaint);
624 | }
625 | } else {
626 | throw new IllegalArgumentException("干扰圆点的数量必须大于0!");
627 | }
628 | }
629 |
630 | /*
631 | 绘制干扰线条
632 | */
633 | if (isShowInterferenceLines) {
634 | mPaint.setStyle(Paint.Style.STROKE);
635 | // 干扰线条的宽度
636 | mPaint.setStrokeWidth(mInterferenceLinesWidth);
637 | if (mInterferenceLinesCount > 0) {
638 | // 画干扰线条
639 | for (int i = 0; i < mInterferenceLinesCount; i++) {
640 | // 干扰线条的颜色
641 | if (isLineColorRandom) {
642 | // 颜色随机
643 | mPaint.setColor(Color.parseColor(getRandomColor()));
644 | } else {
645 | mPaint.setColor(mInterferenceLinesColor);
646 | }
647 | float startX = mRandom.nextFloat() * getWidth();
648 | float startY = mRandom.nextFloat() * getHeight();
649 | float stopX = mRandom.nextFloat() * getWidth();
650 | float stopY = mRandom.nextFloat() * getHeight();
651 | canvas.drawLine(startX, startY, stopX, stopY, mPaint);
652 | }
653 | } else {
654 | throw new IllegalArgumentException("干扰线条的数量必须大于0!");
655 | }
656 | }
657 | }
658 |
659 | /**
660 | * 随机生成一个16进制的颜色值
661 | *
662 | * @return 生成的16进制的颜色值
663 | */
664 | private String getRandomColor() {
665 | String r, g, b;
666 |
667 | r = Integer.toHexString(mRandom.nextInt(256)).toUpperCase();
668 | g = Integer.toHexString(mRandom.nextInt(256)).toUpperCase();
669 | b = Integer.toHexString(mRandom.nextInt(256)).toUpperCase();
670 |
671 | r = r.length() == 1 ? "0" + r : r;
672 | g = g.length() == 1 ? "0" + g : g;
673 | b = b.length() == 1 ? "0" + b : b;
674 |
675 | return "#" + r + g + b;
676 | }
677 | }
678 |
--------------------------------------------------------------------------------