├── .gitignore ├── .jitpack.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── simple │ │ └── vclayout_demo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── simple │ │ │ └── vclayout_demo │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── sp_circle.xml │ │ └── sr_et_bg_accent.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── simple │ └── vclayout_demo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── simple │ │ └── vclayout │ │ ├── Utils.java │ │ ├── VerCodeEditText.java │ │ └── VerCodeLayout.java │ └── res │ ├── drawable │ ├── sp_cursor.xml │ ├── sp_focused_one.xml │ ├── sp_focused_two.xml │ ├── sp_normal_one.xml │ ├── sp_normal_two.xml │ └── sr_one.xml │ └── values │ ├── atts.xml │ ├── colors.xml │ └── strings.xml ├── settings.gradle └── statics └── vercode.gif /.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 | /.idea 11 | .DS_Store 12 | /build 13 | /captures 14 | .externalNativeBuild 15 | -------------------------------------------------------------------------------- /.jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk11 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ChenPeng 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VerCodeLayout 2 | 3 | [![](https://jitpack.io/v/simplepeng/VerCodeLayout.svg)](https://jitpack.io/#simplepeng/VerCodeLayout) 4 | 5 | 可能是支持属性最多类似校验验证码的输入控件。 6 | 7 | ![](statics/vercode.gif) 8 | 9 | ## 引入依赖 10 | 11 | ```groovy 12 | maven { url 'https://jitpack.io' } 13 | ``` 14 | 15 | ```groovy 16 | implementation 'com.github.simplepeng:VerCodeLayout:v1.0.2' 17 | ``` 18 | 19 | ## 基本使用 20 | 21 | 使用`VerCodeEditText`控件 22 | 23 | ```xml 24 | 33 | ``` 34 | 35 | ### 可用的属性 36 | 37 | | 属性名 | 作用 | 38 | | -------------------- | --------------------------------------------- | 39 | | vcCount | EditText的个数 | 40 | | vcMaxLength | EditText最大输入长度 | 41 | | vcNormalBackground | 未选中的背景 | 42 | | vcFocusedBackground | 选中的背景 | 43 | | vcWidth | EditText的宽 | 44 | | vcHeight | EditText的高 | 45 | | vcMinWidth | EditText的最小宽度 | 46 | | vcMinHeight | EditText的最小高度 | 47 | | vcMargin | EditText的外边距,当然还有MarginLeft等小属性 | 48 | | vcPadding | EditText的内边距,当然还有PaddingLeft等小属性 | 49 | | vcTextSize | EditText的文本大小 | 50 | | vcTextColor | EditText的文本颜色 | 51 | | vcTextCursorDrawable | EditText的游标Drawable | 52 | | vcGravity | EditText的Gravity | 53 | | vcInputType | EditText的输入类型 | 54 | 55 | ## 高级使用 56 | 57 | 使用`VerCodeLayout`控件,VerCodeEditText继承于VerCodeLayout。VerCodeLayout自带了当一个EditText输入完成选中下一个或删除完成选中上一个的功能,但是EditText必须设置`maxLength`。 58 | 59 | ```xml 60 | 61 | 64 | 65 | 73 | 74 | 82 | 83 | 91 | 92 | 100 | 101 | 109 | 110 | ``` 111 | 112 | ## 可用的方法 113 | 114 | | 方法名 | 方法作用 | 115 | | --------------------- | ------------------ | 116 | | setOnCompleteListener | 监听输入完成 | 117 | | clear | 清除所有的输入 | 118 | | getEditTexts | 获取所有的EditText | 119 | 120 | ## 混淆 121 | 122 | ```shell 123 | -keep class com.simple.vclayout.** {*;} 124 | ``` 125 | 126 | ## 版本更新 127 | 128 | * v1.0.2:增加`autoFocus`的支持 129 | 130 | * v1.0.1:迁移到`jitpack`,`AndroidX` 131 | 132 | * v1.0.0: 首次上传 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 30 8 | 9 | defaultConfig { 10 | applicationId "com.simple.vclayout_demo" 11 | minSdk 19 12 | targetSdk 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | viewBinding { 17 | enabled = true 18 | } 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | 33 | kotlinOptions { 34 | jvmTarget = '1.8' 35 | } 36 | } 37 | 38 | dependencies { 39 | implementation fileTree(include: ['*.jar'], dir: 'libs') 40 | implementation 'androidx.appcompat:appcompat:1.0.0' 41 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 44 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 45 | 46 | // 47 | // implementation project(':library') 48 | implementation 'com.github.simplepeng:VerCodeLayout:v1.0.2' 49 | } 50 | -------------------------------------------------------------------------------- /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 | 23 | -keep class com.simple.vclayout.** {*;} 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/simple/vclayout_demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.simple.vclayout_demo; 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("com.simple.vclayout", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/simple/vclayout_demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.simple.vclayout_demo; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.text.Editable; 6 | import android.view.View; 7 | import android.widget.Toast; 8 | 9 | import com.simple.vclayout.VerCodeEditText; 10 | import com.simple.vclayout.VerCodeLayout; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | 19 | VerCodeEditText vcEt1 = findViewById(R.id.vcEt1); 20 | vcEt1.setOnCompleteListener(new VerCodeLayout.OnCompleteListener() { 21 | @Override 22 | public void onComplete(Editable editable, String code) { 23 | showToast(code); 24 | } 25 | }); 26 | } 27 | 28 | public void clear(View view) { 29 | VerCodeEditText vcEt1 = findViewById(R.id.vcEt1); 30 | vcEt1.clear(); 31 | } 32 | 33 | private void showToast(CharSequence text) { 34 | Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sp_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sr_et_bg_accent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 21 | 22 | 31 | 32 |