├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ ├── cursor_color.xml
│ │ │ │ ├── bac_square.xml
│ │ │ │ ├── bac_square_selector.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── me
│ │ │ └── leefeng
│ │ │ └── verificationview
│ │ │ ├── MainActivity.kt
│ │ │ └── Main2Activity.java
│ ├── test
│ │ └── java
│ │ │ └── me
│ │ │ └── leefeng
│ │ │ └── verificationview
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── leefeng
│ │ └── verificationview
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── libverify
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styleable.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── me
│ │ │ └── leefeng
│ │ │ └── libverify
│ │ │ └── VerificationView.kt
│ ├── test
│ │ └── java
│ │ │ └── me
│ │ │ └── leefeng
│ │ │ └── libverify
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── leefeng
│ │ └── libverify
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── c99706f26b3a3b42367d8832a4dce716.GIF
├── .gitignore
├── gradle.properties
├── LICENSE
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/libverify/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':libverify'
2 |
--------------------------------------------------------------------------------
/libverify/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | libVerify
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Kotlin-VerificationView
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/c99706f26b3a3b42367d8832a4dce716.GIF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/c99706f26b3a3b42367d8832a4dce716.GIF
--------------------------------------------------------------------------------
/libverify/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Kotlin-VerificationView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cursor_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bac_square.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .idea
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 08 16:43:43 CST 2019
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.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bac_square_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/me/leefeng/verificationview/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package me.leefeng.verificationview
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/libverify/src/test/java/me/leefeng/libverify/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.libverify;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/me/leefeng/verificationview/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package me.leefeng.verificationview
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("me.leefeng.verificationview", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/libverify/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/libverify/src/androidTest/java/me/leefeng/libverify/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.libverify;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("me.leefeng.libverify.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # Kotlin code style for this project: "official" or "obsolete":
15 | kotlin.code.style=official
16 | android.useAndroidX=true
17 | android.enableJetifier=true
18 |
--------------------------------------------------------------------------------
/app/src/main/java/me/leefeng/verificationview/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package me.leefeng.verificationview
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import android.widget.Toast
6 | import kotlinx.android.synthetic.main.activity_main.*
7 |
8 | class MainActivity : AppCompatActivity() {
9 |
10 | override fun onCreate(savedInstanceState: Bundle?) {
11 | super.onCreate(savedInstanceState)
12 | setContentView(R.layout.activity_main)
13 | verificationView.finish = {
14 | Toast.makeText(this,"$it",Toast.LENGTH_SHORT).show()
15 | }
16 | verificationView2.listener = {s,b->
17 | println("$s,$b")
18 | // Toast.makeText(this,"$it",Toast.LENGTH_SHORT).show()
19 | }
20 | button.setOnClickListener {
21 | verificationView.clear()
22 | }
23 | button2.setOnClickListener {
24 | verificationView2.clear()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/me/leefeng/verificationview/Main2Activity.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.verificationview;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import android.widget.Toast;
7 | import kotlin.Unit;
8 | import kotlin.jvm.functions.Function1;
9 | import me.leefeng.libverify.VerificationView;
10 |
11 | /**
12 | * Created by lilifeng on 2019/4/9
13 | *
14 | * java demo
15 | *
16 | */
17 | public class Main2Activity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | VerificationView verificationView = findViewById(R.id.verificationView);
23 | verificationView.setFinish(new Function1() {
24 | @Override
25 | public Unit invoke(String s) {
26 | Toast.makeText(Main2Activity.this, s, Toast.LENGTH_SHORT).show();
27 | return null;
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Lifeng Li
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/libverify/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 28
7 |
8 |
9 |
10 | defaultConfig {
11 | minSdkVersion 18
12 | targetSdkVersion 28
13 | versionCode 2
14 | versionName "1.1"
15 |
16 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'androidx.appcompat:appcompat:1.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
36 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
37 | }
38 | repositories {
39 | mavenCentral()
40 | }
41 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "me.leefeng.verificationview"
11 | minSdkVersion 18
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | implementation 'androidx.appcompat:appcompat:1.0.0'
29 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
33 | implementation project(':libverify')
34 | }
35 |
--------------------------------------------------------------------------------
/libverify/src/main/res/values/styleable.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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kotlin-VerificationView
2 | VerificationView-手机验证码输入框 [](https://jitpack.io/#limxing/Kotlin-VerificationView)
3 |
4 |
5 |
6 |
7 | ## Usage
8 | #### Gradle
9 |
10 | Project level build.gradle
11 | ```
12 | buildscript {
13 | ext.kotlin_version = '1.3.21'
14 | }
15 | ...
16 | allprojects {
17 | repositories {
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 | ```
22 | App level build.gradle
23 | ```
24 | dependencies {
25 | implementation 'com.github.limxing:Kotlin-VerificationView:1.4'
26 | }
27 | ```
28 |
29 | ### XML
30 | ```
31 |
40 |
41 | ```
42 | vTextCount : 验证码位数
43 |
44 | vTextColor :字体颜色
45 |
46 | vTextSize :字体大小,注意:layout_height 属性须大于textSize的2倍,否则效果欠佳
47 |
48 | vBackgroundResource :每一个输入框的选中背景色
49 |
50 | vCursorDrawable :光标颜色,否则默认主题色
51 |
52 | vBackgroundColor: 背景色,与vBackgroundResource互斥
53 |
54 | vAutoShowInputBoard:是否自动弹出键盘,默认true
55 |
56 |
57 | ### Code
58 |
59 | kotlin
60 | ```kotlin
61 | verificationView.finish = {
62 | Toast.makeText(this,"$it",Toast.LENGTH_SHORT).show()
63 | }
64 | ```
65 | java
66 | ```java
67 | VerificationView verificationView = findViewById(R.id.verificationView);
68 | verificationView.setFinish(new Function1() {
69 | @Override
70 | public Unit invoke(String s) {
71 | Toast.makeText(Main2Activity.this, s, Toast.LENGTH_SHORT).show();
72 | return null;
73 | }
74 | });
75 | ```
76 | ### History
77 | 2021-12-13 Support Set EditText's ImeOptions Property .
78 |
79 |
80 | #### License
81 | Kotlin-VerificationView is available under the MIT license.
82 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
23 |
24 |
25 |
35 |
36 |
45 |
46 |
55 |
56 |
68 |
69 |
70 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/libverify/src/main/java/me/leefeng/libverify/VerificationView.kt:
--------------------------------------------------------------------------------
1 | package me.leefeng.libverify
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.graphics.Color
6 | import android.graphics.Paint
7 | import android.graphics.drawable.ColorDrawable
8 | import android.text.Editable
9 | import android.text.InputFilter
10 | import android.text.InputType
11 | import android.text.TextWatcher
12 | import android.util.AttributeSet
13 | import android.util.TypedValue
14 | import android.view.Gravity
15 | import android.view.KeyEvent
16 | import android.view.View
17 | import android.view.ViewGroup
18 | import android.view.inputmethod.EditorInfo
19 | import android.view.inputmethod.InputMethodManager
20 | import android.widget.EditText
21 | import android.widget.TextView
22 |
23 | /**
24 | *
25 | * Created by lilifeng on 2019/4/8
26 | *
27 | * 自定义View - 手机验证码输入框
28 | *
29 | */
30 | class VerificationView @JvmOverloads constructor(
31 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
32 | ) : ViewGroup(context, attrs, defStyleAttr), TextWatcher, View.OnKeyListener {
33 | override fun onKey(v: View?, keyCode: Int, event: KeyEvent?): Boolean {
34 | if (keyCode == KeyEvent.KEYCODE_DEL && event?.action == KeyEvent.ACTION_UP) {
35 | if (v?.tag == (etTextCount - 1)) {
36 | if (lastEtisEmpty) {
37 | backFocus()
38 | }
39 | lastEtisEmpty = true
40 | } else {
41 | backFocus()
42 | }
43 | }
44 | return false
45 | }
46 |
47 | override fun afterTextChanged(s: Editable?) {
48 | synchronized(this) {
49 | focus()
50 | }
51 |
52 | }
53 |
54 | private var imeOptions: Int
55 | private var lastEtisEmpty = true
56 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
57 | val lastETC = getChildAt(etTextCount - 1) as EditText
58 | lastEtisEmpty = lastETC.text.isEmpty()
59 | }
60 |
61 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
62 | }
63 |
64 |
65 | override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
66 | if (wtWidthPercent != 1f) etWidth = wtWidthPercent * sizeW / 4
67 | val w = if (etWidth != 0f) etWidth.toInt() else sizeH
68 | val middle = (sizeW - w * etTextCount) / (etTextCount - 1)
69 | for (i in 0 until etTextCount) {
70 | val et = getChildAt(i) as EditText
71 | val lp = getChildAt(0).layoutParams
72 | lp.width = w
73 | lp.height = sizeH
74 | getChildAt(i).layoutParams = lp
75 |
76 | val left = (middle + w) * i
77 | et.layout(left, 0, left + w, sizeH)
78 | }
79 | getChildAt(etTextCount).layout(0, 0, sizeW, sizeH)
80 |
81 | }
82 |
83 | private val density = resources.displayMetrics.density
84 | private var etTextSize = 18 * density
85 | private var etTextCount = 4
86 | private var etBackGround = 0
87 | private var etBackGroundColor = Color.BLACK
88 | private var etTextColor = Color.BLACK
89 | private var etCursorDrawable = 0
90 | private var etAutoShow = true
91 |
92 | private var etWidth: Float
93 |
94 | private var etLineColor: Int
95 |
96 | private var etLineHeight: Float
97 |
98 | private var wtWidthPercent: Float
99 |
100 | init {
101 | val array = context.obtainStyledAttributes(attrs, R.styleable.VerificationView)
102 | etTextSize = array.getDimension(R.styleable.VerificationView_vTextSize, 18 * density)
103 | etTextCount = array.getInteger(R.styleable.VerificationView_vTextCount, 4)
104 | etBackGround = array.getResourceId(R.styleable.VerificationView_vBackgroundResource, 0)
105 | etBackGroundColor =
106 | array.getColor(R.styleable.VerificationView_vBackgroundColor, Color.BLACK)
107 | etTextColor = array.getColor(R.styleable.VerificationView_vTextColor, Color.BLACK)
108 | etCursorDrawable = array.getResourceId(R.styleable.VerificationView_vCursorDrawable, 0)
109 | etAutoShow = array.getBoolean(R.styleable.VerificationView_vAutoShowInputBoard, true)
110 | etWidth = array.getDimension(R.styleable.VerificationView_vWidth, 0f)
111 | wtWidthPercent = array.getFloat(R.styleable.VerificationView_vWidthPercent, 1f)
112 | etLineColor = array.getColor(R.styleable.VerificationView_vLineColor, Color.BLACK)
113 | etLineHeight = array.getDimension(R.styleable.VerificationView_vLineHeight, 1f)
114 | imeOptions = array.getInt(R.styleable.VerificationView_vImeOptions, EditorInfo.IME_NULL)
115 | array.recycle()
116 |
117 | }
118 |
119 | private fun backFocus() {
120 | for (i in etTextCount - 1 downTo 0) {
121 | val editText = getChildAt(i) as EditText
122 | if (editText.text.length == 1) {
123 | editText.setText("")
124 | return
125 | }
126 | }
127 | }
128 |
129 | /**
130 | * 展示输入键盘
131 | */
132 | private fun showInputPad(editText: EditText) {
133 | editText.isFocusable = true
134 | editText.isFocusableInTouchMode = true
135 | editText.requestFocus()
136 | (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(
137 | editText,
138 | 0
139 | )
140 | }
141 |
142 | override fun onAttachedToWindow() {
143 | super.onAttachedToWindow()
144 | if (etAutoShow)
145 | postDelayed({
146 | focus()
147 | }, 200)
148 |
149 | }
150 |
151 | private val paint = Paint()
152 | override fun onDraw(canvas: Canvas?) {
153 | super.onDraw(canvas)
154 | if (etWidth == 0f) return
155 | paint.isAntiAlias = true
156 | paint.color = etLineColor
157 | paint.strokeWidth = etLineHeight
158 | val w = if (etWidth != 0f) etWidth.toInt() else sizeH
159 | val middle = (sizeW - w * etTextCount) / (etTextCount - 1)
160 | for (i in 0 until etTextCount) {
161 | val left = (middle + w) * i
162 | canvas?.drawLine(
163 | left.toFloat(),
164 | sizeH - etLineHeight,
165 | (left + w).toFloat(),
166 | sizeH - etLineHeight,
167 | paint
168 | )
169 | }
170 | }
171 |
172 |
173 | private fun focus() {
174 |
175 | val text = StringBuffer()
176 | for (i in 0 until etTextCount) {
177 | text.append((getChildAt(i) as EditText).text.toString())
178 | }
179 | listener?.invoke(text.toString(), text.length == etTextCount)
180 |
181 | for (i in 0 until etTextCount) {
182 | val editText = getChildAt(i) as EditText
183 | (getChildAt(i) as EditText).isEnabled = true
184 | if (editText.text.isEmpty()) {
185 | showInputPad(editText)
186 | editText.isCursorVisible = true
187 | return
188 | }
189 | }
190 | val et = getChildAt(etTextCount - 1) as EditText
191 | if (et.text.isNotEmpty()) {
192 | for (i in 0 until etTextCount) {
193 | (getChildAt(i) as EditText).isEnabled = false
194 | }
195 | (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(
196 | et.windowToken,
197 | 0
198 | )
199 | et.isCursorVisible = false
200 | et.clearFocus()
201 |
202 | }
203 | }
204 |
205 | /**
206 | * 最后一个完成回调
207 | */
208 | @Deprecated("replace by listener")
209 | var finish: ((String) -> Unit)? = null
210 |
211 | var listener: ((String, Boolean) -> Unit)? = null
212 |
213 | init {
214 | setWillNotDraw(false)
215 | for (i in 0 until etTextCount) {
216 | val et = EditText(context)
217 | et.gravity = Gravity.CENTER
218 | et.includeFontPadding = false
219 | if (etBackGroundColor != Color.BLACK)
220 | et.background = ColorDrawable(etBackGroundColor)
221 | et.includeFontPadding = false
222 | if (etBackGround != 0)
223 | et.setBackgroundResource(etBackGround)
224 | et.setEms(1)
225 | if (etCursorDrawable != 0)
226 | try {
227 | val f = TextView::class.java.getDeclaredField("mCursorDrawableRes")
228 | f.isAccessible = true
229 | f.set(et, etCursorDrawable)
230 | } catch (e: Throwable) {
231 | }
232 | et.inputType = InputType.TYPE_CLASS_NUMBER
233 | et.setTextColor(etTextColor)
234 | et.setTextSize(TypedValue.COMPLEX_UNIT_PX, etTextSize)
235 | et.addTextChangedListener(this)
236 | et.setOnKeyListener(this)
237 | et.tag = i
238 | et.filters = arrayOf(InputFilter.LengthFilter(1))
239 | if (imeOptions != EditorInfo.IME_NULL)
240 | et.imeOptions = imeOptions
241 | addView(et)
242 | }
243 | val view = View(context)
244 | view.setOnClickListener {
245 | requestEditeFocus()
246 | }
247 | addView(view)
248 |
249 | }
250 |
251 | private var sizeH = 0
252 | private var sizeW = 0
253 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
254 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
255 | sizeW = View.MeasureSpec.getSize(widthMeasureSpec)
256 | sizeH = View.MeasureSpec.getSize(heightMeasureSpec)
257 | measureChildren(widthMeasureSpec, heightMeasureSpec)
258 | }
259 |
260 | fun clear() {
261 | for (j in 0 until etTextCount) {
262 | val et = (getChildAt(j) as EditText)
263 | et.removeTextChangedListener(this)
264 | et.setText("")
265 | et.addTextChangedListener(this)
266 | }
267 | focus()
268 | }
269 |
270 | private fun requestEditeFocus() {
271 | val lastETC = getChildAt(etTextCount - 1) as EditText
272 | if (lastETC.text.isNotEmpty()) {
273 | lastETC.isEnabled = true
274 | showInputPad(lastETC)
275 | lastETC.isCursorVisible = true
276 | } else
277 | focus()
278 | }
279 | }
--------------------------------------------------------------------------------