├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── glomadrian │ │ └── codeinput │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── glomadrian │ │ └── codeinput │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── art ├── codeInput1.gif ├── codeInput1Small.gif ├── codeInput2.gif └── small.gif ├── build.gradle ├── codeinputlib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── glomadrian │ │ └── codearealib │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── glomadrian │ │ └── codeinputlib │ │ ├── CodeInput.java │ │ ├── CodeInputEditText.java │ │ ├── callback │ │ └── CodeInputCallback.java │ │ ├── data │ │ └── FixedStack.java │ │ └── model │ │ └── Underline.java │ └── res │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── integers.xml │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Android ### 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | 32 | ### Java ### 33 | *.class 34 | 35 | # Mobile Tools for Java (J2ME) 36 | .mtj.tmp/ 37 | 38 | # Package Files # 39 | *.jar 40 | *.war 41 | *.ear 42 | 43 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 44 | hs_err_pid* 45 | 46 | 47 | ### Gradle ### 48 | .gradle 49 | build/ 50 | 51 | # Ignore Gradle GUI config 52 | gradle-app.setting 53 | 54 | 55 | ### Intellij ### 56 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 57 | 58 | *.iml 59 | 60 | ## Directory-based project format: 61 | .idea/ 62 | # if you remove the above rule, at least ignore the following: 63 | 64 | # User-specific stuff: 65 | # .idea/workspace.xml 66 | # .idea/tasks.xml 67 | # .idea/dictionaries 68 | 69 | # Sensitive or high-churn files: 70 | # .idea/dataSources.ids 71 | # .idea/dataSources.xml 72 | # .idea/sqlDataSources.xml 73 | # .idea/dynamic.xml 74 | # .idea/uiDesigner.xml 75 | 76 | # Gradle: 77 | # .idea/gradle.xml 78 | # .idea/libraries 79 | 80 | # Mongo Explorer plugin: 81 | # .idea/mongoSettings.xml 82 | 83 | ## File-based project format: 84 | *.ipr 85 | *.iws 86 | 87 | ## Plugin-specific files: 88 | 89 | # IntelliJ 90 | out/ 91 | 92 | # mpeltonen/sbt-idea plugin 93 | .idea_modules/ 94 | 95 | # JIRA plugin 96 | atlassian-ide-plugin.xml 97 | 98 | # Crashlytics plugin (for Android Studio and IntelliJ) 99 | com_crashlytics_export_strings.xml 100 | crashlytics.properties 101 | crashlytics-build.properties 102 | 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | * updated by bajian 2 | * 增加string 类型返回 3 | * 优化个别代码性能,如attributes.recycle();等 4 | * 增加CodeInputCallback 监听onInputFinish和onInput 5 | * 增加CodeInputEditText extends EditText 特性更多。比如可以很方便的时候et的特性,如maxLength,预输入.. 6 | * 增加使用例子 7 | 8 | Material Code input 9 | ----------------- 10 | 11 | A material style input for put codes 12 | 13 | ![Demo Screenshot][1] 14 | 15 | ![Demo Screenshot][2] 16 | 17 | 18 | Based on 19 | ---------- 20 | 21 | [Code input field concept](http://www.materialup.com/posts/code-input-field-concept) by [SAMUEL KANTALA](http://www.materialup.com/ontidop) 22 | 23 | 24 | How to use 25 | ---------- 26 | 27 | Minimal SDK Version 11 28 | 29 | Usage with default colors (the default codes is 6) 30 | 31 | ```xml 32 | 37 | ``` 38 | 39 | Usage with custom colors and attributes 40 | 41 | ```xml 42 | 53 | ``` 54 | 55 | ``` 56 | 57 | 70 | ``` 71 | 72 | 73 | Remember put this for custom attribute usage 74 | 75 | ```java 76 | 77 | xmlns:app="http://schemas.android.com/apk/res-auto" 78 | 79 | ``` 80 | 81 | Get the input code (Returns a Character[]) 82 | 83 | ```java 84 | codeInput.getCode() 85 | 86 | codeInput.getString() 87 | ``` 88 | 89 | Developed By 90 | ------------ 91 | bajian - <313066164@qq.com> 92 | Adrián García Lomas - 93 | 94 | License 95 | ------- 96 | 97 | Copyright 2015 bajian 98 | 99 | Licensed under the Apache License, Version 2.0 (the "License"); 100 | you may not use this file except in compliance with the License. 101 | You may obtain a copy of the License at 102 | 103 | http://www.apache.org/licenses/LICENSE-2.0 104 | 105 | Unless required by applicable law or agreed to in writing, software 106 | distributed under the License is distributed on an "AS IS" BASIS, 107 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 108 | See the License for the specific language governing permissions and 109 | limitations under the License. 110 | 111 | [1]: ./art/codeInput1.gif 112 | [2]: ./art/codeInput2.gif 113 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.github.glomadrian.codeinput" 9 | minSdkVersion 14 10 | targetSdkVersion 22 11 | versionCode 11 12 | versionName "1.1" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:22.2.0' 25 | compile project(":codeinputlib") 26 | } 27 | -------------------------------------------------------------------------------- /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 /media/Almacen/SDK/Android/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/androidTest/java/com/github/glomadrian/codeinput/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.glomadrian.codeinput; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/glomadrian/codeinput/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.glomadrian.codeinput; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.github.glomadrian.codeinputlib.CodeInput; 9 | import com.github.glomadrian.codeinputlib.CodeInputEditText; 10 | import com.github.glomadrian.codeinputlib.callback.CodeInputCallback; 11 | 12 | /** 13 | * updated by bajian 14 | * 增加string 类型返回 15 | * 优化个别代码性能,如attributes.recycle();等 16 | * 增加CodeInputCallback 监听onInputFinish和onInput 17 | * 增加CodeInputEditText extends EditText 特性更多。比如可以很方便的时候et的特性,如maxLength,预输入.. 18 | * 增加焦点获得 hint自动上升,而不是点击才上升,否则有bug 19 | * 增加使用例子 20 | */ 21 | public class MainActivity extends AppCompatActivity implements CodeInputCallback{ 22 | 23 | private CodeInput ci; 24 | private CodeInputEditText mCit; 25 | 26 | @Override protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | ci=(CodeInput)findViewById(R.id.pairing); 30 | ci.setCodeInputListener(this); 31 | 32 | mCit = (CodeInputEditText) findViewById(R.id.cit); 33 | mCit.setCodeInputListener(new CodeInputCallback() { 34 | @Override 35 | public void onInputFinish(CodeInputEditText ci, String inputResult) { 36 | System.out.println("onInputFinish"+inputResult); 37 | 38 | } 39 | 40 | @Override 41 | public void onInput(CodeInputEditText ci, Character currentChar) { 42 | System.out.println("onInput"+currentChar); 43 | } 44 | }); 45 | } 46 | 47 | public void getCode(View v){ 48 | Toast.makeText(MainActivity.this,ci.getString(),Toast.LENGTH_LONG).show(); 49 | } 50 | 51 | 52 | public void getCodeInputEditText(View v){ 53 | Toast.makeText(MainActivity.this,mCit.getString(),Toast.LENGTH_LONG).show(); 54 | } 55 | 56 | @Override 57 | public void onInputFinish(CodeInput ci, String inputResult) { 58 | System.out.println("inputResult"+inputResult); 59 | } 60 | 61 | @Override 62 | public void onInput(CodeInput ci, Character currentChar) { 63 | System.out.println("currentChar"+currentChar); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 25 |