├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── TdPasswordView1.0.0b2.apk │ ├── TdPasswordView1.0.0b3.apk │ ├── TdPasswordViewSample1.0.0.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tieudieu │ │ └── passwordviewexample │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tieudieu │ │ │ └── passwordviewexample │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.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 │ └── tieudieu │ └── passwordviewexample │ └── ExampleUnitTest.kt ├── build.gradle ├── docs ├── Pic1.png ├── Pic2.png └── Pic3.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── passwordview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cis │ │ └── passwordview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tieudieu │ │ │ └── passwordview │ │ │ ├── PasswordInputSlotView.kt │ │ │ ├── PasswordInputView.kt │ │ │ └── PasswordView.kt │ └── res │ │ ├── layout │ │ ├── password_input_slot_view.xml │ │ └── password_view.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── dimens.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── cis │ └── passwordview │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TdPasswordView 2 | It's simple PasswordView, easy to use 3 | 4 | ## Usage 5 | 6 | ```bash 7 | compile 'com.tieudieu.passwordview:passwordview:0.0.1' 8 | ``` 9 | 10 | 11 | ```bash 12 | 13 | 21 | 22 | ``` 23 | 24 | ## Demo 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 27 7 | defaultConfig { 8 | applicationId "com.tieudieu.passwordviewexample" 9 | minSdkVersion 19 10 | targetSdkVersion 27 11 | versionCode 3 12 | versionName "1.0.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | 26 | //implementation project(':passwordview') 27 | 28 | implementation 'com.tieudieu.passwordview:passwordview:0.0.1' 29 | 30 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'com.android.support:appcompat-v7:27.1.1' 32 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 36 | } 37 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/release/TdPasswordView1.0.0b2.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/release/TdPasswordView1.0.0b2.apk -------------------------------------------------------------------------------- /app/release/TdPasswordView1.0.0b3.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/release/TdPasswordView1.0.0b3.apk -------------------------------------------------------------------------------- /app/release/TdPasswordViewSample1.0.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/release/TdPasswordViewSample1.0.0.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tieudieu/passwordviewexample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordviewexample 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.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("com.tieudieu.passwordview", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/tieudieu/passwordviewexample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordviewexample 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.util.Log 6 | import com.tieudieu.passwordview.PasswordView 7 | import kotlinx.android.synthetic.main.activity_main.* 8 | 9 | class MainActivity : AppCompatActivity() { 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_main) 14 | 15 | password_view.setOnPasswordEnterListener(object: PasswordView.OnPasswordEnterListener { 16 | override fun onPasswordEntered(password: String?) { 17 | 18 | Log.e("MainActivity", "xxx-onPassEntered-" + password) 19 | } 20 | 21 | }) 22 | 23 | password_view.setPassword("12345") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /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/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | tdpasswordview 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/tieudieu/passwordviewexample/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordviewexample 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 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.51' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.3' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" 13 | 14 | // Bintray & Maven Gradle Classpaths 15 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1' 16 | /*classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' 17 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'*/ 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | google() 24 | jcenter() 25 | maven { url "https://jitpack.io" } 26 | maven { 27 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 28 | } 29 | } 30 | } 31 | 32 | task clean(type: Delete) { 33 | delete rootProject.buildDir 34 | } 35 | 36 | // pass error JavaDoc when build library 37 | subprojects { 38 | tasks.withType(Javadoc).all { enabled = false } 39 | } 40 | -------------------------------------------------------------------------------- /docs/Pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/docs/Pic1.png -------------------------------------------------------------------------------- /docs/Pic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/docs/Pic2.png -------------------------------------------------------------------------------- /docs/Pic3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/docs/Pic3.png -------------------------------------------------------------------------------- /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 | 10 | org.gradle.jvmargs=-Xmx1536m 11 | 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | 16 | #org.gradle.daemon=true 17 | #org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 18 | #org.gradle.parallel=true 19 | #org.gradle.configureondemand=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tieudieutiger/TdPasswordView/23ba72aa2cb1f74ac85152379c1c490e0f0006fe/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 17 14:18:05 ICT 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /passwordview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /passwordview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | /*apply plugin: 'com.jfrog.bintray' 6 | apply plugin: 'com.github.dcendents.android-maven' 7 | 8 | ext { 9 | bintrayRepo = 'TdPasswordView' 10 | bintrayName = 'com.tieudieu.passwordview' 11 | 12 | libraryName = 'passwordview' 13 | 14 | publishedGroupId = 'com.tieudieu.passwordview' 15 | artifact = 'passwordview' 16 | libraryVersion = '0.0.1' 17 | 18 | libraryDescription = 'A lightweight library for number password view' 19 | 20 | siteUrl = 'https://github.com/tieudieutiger/TdPasswordView' 21 | gitUrl = 'https://github.com/tieudieutiger/TdPasswordView.git' 22 | 23 | developerId = 'tieudieutiger' 24 | developerName = 'Chieu Vu Van' 25 | developerEmail = 'vuvantrieu.k54.cb@gmail.com' 26 | 27 | licenseName = 'The Apache Software License, Version 2.0' 28 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 29 | allLicenses = ["Apache-2.0"] 30 | }*/ 31 | 32 | android { 33 | compileSdkVersion 27 34 | 35 | 36 | 37 | defaultConfig { 38 | minSdkVersion 19 39 | targetSdkVersion 27 40 | versionCode 1 41 | versionName "0.0.1" 42 | 43 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 44 | 45 | } 46 | 47 | buildTypes { 48 | release { 49 | minifyEnabled false 50 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 51 | } 52 | } 53 | 54 | } 55 | 56 | dependencies { 57 | implementation fileTree(dir: 'libs', include: ['*.jar']) 58 | 59 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 60 | implementation 'com.android.support:appcompat-v7:27.1.1' 61 | testImplementation 'junit:junit:4.12' 62 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 63 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 64 | //compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 65 | } 66 | repositories { 67 | mavenCentral() 68 | maven { 69 | url 'https://dl.bintray.com/tieudieutiger/maven/' 70 | } 71 | maven { 72 | url 'https://dl.bintray.com/tieudieutiger/TdPasswordView/' 73 | } 74 | maven { 75 | url "https://jitpack.io" 76 | } 77 | } 78 | 79 | 80 | //if (project.rootProject.file('local.properties').exists()) { 81 | // apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 82 | // apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' 83 | //} -------------------------------------------------------------------------------- /passwordview/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 | -------------------------------------------------------------------------------- /passwordview/src/androidTest/java/com/cis/passwordview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.cis.passwordview; 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 | * 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.cis.passwordview.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /passwordview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /passwordview/src/main/java/com/tieudieu/passwordview/PasswordInputSlotView.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordview 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.util.AttributeSet 6 | import android.util.Log 7 | import android.view.View 8 | import android.widget.LinearLayout 9 | import kotlinx.android.synthetic.main.password_input_slot_view.view.* 10 | 11 | class PasswordInputSlotView : LinearLayout { 12 | 13 | private var attrs: AttributeSet? = null 14 | private var styleAttr: Int = 0 15 | 16 | private var textColor: Int = 0 17 | private var hintColor: Int = 0 18 | 19 | constructor(context: Context?) : super(context) { 20 | init(context) 21 | } 22 | 23 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { 24 | 25 | this.attrs = attrs 26 | 27 | init(context) 28 | } 29 | 30 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { 31 | 32 | this.attrs = attrs 33 | this.styleAttr = defStyleAttr 34 | 35 | init(context) 36 | } 37 | 38 | private fun init(context: Context?) { 39 | 40 | if (context == null) return 41 | 42 | LinearLayout.inflate(context, R.layout.password_input_slot_view, this) 43 | 44 | var typedArray = context.obtainStyledAttributes( 45 | attrs, R.styleable.TdPasswordInput, styleAttr, 0 46 | ) 47 | 48 | textColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_text_color, Color.BLACK) 49 | hintColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_hint_color, Color.LTGRAY) 50 | 51 | typedArray.recycle() 52 | 53 | } 54 | 55 | /** 56 | * Private functions 57 | */ 58 | 59 | fun initView() { 60 | 61 | Log.d("PIS", "initView") 62 | 63 | tv_password_slot.setTextColor(hintColor) 64 | view_password_slot.setBackgroundColor(hintColor) 65 | view_password_slot.visibility = View.VISIBLE 66 | 67 | tv_password_slot.text = getPasswordSlotHint() 68 | 69 | } 70 | 71 | private fun getPasswordSlotLetter(): String = context.getString(R.string.pass_slot) 72 | 73 | private fun getPasswordSlotHint(): String = context.getString(R.string.pass_slot_hint) 74 | 75 | 76 | private fun setText(text: String?) { 77 | 78 | if (text != null) 79 | tv_password_slot.text = text 80 | } 81 | 82 | private fun setTextColor(color: Int) { 83 | 84 | tv_password_slot.setTextColor(color) 85 | } 86 | 87 | private fun onPass() { 88 | 89 | view_password_slot.setBackgroundColor(Color.TRANSPARENT) 90 | } 91 | 92 | /** 93 | * Public functions 94 | */ 95 | 96 | fun clear() = initView() 97 | 98 | fun setColor(textColor: Int, hintColor: Int) { 99 | 100 | Log.d("PIS", "xxx-setColor") 101 | 102 | this.textColor = textColor 103 | this.hintColor = hintColor 104 | } 105 | 106 | fun setLineVisibility(visibility: Int) { 107 | 108 | view_password_slot.visibility = visibility 109 | } 110 | 111 | fun onViewFocus(isFocus: Boolean) { 112 | 113 | onViewFocus(isFocus, false) 114 | } 115 | 116 | fun onViewFocus(isFocus: Boolean, isPass: Boolean) { 117 | 118 | when { 119 | 120 | isFocus -> { 121 | 122 | view_password_slot.visibility = View.VISIBLE 123 | view_password_slot.setBackgroundColor(textColor) 124 | 125 | } 126 | 127 | isPass -> onPass() 128 | 129 | else -> view_password_slot.setBackgroundColor(hintColor) 130 | } 131 | 132 | } 133 | 134 | fun onInput() { 135 | 136 | setTextColor(hintColor) 137 | setText(getPasswordSlotHint()) 138 | } 139 | 140 | /*fun onEntered() { 141 | 142 | onEntered(getPasswordSlotLetter()) 143 | }*/ 144 | 145 | fun onEntered(letter: String) { 146 | 147 | setTextColor(textColor) 148 | setText(letter) 149 | 150 | onPass() 151 | } 152 | 153 | } -------------------------------------------------------------------------------- /passwordview/src/main/java/com/tieudieu/passwordview/PasswordInputView.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordview 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.util.AttributeSet 6 | import android.util.Log 7 | import android.view.View 8 | import android.widget.LinearLayout 9 | import java.util.* 10 | 11 | class PasswordInputView : LinearLayout { 12 | 13 | private var attrs: AttributeSet? = null 14 | private var styleAttr: Int = 0 15 | 16 | private var textColor: Int = 0 17 | private var hintColor: Int = 0 18 | 19 | private var passwordLength = 0 20 | private lateinit var passwordType: PasswordView.PasswordType 21 | 22 | private var passwordSlotViews = ArrayList() 23 | 24 | constructor(context: Context?) : super(context) { 25 | init(context) 26 | } 27 | 28 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { 29 | 30 | this.attrs = attrs 31 | 32 | init(context) 33 | } 34 | 35 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { 36 | 37 | this.attrs = attrs 38 | this.styleAttr = defStyleAttr 39 | 40 | init(context) 41 | } 42 | 43 | private fun init(context: Context?) { 44 | 45 | orientation = LinearLayout.HORIZONTAL 46 | 47 | if (context == null) return 48 | 49 | var typedArray = context.obtainStyledAttributes( 50 | attrs, R.styleable.TdPasswordInput, styleAttr, 0 51 | ) 52 | 53 | textColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_text_color, Color.BLACK) 54 | hintColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_hint_color, Color.LTGRAY) 55 | 56 | typedArray.recycle() 57 | 58 | } 59 | 60 | /** 61 | * Private functions 62 | */ 63 | 64 | fun initView() { 65 | 66 | removeAllViews() 67 | 68 | passwordSlotViews.clear() 69 | 70 | if (passwordLength <= 0) return 71 | 72 | for (i in 0 until passwordLength) { 73 | addSlot() 74 | } 75 | 76 | } 77 | 78 | private fun addSlot() { 79 | 80 | var slotView = PasswordInputSlotView(context) 81 | slotView.setColor(textColor, hintColor) 82 | slotView.initView() 83 | 84 | passwordSlotViews.add(slotView) 85 | 86 | addView(slotView) 87 | } 88 | 89 | private fun parsePassSlotLetter(letter: Char): String { 90 | 91 | return if (passwordType == PasswordView.PasswordType.PASSWORD) 92 | context.getString(R.string.pass_slot) 93 | else 94 | letter.toString() 95 | } 96 | 97 | /** 98 | * Public functions 99 | */ 100 | 101 | fun clear() { 102 | 103 | initView() 104 | } 105 | 106 | fun setPasswordLength(length: Int) { 107 | 108 | passwordLength = length 109 | } 110 | 111 | fun setPasswordType(type: PasswordView.PasswordType) { 112 | 113 | passwordType = type 114 | } 115 | 116 | fun setPassword(password: String): Boolean { 117 | 118 | if (passwordLength <= 0 || password.isEmpty() || passwordSlotViews.isEmpty() || passwordSlotViews.size != password.length) 119 | return false 120 | 121 | clear() 122 | 123 | for (index in 0..(passwordSlotViews.size - 1)) { 124 | onEntered(index, password[index]) 125 | } 126 | 127 | return true 128 | 129 | } 130 | 131 | fun onViewFocus(hasFocus: Boolean, valueLength: Int) { 132 | 133 | if (passwordSlotViews == null || valueLength < 0 || valueLength > passwordSlotViews.size) 134 | return 135 | 136 | for (p: PasswordInputSlotView in passwordSlotViews) { 137 | p.setLineVisibility(View.VISIBLE) 138 | } 139 | 140 | if (hasFocus) { 141 | 142 | // entered on [valueLength - 1] 143 | if (valueLength > 0) 144 | passwordSlotViews[valueLength - 1].onViewFocus(false, true) 145 | 146 | // focus on [valueLength] 147 | if (valueLength < passwordSlotViews.size) 148 | passwordSlotViews[valueLength].onViewFocus(true) 149 | 150 | // lost focus on [valueLength + 1] 151 | if (valueLength + 1 < passwordSlotViews.size) 152 | passwordSlotViews[valueLength + 1].onViewFocus(false, false) 153 | 154 | } else if (valueLength > 0) 155 | passwordSlotViews[valueLength - 1].onViewFocus(false) 156 | // } else 157 | // for (p: PasswordInputSlotView in passwordSlotViews) { 158 | // p.onViewFocus(false, true) 159 | // } 160 | 161 | } 162 | 163 | fun onInput(index: Int) { 164 | 165 | if (passwordSlotViews == null || index < 0 || index >= passwordSlotViews.size) 166 | return 167 | 168 | passwordSlotViews[index].onInput() 169 | } 170 | 171 | /*fun onEntered(index: Int) { 172 | 173 | if (passwordSlotViews == null || index < 0 || index >= passwordSlotViews.size) 174 | return 175 | 176 | passwordSlotViews[index].onEntered() 177 | 178 | }*/ 179 | 180 | fun onEntered(index: Int, letter: Char) { 181 | 182 | if (passwordSlotViews == null || index < 0 || index >= passwordSlotViews.size) 183 | return 184 | 185 | passwordSlotViews[index].onEntered(parsePassSlotLetter(letter)) 186 | 187 | } 188 | 189 | } -------------------------------------------------------------------------------- /passwordview/src/main/java/com/tieudieu/passwordview/PasswordView.kt: -------------------------------------------------------------------------------- 1 | package com.tieudieu.passwordview 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.graphics.Rect 6 | import android.text.Editable 7 | import android.text.TextWatcher 8 | import android.util.AttributeSet 9 | import android.util.Log 10 | import android.view.View 11 | import android.view.animation.CycleInterpolator 12 | import android.view.inputmethod.InputMethodManager 13 | import android.widget.RelativeLayout 14 | import kotlinx.android.synthetic.main.password_input_slot_view.view.* 15 | 16 | import kotlinx.android.synthetic.main.password_view.view.* 17 | 18 | 19 | class PasswordView : RelativeLayout { 20 | 21 | companion object { 22 | 23 | private const val PASSWORD_LENGTH_DEFAULT = 6 24 | } 25 | 26 | private var attrs: AttributeSet? = null 27 | private var styleAttr: Int = 0 28 | 29 | private var textColor: Int = 0 30 | private var hintColor: Int = 0 31 | private var passwordLength = PASSWORD_LENGTH_DEFAULT 32 | private lateinit var inputType: InputType 33 | private lateinit var passwordType: PasswordType 34 | 35 | private var password: String = "" 36 | private var keyboardVisible = false 37 | private var shakeAnimationDoing = false 38 | private var onPasswordEnterListener: OnPasswordEnterListener? = null 39 | 40 | 41 | constructor(context: Context?) : super(context) { 42 | init(context) 43 | } 44 | 45 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { 46 | 47 | this.attrs = attrs 48 | 49 | init(context) 50 | } 51 | 52 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { 53 | 54 | this.attrs = attrs 55 | this.styleAttr = defStyleAttr 56 | 57 | init(context) 58 | } 59 | 60 | private fun init(context: Context?) { 61 | 62 | if (context == null) return 63 | 64 | inflate(context, R.layout.password_view, this) 65 | 66 | var typedArray = context.obtainStyledAttributes( 67 | attrs, R.styleable.TdPasswordInput, styleAttr, 0 68 | ) 69 | 70 | textColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_text_color, Color.BLACK) 71 | hintColor = typedArray.getColor(R.styleable.TdPasswordInput_tdpi_hint_color, Color.LTGRAY) 72 | passwordLength = typedArray.getInt(R.styleable.TdPasswordInput_tdpi_password_length, PASSWORD_LENGTH_DEFAULT) 73 | 74 | var inputTypeValue = typedArray.getInteger(R.styleable.TdPasswordInput_tdpi_input_type, InputType.NUMBER.attrValue) 75 | inputType = InputType.fromValue(inputTypeValue) 76 | 77 | var passwordTypeValue = typedArray.getInteger(R.styleable.TdPasswordInput_tdpi_password_type, PasswordType.PASSWORD.attrValue) 78 | passwordType = PasswordType.fromValue(passwordTypeValue) 79 | 80 | typedArray.recycle() 81 | 82 | } 83 | 84 | override fun onFinishInflate() { 85 | super.onFinishInflate() 86 | 87 | initView() 88 | } 89 | 90 | override fun onAttachedToWindow() { 91 | super.onAttachedToWindow() 92 | 93 | if (!isInEditMode) { 94 | 95 | addKeyboardVisibilityListener( 96 | this, 97 | object : OnKeyboardVisibilityListener { 98 | 99 | override fun onVisibilityChange(isVisible: Boolean) { 100 | if (keyboardVisible != isVisible) { 101 | keyboardVisible = isVisible 102 | if (!keyboardVisible && edt_input_password_real.isFocused) { 103 | edt_input_password_real.clearFocus() 104 | } 105 | } 106 | } 107 | } 108 | ) 109 | 110 | edt_input_password_real.onFocusChangeListener = OnFocusChangeListener { _, hasFocus -> 111 | showInput(password, hasFocus) 112 | } 113 | 114 | edt_input_password_real.addTextChangedListener( 115 | 116 | object : TextWatcher { 117 | override fun afterTextChanged(s: Editable?) { 118 | } 119 | 120 | override fun beforeTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { 121 | } 122 | 123 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { 124 | 125 | if (s == null) return 126 | 127 | if (!shakeAnimationDoing) { 128 | 129 | if (before > 0) { 130 | 131 | // Remove last char 132 | if (password.isNotEmpty()) 133 | password = password.subSequence(0, password.length - 1).toString() 134 | 135 | } else if (password.length < passwordLength && s.isNotEmpty() && charIsValid(s[s.length - 1])) { 136 | 137 | val unicodeChar = s[s.length - 1] 138 | 139 | password += unicodeChar 140 | 141 | if (password.length == passwordLength && onPasswordEnterListener != null) 142 | onPasswordEnterListener!!.onPasswordEntered(getPassword()) 143 | 144 | } else 145 | shake() 146 | 147 | showInput(password, true) 148 | } 149 | } 150 | 151 | } 152 | ) 153 | 154 | } 155 | } 156 | 157 | /** 158 | * Private functions 159 | */ 160 | 161 | private fun initView() { 162 | 163 | password = "" 164 | 165 | layout_input_password.setPasswordType(passwordType) 166 | layout_input_password.setPasswordLength(passwordLength) 167 | layout_input_password.initView() 168 | 169 | btn_password_view_on_focus.setOnClickListener { 170 | 171 | // select endPosition 172 | edt_input_password_real.setSelection(edt_input_password_real.text.toString().length) 173 | 174 | // focus real edt 175 | edt_input_password_real.requestFocus() 176 | 177 | if (!keyboardVisible) 178 | showKeyboard(context) 179 | 180 | } 181 | } 182 | 183 | private fun showKeyboard(context: Context) { 184 | 185 | val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 186 | inputMethodManager?.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) 187 | } 188 | 189 | private fun addKeyboardVisibilityListener( 190 | rootLayout: View, onKeyboardVisibilityListener: OnKeyboardVisibilityListener) { 191 | 192 | rootLayout.viewTreeObserver.addOnGlobalLayoutListener { 193 | val r = Rect() 194 | rootLayout.getWindowVisibleDisplayFrame(r) 195 | val screenHeight = rootLayout.rootView.height 196 | 197 | // r.bottom is the position above soft keypad or device button. 198 | // if keypad is shown, the r.bottom is smaller than that before. 199 | val keypadHeight = screenHeight - r.bottom 200 | 201 | val isVisible = keypadHeight > screenHeight * 0.15 // 0.15 ratio is perhaps enough to determine keypad height. 202 | onKeyboardVisibilityListener.onVisibilityChange(isVisible) 203 | } 204 | } 205 | 206 | private fun showInput(value: String, hasFocus: Boolean) { 207 | 208 | // onEntered on [length -1] 209 | if (value.isNotEmpty()) { 210 | 211 | val letter = value[value.length - 1] 212 | layout_input_password.onEntered(value.length - 1, letter) 213 | } 214 | 215 | // onInput on [length] 216 | layout_input_password.onInput(value.length) 217 | 218 | // view focus 219 | layout_input_password.onViewFocus(hasFocus, value.length) 220 | 221 | } 222 | 223 | private fun shake() { 224 | 225 | shakeView(layout_input_password) 226 | } 227 | 228 | private fun shakeView(view: View) { 229 | 230 | shakeAnimationDoing = true 231 | 232 | view.animate() 233 | .translationX(-15f).translationX(15f) 234 | .setDuration(30) 235 | .setInterpolator(CycleInterpolator((150 / 30).toFloat())) 236 | .setDuration(150) 237 | .withEndAction { shakeAnimationDoing = false } 238 | .start() 239 | } 240 | 241 | private fun charIsValid(unicodeChar: Char): Boolean { 242 | 243 | return if (inputType == InputType.NUMBER) 244 | Character.isDigit(unicodeChar) 245 | else 246 | true 247 | } 248 | 249 | private fun getPassword(): String? = if (password.length == passwordLength) password else null 250 | 251 | 252 | /** 253 | * Public functions 254 | */ 255 | 256 | fun setOnPasswordEnterListener(listener: OnPasswordEnterListener) { 257 | 258 | this.onPasswordEnterListener = listener 259 | } 260 | 261 | fun setPassword(password: String): Boolean { 262 | 263 | if (passwordLength <= 0 || password.length != passwordLength) 264 | return false 265 | 266 | this.password = password 267 | 268 | edt_input_password_real.setText(password) 269 | 270 | return layout_input_password.setPassword(password) 271 | } 272 | 273 | /** 274 | * Listeners 275 | */ 276 | 277 | interface OnKeyboardVisibilityListener { 278 | 279 | fun onVisibilityChange(isVisible: Boolean) 280 | 281 | } 282 | 283 | interface OnPasswordEnterListener { 284 | 285 | fun onPasswordEntered(password: String?) 286 | } 287 | 288 | /** 289 | * Input type 290 | */ 291 | 292 | enum class InputType { 293 | 294 | NUMBER, 295 | FREE; 296 | 297 | val value: String 298 | get() { 299 | 300 | return when (this) { 301 | NUMBER -> "number" 302 | FREE -> "free" 303 | } 304 | throw IllegalArgumentException("Not value available for this DateFormat: " + this) 305 | } 306 | 307 | val attrValue: Int 308 | get() { 309 | 310 | return when (this) { 311 | NUMBER -> 1 312 | FREE -> 2 313 | } 314 | 315 | throw IllegalArgumentException("Not value available for this DateFormat: " + this) 316 | } 317 | 318 | companion object { 319 | 320 | fun fromValue(value: Int): InputType { 321 | 322 | when (value) { 323 | 324 | 1 -> return NUMBER 325 | 2 -> return FREE 326 | } 327 | throw IllegalArgumentException("This value is not supported for DateFormat: $value") 328 | } 329 | } 330 | } 331 | 332 | /** 333 | * PasswordType 334 | */ 335 | 336 | enum class PasswordType { 337 | 338 | PASSWORD, 339 | OTP; 340 | 341 | val value: String 342 | get() { 343 | 344 | return when (this) { 345 | PASSWORD -> "password" 346 | OTP -> "otp" 347 | } 348 | throw IllegalArgumentException("Not value available for this DateFormat: " + this) 349 | } 350 | 351 | val attrValue: Int 352 | get() { 353 | 354 | return when (this) { 355 | PASSWORD -> 1 356 | OTP -> 2 357 | } 358 | 359 | throw IllegalArgumentException("Not value available for this DateFormat: " + this) 360 | } 361 | 362 | companion object { 363 | 364 | fun fromValue(value: Int): PasswordType { 365 | 366 | when (value) { 367 | 368 | 1 -> return PASSWORD 369 | 2 -> return OTP 370 | } 371 | throw IllegalArgumentException("This value is not supported for DateFormat: $value") 372 | } 373 | } 374 | } 375 | 376 | } -------------------------------------------------------------------------------- /passwordview/src/main/res/layout/password_input_slot_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /passwordview/src/main/res/layout/password_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 28 | 29 | 34 | 35 | 45 | 46 | -------------------------------------------------------------------------------- /passwordview/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 | -------------------------------------------------------------------------------- /passwordview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32dp 4 | 1.5dp 5 | 6 | 1dp 7 | 8 | 32sp 9 | -------------------------------------------------------------------------------- /passwordview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | passwordview 3 | 4 | * 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /passwordview/src/test/java/com/cis/passwordview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.cis.passwordview; 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 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------