├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── keijumt
│ │ └── passwordview
│ │ └── sample
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── keijumt
│ │ │ └── passwordview
│ │ │ └── sample
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── ripple.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
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── keijumt
│ └── passwordview
│ └── sample
│ └── ExampleUnitTest.kt
├── art
├── password-view.gif
└── sample.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── keijumt
│ │ └── passwordview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── keijumt
│ │ │ └── passwordview
│ │ │ ├── ActionListener.kt
│ │ │ ├── CircleView.kt
│ │ │ ├── PasswordView.kt
│ │ │ └── animation
│ │ │ ├── Animator.kt
│ │ │ ├── ColorChangeAnimation.kt
│ │ │ ├── FillAndStrokeColorChangeAnimation.kt
│ │ │ ├── FillColorChangeAnimation.kt
│ │ │ ├── OutLineColorChangeAnimation.kt
│ │ │ ├── ShakeAnimator.kt
│ │ │ └── SpringAnimator.kt
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── keijumt
│ └── passwordview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/*
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # password-view
2 | Android password animation
3 |
4 |
5 | ## Sample
6 |
7 |
8 | ## Useage
9 |
10 | `implementation 'com.keijumt.passwordview:passwordview:1.0.0'`
11 | ### Layout.xml
12 | ```xml
13 |
18 | ```
19 |
20 | ### Input and Remove password
21 | ```kotlin
22 | // append the value of input and run input animation when text is input
23 | passwordView.appendInputText(password)
24 |
25 | // remove last characters from input values and run animation when text is removed
26 | passwordView.removeInputText()
27 | ```
28 |
29 | ### Correct And Incorrect Animation
30 |
31 | ```kotlin
32 | // Run animation when the password is correct
33 | passwordView.correctAnimation()
34 |
35 | // Run animation when the password is incorrect
36 | passwordView.incorrectAnimation()
37 | ```
38 |
39 | ### Listener
40 | ```kotlin
41 | passwordView.setListener(object : ActionListener {
42 | override fun onCompleteInput(inputText: String) {
43 | // When text input is completed
44 | }
45 |
46 | override fun onEndJudgeAnimation() {
47 | // When animation is completed when the password is correct or when it is incorrect
48 | }
49 | })
50 | ```
51 |
52 | ### Attribute
53 | `app:password_count` - The circle count
54 |
55 | `app:password_radius` - The circle radius
56 |
57 | `app:password_between_margin` - The margin between circles
58 |
59 | `app:password_input_color` - The color of the circle when the value is input
60 |
61 | `app:password_not_input_color` - The color of the circle when the value is
62 | not input
63 |
64 | `app:password_outline_color` - The color of the line around the circle
65 |
66 | `app:password_outline_stroke_width` - The stroke width of the line around
67 | the circle
68 |
69 | `app:password_correct_color` - The color of the circle when the password
70 | is correct
71 |
72 | `app:password_incorrect_color` - The color of the circle when the password
73 | is incorrect
74 |
75 | `app:password_correct_duration` - The animation time when the password is
76 | correct
77 |
78 | `app:password_incorrect_duration` - The animation time when the password
79 | is incorrect
80 |
81 | `app:password_color_change_duration` - The animation time when circle
82 | color changes
83 |
84 | `app:password_input_and_remove_duration` - The animation time when
85 | password is input or remove
86 |
87 | `app:password_correct_top` - In animation when the password is correct, the y coordinate of the highest circle
88 |
89 | `app:password_correct_bottom` - In animation when the password is correct,
90 | the y coordinate of the lowest circle
91 |
92 | `app:password_incorrect_max_width` - In animation when the password is
93 | incorrect, the swing width of the circle
94 |
95 |
96 | ## License
97 | ```
98 | Copyright 2019 Keiju Matsumoto
99 |
100 | Licensed under the Apache License, Version 2.0 (the "License");
101 | you may not use this file except in compliance with the License.
102 | You may obtain a copy of the License at
103 |
104 | http://www.apache.org/licenses/LICENSE-2.0
105 |
106 | Unless required by applicable law or agreed to in writing, software
107 | distributed under the License is distributed on an "AS IS" BASIS,
108 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109 | See the License for the specific language governing permissions and
110 | limitations under the License.
111 | ```
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/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 "com.keijumt.passwordview.sample"
11 | minSdkVersion 21
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 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
37 |
38 | implementation project(':library')
39 | }
40 |
--------------------------------------------------------------------------------
/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/src/androidTest/java/com/keijumt/passwordview/sample/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.keijumt.passwordview.sample
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.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.keijumt.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/keijumt/passwordview/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.keijumt.passwordview.sample
2 |
3 | import android.os.Bundle
4 | import android.widget.TextView
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.keijumt.passwordview.ActionListener
7 | import kotlinx.android.synthetic.main.activity_main.password_view
8 | import kotlinx.android.synthetic.main.activity_main.text_0
9 | import kotlinx.android.synthetic.main.activity_main.text_1
10 | import kotlinx.android.synthetic.main.activity_main.text_2
11 | import kotlinx.android.synthetic.main.activity_main.text_3
12 | import kotlinx.android.synthetic.main.activity_main.text_4
13 | import kotlinx.android.synthetic.main.activity_main.text_5
14 | import kotlinx.android.synthetic.main.activity_main.text_6
15 | import kotlinx.android.synthetic.main.activity_main.text_7
16 | import kotlinx.android.synthetic.main.activity_main.text_8
17 | import kotlinx.android.synthetic.main.activity_main.text_9
18 | import kotlinx.android.synthetic.main.activity_main.text_d
19 |
20 | class MainActivity : AppCompatActivity() {
21 |
22 | companion object {
23 | private const val CORRECT_PASSWORD = "1234"
24 | }
25 |
26 | override fun onCreate(savedInstanceState: Bundle?) {
27 | super.onCreate(savedInstanceState)
28 | setContentView(R.layout.activity_main)
29 |
30 | password_view.setListener(object : ActionListener {
31 | override fun onCompleteInput(inputText: String) {
32 | if (CORRECT_PASSWORD == inputText) {
33 | password_view.correctAnimation()
34 | } else {
35 | password_view.incorrectAnimation()
36 | }
37 | }
38 |
39 | override fun onEndJudgeAnimation() {
40 | password_view.reset()
41 | }
42 | })
43 |
44 | text_0.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
45 | text_1.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
46 | text_2.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
47 | text_3.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
48 | text_4.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
49 | text_5.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
50 | text_6.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
51 | text_7.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
52 | text_8.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
53 | text_9.setOnClickListener { password_view.appendInputText((it as TextView).text.toString()) }
54 | text_d.setOnClickListener { password_view.removeInputText() }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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/ripple.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
23 |
24 |
33 |
34 |
42 |
43 |
51 |
52 |
60 |
61 |
69 |
70 |
78 |
79 |
87 |
88 |
96 |
97 |
105 |
106 |
114 |
115 |
124 |
125 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/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/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 100dp
4 | 80dp
5 | 40sp
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | password-view
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/keijumt/passwordview/sample/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.keijumt.passwordview.sample
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 |
--------------------------------------------------------------------------------
/art/password-view.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/art/password-view.gif
--------------------------------------------------------------------------------
/art/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/art/sample.gif
--------------------------------------------------------------------------------
/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.3.21'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.3.1'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'com.novoda:bintray-release:0.9'
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 |
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keijumt/password-view/f3e4c1067cbeb704ec9f96b01973a90297821db3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 21 21:45:06 JST 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 | apply plugin: 'com.novoda.bintray-release'
5 |
6 | android {
7 | compileSdkVersion 28
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 | }
28 |
29 | publish {
30 | userOrg = 'mtmtkj'
31 | groupId = 'com.keijumt.passwordview'
32 | artifactId = 'passwordview'
33 | publishVersion = '1.0.0'
34 | desc = 'password animation'
35 | website = 'https://github.com/keijumt/password-view'
36 | repoName = 'password-view'
37 | }
38 |
39 | dependencies {
40 | implementation fileTree(dir: 'libs', include: ['*.jar'])
41 |
42 | implementation 'com.android.support:appcompat-v7:28.0.0'
43 | testImplementation 'junit:junit:4.12'
44 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
45 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
46 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
47 | }
48 | repositories {
49 | mavenCentral()
50 | }
51 |
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/keijumt/passwordview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.keijumt.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.keijumt.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/ActionListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview
18 |
19 | interface ActionListener {
20 | fun onCompleteInput(inputText: String)
21 | fun onEndJudgeAnimation()
22 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/CircleView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview
18 |
19 | import android.animation.Animator
20 | import android.animation.AnimatorListenerAdapter
21 | import android.animation.ValueAnimator
22 | import android.annotation.SuppressLint
23 | import android.content.Context
24 | import android.graphics.Canvas
25 | import android.graphics.Color
26 | import android.graphics.Paint
27 | import android.graphics.Paint.ANTI_ALIAS_FLAG
28 | import android.util.AttributeSet
29 | import android.view.View
30 | import androidx.interpolator.view.animation.FastOutLinearInInterpolator
31 |
32 | internal class CircleView @JvmOverloads constructor(
33 | context: Context,
34 | attrs: AttributeSet? = null,
35 | defStyleAttr: Int = 0
36 | ) : View(context, attrs, defStyleAttr) {
37 |
38 | private val outLinePaint = Paint(ANTI_ALIAS_FLAG).apply {
39 | color = Color.GRAY
40 | strokeWidth = 4f
41 | style = Paint.Style.STROKE
42 | }
43 |
44 | private val fillCirclePaint = Paint(ANTI_ALIAS_FLAG).apply {
45 | color = Color.WHITE
46 | style = Paint.Style.FILL
47 | }
48 |
49 | private val fillAndStrokeCirclePaint = Paint(ANTI_ALIAS_FLAG).apply {
50 | color = Color.BLACK
51 | style = Paint.Style.FILL_AND_STROKE
52 | }
53 |
54 | private var radius = 16f
55 |
56 | private var animator: ValueAnimator? = null
57 |
58 | private var inputAndRemoveAnimationDuration = 200L
59 |
60 | private var progress = 0.0f
61 | set(value) {
62 | field = value
63 | postInvalidateOnAnimation()
64 | }
65 |
66 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
67 | val width = ((radius * 2) + (outLinePaint.strokeWidth)).toInt()
68 | val height = ((radius * 2) + (outLinePaint.strokeWidth)).toInt()
69 | setMeasuredDimension(width, height)
70 | }
71 |
72 | @SuppressLint("DrawAllocation")
73 | override fun onDraw(canvas: Canvas) {
74 |
75 | val halfOutLineStrokeWidth = outLinePaint.strokeWidth / 2
76 |
77 | // fill circle
78 | canvas.drawCircle(
79 | radius + halfOutLineStrokeWidth,
80 | radius + halfOutLineStrokeWidth,
81 | lerp(radius - halfOutLineStrokeWidth, 0f, progress),
82 | fillCirclePaint
83 | )
84 |
85 | // outline circle
86 | canvas.drawCircle(
87 | radius + halfOutLineStrokeWidth,
88 | radius + halfOutLineStrokeWidth,
89 | lerp(radius, 0f, progress),
90 | outLinePaint
91 | )
92 |
93 | // fill and stroke circle
94 | canvas.drawCircle(
95 | radius + halfOutLineStrokeWidth,
96 | radius + halfOutLineStrokeWidth,
97 | lerp(0f, radius + halfOutLineStrokeWidth, progress),
98 | fillAndStrokeCirclePaint
99 | )
100 | }
101 |
102 | fun animateAndInvoke(onEnd: (() -> Unit)? = null) {
103 | if (animator != null) {
104 | return
105 | }
106 |
107 | val newProgress = if (progress == 0f) 1f else 0f
108 | animator = ValueAnimator.ofFloat(progress, newProgress).apply {
109 | duration = inputAndRemoveAnimationDuration
110 | addUpdateListener {
111 | progress = it.animatedValue as Float
112 | }
113 | addListener(object : AnimatorListenerAdapter() {
114 | override fun onAnimationEnd(animation: Animator?) {
115 | animator = null
116 | onEnd?.invoke()
117 | }
118 | })
119 | interpolator = FastOutLinearInInterpolator()
120 | }
121 | animator?.start()
122 | }
123 |
124 | fun setRadius(radius: Float) {
125 | this.radius = radius
126 | invalidate()
127 | }
128 |
129 | fun setFillCircleColor(color: Int) {
130 | fillCirclePaint.color = color
131 | postInvalidateOnAnimation()
132 | }
133 |
134 | fun setOutLineColor(color: Int) {
135 | outLinePaint.color = color
136 | postInvalidateOnAnimation()
137 | }
138 |
139 | fun setFillAndStrokeCircleColor(color: Int) {
140 | fillAndStrokeCirclePaint.color = color
141 | postInvalidateOnAnimation()
142 | }
143 |
144 | fun setOutlineStrokeWidth(strokeWidth: Float) {
145 | outLinePaint.strokeWidth = strokeWidth
146 | }
147 |
148 | fun isAnimating(): Boolean = animator != null
149 |
150 | fun getFillAndStrokeCircleColor(): Int = fillAndStrokeCirclePaint.color
151 |
152 | fun getFillCircleColor(): Int = fillCirclePaint.color
153 |
154 | fun getOutLineColor(): Int = outLinePaint.color
155 |
156 | fun setInputAndRemoveAnimationDuration(duration: Long) {
157 | inputAndRemoveAnimationDuration = duration
158 | }
159 |
160 | /*
161 | * Linearly interpolate between two values.
162 | */
163 | private fun lerp(a: Float, b: Float, t: Float): Float {
164 | return a + (b - a) * t
165 | }
166 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/PasswordView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview
18 |
19 | import android.content.Context
20 | import android.graphics.Color
21 | import android.util.AttributeSet
22 | import android.view.ViewGroup
23 | import android.widget.LinearLayout
24 | import com.keijumt.passwordview.animation.Animator
25 | import com.keijumt.passwordview.animation.FillAndStrokeColorChangeAnimation
26 | import com.keijumt.passwordview.animation.FillColorChangeAnimation
27 | import com.keijumt.passwordview.animation.ShakeAnimator
28 | import com.keijumt.passwordview.animation.SpringAnimator
29 |
30 | class PasswordView @JvmOverloads constructor(
31 | context: Context,
32 | attrs: AttributeSet? = null,
33 | defStyleAttr: Int = 0
34 | ) : LinearLayout(context, attrs, defStyleAttr) {
35 |
36 | companion object {
37 | private const val DEFAULT_CIRCLE_COUNT = 4
38 | private const val DEFAULT_RADIUS = 20f
39 | private const val DEFAULT_BETWEEN_MARGIN = 72
40 | private const val DEFAULT_INPUT_COLOR = Color.BLACK
41 | private const val DEFAULT_NOT_INPUT_COLOR = Color.WHITE
42 | private const val DEFAULT_OUTLINE_COLOR = Color.GRAY
43 | private const val DEFAULT_CORRECT_COLOR = Color.GREEN
44 | private const val DEFAULT_INCORRECT_COLOR = Color.RED
45 | private const val DEFAULT_CORRECT_ANIMATION_DURATION = 150
46 | private const val DEFAULT_INCORRECT_ANIMATION_DURATION = 400
47 | private const val DEFAULT_COLOR_CHANGE_ANIMATION_DURATION = 200
48 | private const val DEFAULT_INPUT_AND_REMOVE_ANIMATION_DURATION = 200
49 | private const val DEFAULT_CORRECT_TOP = 40f
50 | private const val DEFAULT_CORRECT_BOTTOM = 15f
51 | private const val DEFAULT_INCORRECT_MAX_WIDTH = 40f
52 | private const val DEFAULT_OUTLINE_STROKE_WIDTH = 4f
53 | }
54 |
55 | private val array = context.obtainStyledAttributes(attrs, R.styleable.PasswordView)
56 | var passwordCount = array.getInteger(R.styleable.PasswordView_password_count, DEFAULT_CIRCLE_COUNT)
57 | set(value) {
58 | field = value
59 | addCircleView(passwordCount)
60 | }
61 | private val radius = array.getDimension(R.styleable.PasswordView_password_radius, DEFAULT_RADIUS)
62 | private val betweenMargin =
63 | array.getDimensionPixelOffset(R.styleable.PasswordView_password_between_margin, DEFAULT_BETWEEN_MARGIN)
64 | private val inputColor = array.getColor(R.styleable.PasswordView_password_input_color, DEFAULT_INPUT_COLOR)
65 | private val notInputColor = array.getColor(R.styleable.PasswordView_password_input_color, DEFAULT_NOT_INPUT_COLOR)
66 | private val outlineColor = array.getColor(R.styleable.PasswordView_password_outline_color, DEFAULT_OUTLINE_COLOR)
67 | private val correctColor = array.getColor(R.styleable.PasswordView_password_correct_color, DEFAULT_CORRECT_COLOR)
68 | private val incorrectColor =
69 | array.getColor(R.styleable.PasswordView_password_incorrect_color, DEFAULT_INCORRECT_COLOR)
70 | private val correctAnimationDuration =
71 | array.getInteger(R.styleable.PasswordView_password_correct_duration, DEFAULT_CORRECT_ANIMATION_DURATION)
72 | .toLong()
73 | private val incorrectAnimationDuration =
74 | array.getInteger(R.styleable.PasswordView_password_correct_duration, DEFAULT_INCORRECT_ANIMATION_DURATION)
75 | .toLong()
76 | private val colorChangeAnimationDuration =
77 | array.getInteger(
78 | R.styleable.PasswordView_password_color_change_duration,
79 | DEFAULT_COLOR_CHANGE_ANIMATION_DURATION
80 | )
81 | .toLong()
82 | private val inputAndRemoveAnimationDuration =
83 | array.getInteger(
84 | R.styleable.PasswordView_password_input_and_remove_duration,
85 | DEFAULT_INPUT_AND_REMOVE_ANIMATION_DURATION
86 | ).toLong()
87 | private val correctTop = array.getDimension(R.styleable.PasswordView_password_correct_top, DEFAULT_CORRECT_TOP)
88 | private val correctBottom =
89 | array.getDimension(R.styleable.PasswordView_password_correct_bottom, DEFAULT_CORRECT_BOTTOM)
90 | private val incorrectMaxWidth =
91 | array.getDimension(R.styleable.PasswordView_password_incorrect_max_width, DEFAULT_INCORRECT_MAX_WIDTH)
92 | private val outlineStrokeWidth = array.getDimension(
93 | R.styleable.PasswordView_password_outline_stroke_width,
94 | DEFAULT_OUTLINE_STROKE_WIDTH
95 | )
96 |
97 | private val circleViews = mutableListOf()
98 |
99 | private var input: String = ""
100 | set(value) {
101 | val oldInput = field
102 | field = value
103 | if (oldInput.length != value.length || value.length <= circleViews.size) {
104 | handleInputAnimate(oldInput, value)
105 | }
106 | }
107 |
108 | private var actionListener: ActionListener? = null
109 |
110 | init {
111 | array.recycle()
112 |
113 | orientation = LinearLayout.HORIZONTAL
114 | addCircleView(passwordCount)
115 | }
116 |
117 | private fun incorrectAnimation(duration: Long) {
118 | circleViews.forEachIndexed { index, circleView ->
119 | ShakeAnimator(circleView).apply {
120 | this.duration = duration
121 | this.shakeMaxWidth = incorrectMaxWidth.toInt()
122 | startDelay = (index * 40).toLong()
123 |
124 | addListener(object : Animator.AnimatorListener {
125 | override fun onAnimationEnd() {
126 | if (index == passwordCount - 1) {
127 | this@PasswordView.actionListener?.onEndJudgeAnimation()
128 | }
129 | }
130 | })
131 |
132 | start()
133 | }
134 | }
135 | }
136 |
137 | private fun correctAnimation(duration: Long) {
138 | circleViews.forEachIndexed { index, circleView ->
139 | SpringAnimator(circleView).run {
140 | this.duration = duration
141 | startDelay = (index * 40).toLong()
142 | moveTopY = correctTop
143 | moveBottomY = correctBottom
144 |
145 |
146 | addListener(object : Animator.AnimatorListener {
147 | override fun onAnimationEnd() {
148 | if (index == passwordCount - 1) {
149 | this@PasswordView.actionListener?.onEndJudgeAnimation()
150 | }
151 | }
152 | })
153 |
154 | start()
155 | }
156 | }
157 | }
158 |
159 | private fun addCircleView(circleCount: Int) {
160 |
161 | removeAllViews()
162 |
163 | for (i in 0 until circleCount) {
164 | val circleView = CircleView(context).apply {
165 | setOutLineColor(outlineColor)
166 | setOutlineStrokeWidth(outlineStrokeWidth)
167 | setFillCircleColor(notInputColor)
168 | setFillAndStrokeCircleColor(inputColor)
169 | setInputAndRemoveAnimationDuration(inputAndRemoveAnimationDuration)
170 | setRadius(radius)
171 | layoutParams = calcMargin(i, circleCount)
172 | }
173 | this.addView(circleView)
174 | circleViews.add(circleView)
175 | }
176 | }
177 |
178 | private fun calcMargin(circleIndex: Int, circleCount: Int): ViewGroup.LayoutParams? {
179 | if (circleCount < 0) {
180 | throw IllegalArgumentException("passwordCount:$circleCount must be greater than or equal to 0")
181 | }
182 |
183 | if (circleIndex < 0) {
184 | throw IllegalArgumentException("circleIndex:$circleIndex must be greater than or equal to 0")
185 | }
186 |
187 | if (circleCount == 0) {
188 | return null
189 | }
190 |
191 | val halfMargin = betweenMargin / 2
192 | val halfIncorrectMaxWidth = (incorrectMaxWidth / 2).toInt()
193 | val layoutParams = LinearLayout.LayoutParams(width, height).apply {
194 | topMargin = correctTop.toInt()
195 | bottomMargin = correctBottom.toInt()
196 | }
197 | if (circleCount == 1) {
198 | return layoutParams.apply {
199 | leftMargin = halfIncorrectMaxWidth
200 | rightMargin = halfIncorrectMaxWidth
201 | }
202 | }
203 |
204 | if (circleCount == 2) {
205 | return when (circleIndex) {
206 | 0 -> layoutParams.apply {
207 | leftMargin = halfIncorrectMaxWidth
208 | rightMargin = halfMargin
209 | }
210 | 1 -> layoutParams.apply {
211 | leftMargin = halfMargin
212 | rightMargin = halfIncorrectMaxWidth
213 | }
214 | else -> throw IllegalArgumentException("circleIndex:$circleIndex must be greater than or equal to 0")
215 | }
216 | }
217 |
218 | return when (circleIndex) {
219 | 0 -> layoutParams.apply {
220 | leftMargin = halfIncorrectMaxWidth
221 | rightMargin = halfMargin
222 | }
223 | in 1 until circleCount - 1 -> layoutParams.apply {
224 | leftMargin = halfMargin
225 | rightMargin = halfMargin
226 | }
227 | circleCount - 1 -> layoutParams.apply {
228 | leftMargin = halfMargin
229 | rightMargin = halfIncorrectMaxWidth
230 | }
231 | else -> throw IllegalArgumentException("circleIndex:$circleIndex must be greater than or equal to 0")
232 | }
233 | }
234 |
235 | private fun handleInputAnimate(oldInput: String, newInput: String) {
236 |
237 | // increase input text
238 | if (newInput.length > oldInput.length) {
239 | for (i in oldInput.length until newInput.length) {
240 | circleViews[i].animateAndInvoke {
241 | if (newInput.length == circleViews.size) {
242 | actionListener?.onCompleteInput(input)
243 | }
244 | }
245 | }
246 | } else {
247 | for (i in newInput.length until oldInput.length) {
248 | circleViews[i].animateAndInvoke()
249 | }
250 | }
251 | }
252 |
253 | /**
254 | * run correct animation
255 | */
256 | fun correctAnimation() {
257 | correctAnimation(correctAnimationDuration)
258 | fillAndStrokeColorChangeAnimation(colorChangeAnimationDuration, correctColor)
259 | }
260 |
261 | /**
262 | * run incorrect animation
263 | */
264 | fun incorrectAnimation() {
265 | incorrectAnimation(incorrectAnimationDuration)
266 | fillAndStrokeColorChangeAnimation(colorChangeAnimationDuration, incorrectColor)
267 | }
268 |
269 | /**
270 | * Empty the value of input and run reset animation
271 | */
272 | fun reset() {
273 | input = ""
274 | fillColorChangeAnimation(colorChangeAnimationDuration, notInputColor)
275 | fillAndStrokeColorChangeAnimation(colorChangeAnimationDuration, inputColor)
276 | }
277 |
278 | fun setListener(actionListener: ActionListener) {
279 | this.actionListener = actionListener
280 | }
281 |
282 |
283 | fun removeListener() {
284 | this.actionListener = null
285 | }
286 |
287 | /**
288 | * append the value of input and run input animation
289 | */
290 | fun appendInputText(text: String) {
291 | if (text.length + input.length > passwordCount) {
292 | return
293 | }
294 |
295 | repeat(text.length) {
296 | if (circleViews[input.length + it].isAnimating()) {
297 | return
298 | }
299 | }
300 |
301 | input += text
302 | }
303 |
304 | /**
305 | * remove last characters from input values and run not input animation
306 | */
307 | fun removeInputText() {
308 | if (input.isEmpty()) {
309 | return
310 | }
311 |
312 | if (circleViews[input.length - 1].isAnimating()) {
313 | return
314 | }
315 |
316 | input = input.dropLast(1)
317 | }
318 |
319 | private fun fillAndStrokeColorChangeAnimation(duration: Long, color: Int) {
320 | circleViews.forEach { circleView ->
321 | FillAndStrokeColorChangeAnimation(circleView).run {
322 | this.duration = duration
323 | toColor = color
324 | start()
325 | }
326 | }
327 | }
328 |
329 | private fun fillColorChangeAnimation(duration: Long, color: Int) {
330 | circleViews.forEach { circleView ->
331 | FillColorChangeAnimation(circleView).run {
332 | this.duration = duration
333 | toColor = color
334 | start()
335 | }
336 | }
337 | }
338 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/Animator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import android.view.View
20 |
21 | abstract class Animator(private val target: View) {
22 |
23 | abstract fun start()
24 |
25 | open fun addListener(listener: AnimatorListener) {
26 | throw RuntimeException("Stub!")
27 | }
28 |
29 | open fun removeAllListener() {
30 | throw RuntimeException("Stub!")
31 | }
32 |
33 | interface AnimatorListener {
34 | fun onAnimationEnd()
35 | }
36 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/ColorChangeAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import android.animation.AnimatorListenerAdapter
20 | import android.animation.ValueAnimator
21 | import com.keijumt.passwordview.CircleView
22 |
23 | internal abstract class ColorChangeAnimation(
24 | target: CircleView
25 | ) : Animator(target) {
26 |
27 | private var animator: ValueAnimator? = null
28 | var toColor: Int = 0
29 | var duration: Long = 200
30 | var startDelay: Long = 100
31 |
32 | override fun start() {
33 | animator = ValueAnimator.ofArgb(getColor(), toColor).apply {
34 | duration = this@ColorChangeAnimation.duration
35 | startDelay = this@ColorChangeAnimation.startDelay
36 | addUpdateListener {
37 | setColor(it.animatedValue as Int)
38 | }
39 | }
40 | animator?.start()
41 | }
42 |
43 | override fun addListener(listener: AnimatorListener) {
44 | animator?.addListener(object : AnimatorListenerAdapter() {
45 | override fun onAnimationEnd(animation: android.animation.Animator?) {
46 | listener.onAnimationEnd()
47 | }
48 | })
49 | }
50 |
51 | protected abstract fun getColor(): Int
52 | abstract fun setColor(color: Int)
53 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/FillAndStrokeColorChangeAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import com.keijumt.passwordview.CircleView
20 |
21 | internal class FillAndStrokeColorChangeAnimation(
22 | private val circleView: CircleView
23 | ) : ColorChangeAnimation(circleView) {
24 |
25 | override fun getColor(): Int = circleView.getFillAndStrokeCircleColor()
26 |
27 | override fun setColor(color: Int) {
28 | circleView.setFillAndStrokeCircleColor(color)
29 | }
30 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/FillColorChangeAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import com.keijumt.passwordview.CircleView
20 |
21 | internal class FillColorChangeAnimation(
22 | private val circleView: CircleView
23 | ) : ColorChangeAnimation(circleView) {
24 |
25 | override fun getColor(): Int = circleView.getFillCircleColor()
26 |
27 | override fun setColor(color: Int) {
28 | circleView.setFillCircleColor(color)
29 | }
30 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/OutLineColorChangeAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import com.keijumt.passwordview.CircleView
20 |
21 | internal class OutLineColorChangeAnimation(
22 | private val circleView: CircleView
23 | ) : ColorChangeAnimation(circleView) {
24 |
25 | override fun getColor(): Int = circleView.getOutLineColor()
26 |
27 | override fun setColor(color: Int) {
28 | circleView.setOutLineColor(color)
29 | }
30 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/ShakeAnimator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import android.animation.AnimatorListenerAdapter
20 | import android.animation.ValueAnimator
21 | import android.view.View
22 | import kotlin.math.sin
23 |
24 | internal class ShakeAnimator(
25 | private val target: View
26 | ) : Animator(target) {
27 |
28 | private var animator = ValueAnimator.ofFloat(0f, 1f)
29 | var duration: Long = 400
30 | var startDelay: Long = 0
31 | var shakeMaxWidth: Int = 40
32 | var shakeTimes: Int = 4
33 |
34 | override fun start() {
35 | animator.run {
36 | cancel()
37 | duration = this@ShakeAnimator.duration
38 | startDelay = this@ShakeAnimator.startDelay
39 |
40 | val initialPositionX = target.x
41 | addUpdateListener {
42 | val progress = it.animatedValue as Float
43 | target.run {
44 | x = initialPositionX + sin(shakeTimes * Math.PI * progress).toFloat() * shakeMaxWidth / 2
45 | }
46 | }
47 | start()
48 | }
49 | }
50 |
51 | override fun addListener(listener: AnimatorListener) {
52 | animator.addListener(object : AnimatorListenerAdapter() {
53 | override fun onAnimationEnd(animation: android.animation.Animator?) {
54 | listener.onAnimationEnd()
55 | }
56 | })
57 | }
58 |
59 | override fun removeAllListener() {
60 | animator.removeAllListeners()
61 | }
62 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/keijumt/passwordview/animation/SpringAnimator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Keiju Matsumoto
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.keijumt.passwordview.animation
18 |
19 | import android.animation.AnimatorListenerAdapter
20 | import android.animation.AnimatorSet
21 | import android.animation.ObjectAnimator
22 | import android.view.View
23 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator
24 |
25 | internal class SpringAnimator(
26 | private val target: View
27 | ) : Animator(target) {
28 |
29 | private val animatorSet = AnimatorSet()
30 |
31 | var duration: Long = 150
32 | var startDelay: Long = 0
33 |
34 | var moveTopY: Float = target.y - 30f
35 | set(value) {
36 | field = target.y - value
37 | }
38 |
39 | var moveBottomY: Float = target.y + 10f
40 | set(value) {
41 | field = target.y + value
42 | }
43 |
44 | override fun start() {
45 | animatorSet.run {
46 | val initialPositionY = target.y
47 | val animator1 = ObjectAnimator.ofFloat(target, "y", moveTopY)
48 | val animator2 = ObjectAnimator.ofFloat(target, "y", moveBottomY)
49 | val animator3 = ObjectAnimator.ofFloat(target, "y", initialPositionY)
50 | playSequentially(animator1, animator2, animator3)
51 |
52 | interpolator = FastOutSlowInInterpolator()
53 | duration = this@SpringAnimator.duration
54 | startDelay = this@SpringAnimator.startDelay
55 |
56 | start()
57 | }
58 | }
59 |
60 | override fun addListener(listener: AnimatorListener) {
61 | animatorSet.addListener(object : AnimatorListenerAdapter() {
62 | override fun onAnimationEnd(animation: android.animation.Animator?) {
63 | listener.onAnimationEnd()
64 | }
65 | })
66 | }
67 | }
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/keijumt/passwordview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.keijumt.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', ':library'
2 |
--------------------------------------------------------------------------------