├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── goldenpie
│ │ └── devs
│ │ └── pincodeview
│ │ └── example
│ │ └── MainActivity.kt
│ └── res
│ ├── layout
│ └── activity_main.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
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
└── preview.png
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── goldenpie
│ │ └── devs
│ │ └── pincodeview
│ │ ├── PinCodeView.kt
│ │ ├── SinglePinView.kt
│ │ └── core
│ │ ├── Listeners.kt
│ │ ├── LockType.kt
│ │ └── Utils.ext.kt
│ └── res
│ ├── drawable
│ └── circle.xml
│ ├── layout
│ ├── pin_code_view_layout.xml
│ └── single_pin_view_layout.xml
│ └── values
│ ├── attrs.xml
│ └── colors.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/java,android,androidstudio
3 |
4 | ### Android ###
5 | # Built application files
6 | *.apk
7 | *.ap_
8 |
9 | # Files for the ART/Dalvik VM
10 | *.dex
11 |
12 | # Java class files
13 | *.class
14 |
15 | # Generated files
16 | bin/
17 | gen/
18 | out/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # Intellij
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/dictionaries
45 | .idea/libraries
46 |
47 | # Keystore files
48 | *.jks
49 |
50 | # External native build folder generated in Android Studio 2.2 and later
51 | .externalNativeBuild
52 |
53 | # Google Services (e.g. APIs or Firebase)
54 | google-services.json
55 |
56 | # Freeline
57 | freeline.py
58 | freeline/
59 | freeline_project_description.json
60 |
61 | ### Android Patch ###
62 | gen-external-apklibs
63 |
64 | ### AndroidStudio ###
65 | # Covers files to be ignored for android development using Android Studio.
66 |
67 | # Built application files
68 |
69 | # Files for the ART/Dalvik VM
70 |
71 | # Java class files
72 |
73 | # Generated files
74 |
75 | # Gradle files
76 | .gradle
77 |
78 | # Signing files
79 | .signing/
80 |
81 | # Local configuration file (sdk path, etc)
82 |
83 | # Proguard folder generated by Eclipse
84 |
85 | # Log Files
86 |
87 | # Android Studio
88 | /*/build/
89 | /*/local.properties
90 | /*/out
91 | /*/*/build
92 | /*/*/production
93 | *.ipr
94 | *~
95 | *.swp
96 |
97 | # Android Patch
98 |
99 | # External native build folder generated in Android Studio 2.2 and later
100 |
101 | # NDK
102 | obj/
103 |
104 | # IntelliJ IDEA
105 | *.iws
106 | /out/
107 |
108 | # User-specific configurations
109 | .idea/libraries/
110 | .idea/.name
111 | .idea/compiler.xml
112 | .idea/copyright/profiles_settings.xml
113 | .idea/encodings.xml
114 | .idea/misc.xml
115 | .idea/modules.xml
116 | .idea/scopes/scope_settings.xml
117 | .idea/vcs.xml
118 | .idea/jsLibraryMappings.xml
119 | .idea/datasources.xml
120 | .idea/dataSources.ids
121 | .idea/sqlDataSources.xml
122 | .idea/dynamic.xml
123 | .idea/uiDesigner.xml
124 |
125 | # Keystore files
126 |
127 | # OS-specific files
128 | .DS_Store
129 | .DS_Store?
130 | ._*
131 | .Spotlight-V100
132 | .Trashes
133 | ehthumbs.db
134 | Thumbs.db
135 |
136 | # Legacy Eclipse project files
137 | .classpath
138 | .project
139 |
140 | # Mobile Tools for Java (J2ME)
141 | .mtj.tmp/
142 |
143 | # Package Files #
144 | *.jar
145 | *.war
146 | *.ear
147 |
148 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
149 | hs_err_pid*
150 |
151 | ## Plugin-specific files:
152 |
153 | # mpeltonen/sbt-idea plugin
154 | .idea_modules/
155 |
156 | # JIRA plugin
157 | atlassian-ide-plugin.xml
158 |
159 | # Mongo Explorer plugin
160 | .idea/mongoSettings.xml
161 |
162 | # Crashlytics plugin (for Android Studio and IntelliJ)
163 | com_crashlytics_export_strings.xml
164 | crashlytics.properties
165 | crashlytics-build.properties
166 | fabric.properties
167 |
168 | ### AndroidStudio Patch ###
169 | # Google Services plugin
170 |
171 | !/gradle/wrapper/gradle-wrapper.jar
172 |
173 | ### Java ###
174 | # Compiled class file
175 |
176 | # Log file
177 |
178 | # BlueJ files
179 | *.ctxt
180 |
181 | # Mobile Tools for Java (J2ME)
182 |
183 | # Package Files #
184 | *.zip
185 | *.tar.gz
186 | *.rar
187 |
188 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
189 |
190 | # End of https://www.gitignore.io/api/java,android,androidstudio
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://android-arsenal.com/details/1/5852) [](https://jitpack.io/#antoxa2584x/PinCodeView)
2 |
3 | PinCodeView
4 | =====================
5 | `PinCodeView` is Android UI library for replace `EditText`'s PIN input with pretty customizable view.
6 |
7 | ## Demo
8 | 
9 |
10 | See demo app for usage example.
11 |
12 | Installation
13 | ============
14 |
15 | Edit your master `gradle.build` file and **add** `maven { url 'https://jitpack.io' }` to your current
16 | `repositories` block content (if you use other jitpack hosted libraries, then this step can be skipped):
17 |
18 | allprojects {
19 | repositories {
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 |
24 | Next, edit your **module**'s `build.gradle` and the following dependency:
25 |
26 | compile 'com.github.antoxa2584x:PinCodeView:'
27 |
28 | For recent value of `` consult [library releases](https://github.com/antoxa2584x/PinCodeView/releases)
29 | or jitpack badge: [](https://jitpack.io/#antoxa2584x/PinCodeView/v1.0)
30 |
31 | ## How To Use
32 | ### In Xml
33 | ```xml
34 |
49 | ```
50 |
51 | ### In Your Code
52 | ```java
53 | PinCodeView pinCodeView = new PinCodeView(this)
54 | .setLockType(LOCK_TYPE.ENTER_PIN)
55 | .setPinEnteredListener(this)
56 | .setPinReEnterListener(this)
57 | .setPinMismatchListener(this)
58 | .setInnerCircleColor(color)
59 | .setOuterCircleColor(color)
60 | .setErrorColor(color)
61 | .setLockType(isChecked ? LOCK_TYPE.ENTER_PIN : LOCK_TYPE.UNLOCK)
62 | .setPinLength(length)
63 | .setInnerAlpha(1)
64 | .setTintInner(false)
65 | .setTintOuter(false)
66 | .setInnerDrawable(ContextCompat.getDrawable(this, R.drawable.circle))
67 | .setOuterDrawable(ContextCompat.getDrawable(this, R.drawable.circle));
68 | ```
69 |
70 | ## Changelog
71 | ### v1.2
72 | - custom pin drawable
73 | - inner pin alpha
74 | - use tint or not
75 |
76 | ## License
77 | ```
78 | MIT License
79 |
80 | Copyright (c) 2017 antoxa2584x
81 |
82 | Permission is hereby granted, free of charge, to any person obtaining a copy
83 | of this software and associated documentation files (the "Software"), to deal
84 | in the Software without restriction, including without limitation the rights
85 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
86 | copies of the Software, and to permit persons to whom the Software is
87 | furnished to do so, subject to the following conditions:
88 |
89 | The above copyright notice and this permission notice shall be included in all
90 | copies or substantial portions of the Software.
91 |
92 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
93 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
94 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
95 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
96 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
97 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
98 | SOFTWARE.
99 | ```
100 |
--------------------------------------------------------------------------------
/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 28
7 |
8 | defaultConfig {
9 | applicationId "com.goldenpie.devs.pincodeview"
10 | minSdkVersion 16
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(include: ['*.jar'], dir: 'libs')
26 | implementation 'com.android.support:appcompat-v7:28.0.0'
27 | implementation 'com.pes.materialcolorpicker:library:1.2.4'
28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 |
30 | implementation project(':library')
31 | }
32 |
33 | androidExtensions {
34 | experimental = true
35 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/antoxa2584/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview.example
2 |
3 | import android.app.Activity
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import android.widget.SeekBar
8 | import android.widget.Toast
9 | import com.goldenpie.devs.pincodeview.core.Listeners
10 | import com.goldenpie.devs.pincodeview.core.LockType
11 | import com.pes.androidmaterialcolorpickerdialog.ColorPicker
12 | import kotlinx.android.synthetic.main.activity_main.*
13 |
14 |
15 | class MainActivity : AppCompatActivity(), Listeners.PinEnteredListener, Listeners.PinReEnterListener, Listeners.PinMismatchListener, View.OnClickListener {
16 |
17 | override fun onCreate(savedInstanceState: Bundle?) {
18 | super.onCreate(savedInstanceState)
19 | setContentView(R.layout.activity_main)
20 |
21 | initView()
22 |
23 | listOf(pinCodeView, drawablePinCodeView).onEach {
24 | it.setLockType(LockType.ENTER_PIN)
25 | it.setPinEnteredListener(this)
26 | it.setPinReEnterListener(this)
27 | it.setPinMismatchListener(this)
28 | }
29 | }
30 |
31 | private fun initView() {
32 | seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
33 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
34 | listOf(pinCodeView, drawablePinCodeView).onEach {
35 | it.setPinLength(progress)
36 | }
37 | }
38 |
39 | override fun onStartTrackingTouch(seekBar: SeekBar) {
40 |
41 | }
42 |
43 | override fun onStopTrackingTouch(seekBar: SeekBar) {
44 |
45 | }
46 | })
47 |
48 | alphaSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
49 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
50 | listOf(pinCodeView, drawablePinCodeView).onEach {
51 | it.setInnerAlpha(progress.div(10f))
52 | }
53 | }
54 |
55 | override fun onStartTrackingTouch(seekBar: SeekBar) {
56 |
57 | }
58 |
59 | override fun onStopTrackingTouch(seekBar: SeekBar) {
60 |
61 | }
62 | })
63 |
64 | listOf(innerColor, outerColor, errorColor).onEach {
65 | it.setOnClickListener(this)
66 | }
67 |
68 | switchCompat.setOnCheckedChangeListener { _, isChecked ->
69 | listOf(pinCodeView, drawablePinCodeView).onEach {
70 | it.setLockType(if (isChecked) LockType.ENTER_PIN else LockType.UNLOCK)
71 | }
72 | }
73 |
74 | innerTintSwitch.setOnCheckedChangeListener { _, isChecked ->
75 | listOf(pinCodeView, drawablePinCodeView).onEach {
76 | it.setTintInner(isChecked)
77 | }
78 | }
79 |
80 | outerTintSwitch.setOnCheckedChangeListener { _, isChecked ->
81 | listOf(pinCodeView, drawablePinCodeView).onEach {
82 | it.setTintOuter(isChecked)
83 | }
84 | }
85 | }
86 |
87 | override fun onPinEntered(pinCode: String?) {
88 | toast(pinCode)
89 | }
90 |
91 | override fun onPinReEnterStarted() {
92 | toast("Pin re-enter started")
93 | }
94 |
95 | override fun onPinMismatch() {
96 | toast("Pin mismatch")
97 | }
98 |
99 | override fun onClick(v: View) {
100 | val cp = ColorPicker(this@MainActivity)
101 | .apply {
102 | show()
103 | }
104 |
105 | when (v) {
106 | innerColor -> {
107 | cp.setCallback { color ->
108 | listOf(pinCodeView, drawablePinCodeView).onEach {
109 | it.setInnerCircleColor(color)
110 | }
111 | cp.dismiss()
112 | }
113 | }
114 | outerColor -> {
115 | cp.setCallback { color ->
116 | listOf(pinCodeView, drawablePinCodeView).onEach {
117 | it.setOuterCircleColor(color)
118 | }
119 | cp.dismiss()
120 | }
121 | }
122 | errorColor -> {
123 | cp.setCallback { color ->
124 | listOf(pinCodeView, drawablePinCodeView).onEach {
125 | it.setErrorColor(color)
126 | }
127 | cp.dismiss()
128 | }
129 | }
130 | }
131 | }
132 |
133 | private fun Activity.toast(string: String?) =
134 | Toast.makeText(this, string, Toast.LENGTH_SHORT).show()
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
28 |
29 |
42 |
43 |
48 |
49 |
55 |
56 |
62 |
63 |
69 |
70 |
71 |
76 |
77 |
84 |
85 |
90 |
91 |
98 |
99 |
104 |
105 |
110 |
111 |
118 |
119 |
123 |
124 |
131 |
132 |
133 |
134 |
139 |
140 |
145 |
146 |
153 |
154 |
159 |
160 |
167 |
168 |
169 |
174 |
175 |
180 |
181 |
188 |
189 |
194 |
195 |
202 |
203 |
204 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/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 | PinCodeView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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.71'
5 | repositories {
6 | jcenter()
7 | maven { url "https://jitpack.io" }
8 | google()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.1.4'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | jcenter()
23 | maven { url "https://jitpack.io" }
24 | google()
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | org.gradle.configureondemand=false
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 26 14:44:31 MSK 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 bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/images/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antoxa2584x/PinCodeView/f4df80276eabe9d2a1fc2847da597b78be2bd196/images/preview.png
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'com.github.dcendents.android-maven'
5 |
6 | android {
7 | compileSdkVersion 28
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | ext.supportLibsVersion = "28.0.0"
26 |
27 | implementation "com.android.support:appcompat-v7:$supportLibsVersion"
28 | implementation "com.android.support:design:$supportLibsVersion"
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 | }
31 |
32 | androidExtensions {
33 | experimental = true
34 | }
35 |
36 | group='com.github.antoxa2584x'
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/antoxa2584/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview
2 |
3 | import android.content.Context
4 | import android.graphics.Color
5 | import android.graphics.drawable.Drawable
6 | import android.os.Build
7 | import android.os.Handler
8 | import android.support.annotation.ColorInt
9 | import android.support.annotation.RequiresApi
10 | import android.support.v4.content.ContextCompat
11 | import android.support.v7.widget.AppCompatEditText
12 | import android.text.Editable
13 | import android.text.InputFilter
14 | import android.text.TextWatcher
15 | import android.util.AttributeSet
16 | import android.view.Gravity
17 | import android.view.LayoutInflater
18 | import android.view.View
19 | import android.view.View.OnFocusChangeListener
20 | import android.view.ViewGroup
21 | import android.widget.LinearLayout
22 | import com.goldenpie.devs.pincodeview.core.Listeners
23 | import com.goldenpie.devs.pincodeview.core.LockType
24 | import com.goldenpie.devs.pincodeview.core.pxFromDp
25 | import com.goldenpie.devs.pincodeview.core.showDelayedKeyboard
26 | import java.util.*
27 |
28 | open class PinCodeView : LinearLayout, View.OnClickListener {
29 |
30 | @ColorInt
31 | private var innerCircleColor: Int = 0
32 | @ColorInt
33 | private var outerCircleColor: Int = 0
34 | @ColorInt
35 | private var errorColor: Int = 0
36 |
37 | private var innerDrawable: Drawable? = null
38 | private var outerDrawable: Drawable? = null
39 | private var pinCount: Int = 0
40 | private var innerAlpha: Float = 0.toFloat()
41 | private var tintInner = true
42 | private var tintOuter = true
43 |
44 | private lateinit var pinLayout: LinearLayout
45 | private lateinit var invisibleEditText: AppCompatEditText
46 | private var lockType: LockType? = null
47 | private var pass: String? = null
48 |
49 | private var pinEnteredListener: Listeners.PinEnteredListener? = null
50 | private var pinMismatchListener: Listeners.PinMismatchListener? = null
51 | private var pinReEnterListener: Listeners.PinReEnterListener? = null
52 |
53 | private val pins = ArrayList()
54 |
55 | constructor(context: Context) : super(context) {
56 | init(null)
57 | }
58 |
59 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
60 | init(attrs)
61 | }
62 |
63 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
64 | init(attrs)
65 | }
66 |
67 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
68 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
69 | init(attrs)
70 | }
71 |
72 | private fun initView() {
73 | val inflater: LayoutInflater = context
74 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
75 |
76 | with(inflater.inflate(R.layout.pin_code_view_layout, this)) {
77 | pinLayout = findViewById(R.id.pin_layout) as LinearLayout
78 | invisibleEditText = findViewById(R.id.invisible_edittext) as AppCompatEditText
79 | }
80 | }
81 |
82 | private fun parseAttributes(attrs: AttributeSet?) {
83 | innerCircleColor = Color.WHITE
84 | outerCircleColor = ContextCompat.getColor(context, R.color.primary_dark)
85 | errorColor = ContextCompat.getColor(context, R.color.accent)
86 | pinCount = 4
87 | lockType = LockType.UNLOCK
88 | innerAlpha = 0.3f
89 |
90 | if (attrs == null)
91 | return
92 |
93 | with(context.obtainStyledAttributes(attrs, R.styleable.PinCodeView)) {
94 | innerCircleColor = getColor(R.styleable.PinCodeView_pcv_pin_inner_color, innerCircleColor)
95 | outerCircleColor = getColor(R.styleable.PinCodeView_pcv_pin_outer_color, outerCircleColor)
96 | errorColor = getColor(R.styleable.PinCodeView_pcv_pin_error_color, errorColor)
97 | pinCount = getInteger(R.styleable.PinCodeView_pcv_pin_length, pinCount)
98 | innerAlpha = getFloat(R.styleable.PinCodeView_pcv_pin_inner_alpha, innerAlpha)
99 | tintInner = getBoolean(R.styleable.PinCodeView_pcv_pin_tint_inner, tintInner)
100 | tintOuter = getBoolean(R.styleable.PinCodeView_pcv_pin_tint_outer, tintOuter)
101 |
102 | innerDrawable = getDrawable(R.styleable.PinCodeView_pcv_pin_inner_drawable)
103 | innerDrawable?:run { innerDrawable = ContextCompat.getDrawable(context, R.drawable.circle) }
104 |
105 | outerDrawable = getDrawable(R.styleable.PinCodeView_pcv_pin_outer_drawable)
106 | outerDrawable?:run { outerDrawable = ContextCompat.getDrawable(context, R.drawable.circle) }
107 |
108 | when (getInt(R.styleable.PinCodeView_pcv_pin_type, 0)) {
109 | 0 -> lockType = LockType.UNLOCK
110 | 1 -> lockType = LockType.ENTER_PIN
111 | }
112 |
113 | recycle()
114 | }
115 | }
116 |
117 | private fun init(attrs: AttributeSet?) {
118 | initView()
119 | parseAttributes(attrs)
120 |
121 | setUpView()
122 | setUpPins()
123 | }
124 |
125 | private fun setUpPins() {
126 | pins.clear()
127 | pinLayout.removeAllViews()
128 |
129 | if (pinCount <= 0)
130 | return
131 |
132 | for (i in 0 until pinCount) {
133 | val singlePinView = SinglePinView(context).apply {
134 | setColors(innerCircleColor, outerCircleColor)
135 |
136 | layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT)
137 | .apply {
138 | weight = 1f
139 | gravity = Gravity.CENTER_HORIZONTAL
140 |
141 | with(pxFromDp(2f).toInt()) {
142 | setMargins(this, this, this, this)
143 | }
144 | }
145 |
146 | innerPinView.setImageDrawable(innerDrawable)
147 | outerPinView.setImageDrawable(outerDrawable)
148 |
149 | if (!tintInner)
150 | innerPinView.clearColorFilter()
151 |
152 | if (!tintOuter)
153 | outerPinView.clearColorFilter()
154 |
155 | innerPinView.alpha = innerAlpha
156 | }
157 |
158 | with(singlePinView) {
159 | pins.add(this)
160 | pinLayout.addView(this)
161 | }
162 | }
163 |
164 | invisibleEditText.filters = arrayOf(InputFilter.LengthFilter(pinCount))
165 | }
166 |
167 | private fun setUpView() {
168 | invisibleEditText.onFocusChangeListener = OnFocusChangeListener { v, hasFocus ->
169 | if (hasFocus) {
170 | showDelayedKeyboard(v)
171 | }
172 | }
173 |
174 | invisibleEditText.addTextChangedListener(object : TextWatcher {
175 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
176 |
177 | }
178 |
179 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
180 | if (pinCount <= 0)
181 | return
182 |
183 | for (pin in pins) {
184 | pin.innerPinView.alpha = innerAlpha
185 | }
186 |
187 | for (i in 0 until s.length) {
188 | pins[i].innerPinView.alpha = 1f
189 | }
190 |
191 | if (lockType == LockType.ENTER_PIN && !pass.isNullOrEmpty() && s.isEmpty()) {
192 | pinReEnterListener?.onPinReEnterStarted()
193 | }
194 |
195 | if (s.length == pinCount) {
196 | pass = s.toString()
197 |
198 | if (lockType == LockType.UNLOCK) {
199 | pinEnteredListener?.onPinEntered(pass)
200 | return
201 | }
202 |
203 | if (pass.isNullOrEmpty()) {
204 | invisibleEditText.text!!.clear()
205 | } else {
206 | if (pass != s.toString()) {
207 |
208 | reset()
209 |
210 | pinMismatchListener?.onPinMismatch()
211 |
212 | return
213 | }
214 |
215 | pinEnteredListener?.onPinEntered(pass)
216 | }
217 | }
218 | }
219 |
220 | override fun afterTextChanged(s: Editable) {
221 |
222 | }
223 | })
224 |
225 | pinLayout.setOnClickListener(this)
226 | }
227 |
228 | /**
229 | * Reset pin code view with error style
230 | */
231 | fun reset() {
232 | for (pin in pins) {
233 | pin.innerPinView.setColorFilter(errorColor)
234 | }
235 |
236 | Handler().postDelayed({
237 | for (pin in pins) {
238 | pin.innerPinView.apply {
239 | if (tintInner)
240 | setColorFilter(innerCircleColor)
241 | else
242 | clearColorFilter()
243 | }
244 |
245 | }
246 |
247 | invisibleEditText.text!!.clear()
248 | }, 500)
249 | }
250 |
251 | /**
252 | * Clear pin code view input
253 | */
254 | fun clear() {
255 | pass = null
256 | invisibleEditText.text!!.clear()
257 | }
258 |
259 | override fun onClick(v: View) {
260 | val id = v.id
261 |
262 | if (id == R.id.pin_layout) {
263 | with(invisibleEditText) {
264 | clearFocus()
265 | requestFocus()
266 | }
267 | }
268 | }
269 |
270 | /**
271 | * Set type of view logic
272 | * Could be one of
273 | * - LockType.UNLOCK if you need just confirm pin
274 | * - LockType.ENTER_PIN if you want to save pin
275 | *
276 | * @param lockType
277 | */
278 | fun setLockType(lockType: LockType): PinCodeView {
279 | this.lockType = lockType
280 | this.pass = null
281 | clear()
282 | return this
283 | }
284 |
285 | fun setInnerCircleColor(@ColorInt innerCircleColor: Int): PinCodeView {
286 | this.innerCircleColor = innerCircleColor
287 | setUpPins()
288 | return this
289 | }
290 |
291 | fun setOuterCircleColor(@ColorInt outerCircleColor: Int): PinCodeView {
292 | this.outerCircleColor = outerCircleColor
293 | setUpPins()
294 | return this
295 | }
296 |
297 | fun setErrorColor(@ColorInt errorColor: Int): PinCodeView {
298 | this.errorColor = errorColor
299 | return this
300 | }
301 |
302 | fun setPinLength(pinCount: Int): PinCodeView {
303 | this.pinCount = pinCount
304 | setUpPins()
305 | return this
306 | }
307 |
308 | fun setInnerDrawable(innerDrawable: Drawable): PinCodeView {
309 | this.innerDrawable = innerDrawable
310 | setUpPins()
311 | return this
312 | }
313 |
314 | fun setOuterDrawable(outerDrawable: Drawable): PinCodeView {
315 | this.outerDrawable = outerDrawable
316 | setUpPins()
317 | return this
318 | }
319 |
320 | fun setInnerAlpha(innerAlpha: Float): PinCodeView {
321 | this.innerAlpha = innerAlpha
322 | setUpPins()
323 | return this
324 | }
325 |
326 | fun setTintInner(tintInner: Boolean): PinCodeView {
327 | this.tintInner = tintInner
328 | setUpPins()
329 | return this
330 | }
331 |
332 | fun setTintOuter(tintOuter: Boolean): PinCodeView {
333 | this.tintOuter = tintOuter
334 | setUpPins()
335 | return this
336 | }
337 |
338 | fun setPinEnteredListener(pinEnteredListener: Listeners.PinEnteredListener): PinCodeView {
339 | this.pinEnteredListener = pinEnteredListener
340 | return this
341 | }
342 |
343 | fun setPinMismatchListener(pinMismatchListener: Listeners.PinMismatchListener): PinCodeView {
344 | this.pinMismatchListener = pinMismatchListener
345 | return this
346 | }
347 |
348 | fun setPinReEnterListener(pinReEnterListener: Listeners.PinReEnterListener): PinCodeView {
349 | this.pinReEnterListener = pinReEnterListener
350 | return this
351 | }
352 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import android.support.annotation.RequiresApi
6 | import android.support.v7.widget.AppCompatImageView
7 | import android.util.AttributeSet
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.widget.LinearLayout
11 |
12 | internal class SinglePinView : LinearLayout {
13 | lateinit var outerPinView: AppCompatImageView
14 | private set
15 | lateinit var innerPinView: AppCompatImageView
16 | private set
17 |
18 | constructor(context: Context) : super(context) {
19 | initView()
20 | }
21 |
22 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
23 | initView()
24 | }
25 |
26 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
27 | initView()
28 | }
29 |
30 | @Suppress("unused")
31 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
32 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
33 | initView()
34 | }
35 |
36 | private fun initView() {
37 | val inflater: LayoutInflater = context
38 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
39 |
40 | with(inflater.inflate(R.layout.single_pin_view_layout, this)) {
41 | outerPinView = findViewById(R.id.outer_pin_view) as AppCompatImageView
42 | innerPinView = findViewById(R.id.inner_pin_view) as AppCompatImageView
43 | }
44 |
45 | listOf(outerPinView, innerPinView).onEach { it.setImageResource(R.drawable.circle) }
46 | }
47 |
48 | fun setColors(innerColor: Int, outerColor: Int) {
49 | outerPinView.setColorFilter(outerColor)
50 | innerPinView.setColorFilter(innerColor)
51 | }
52 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview.core
2 |
3 | open class Listeners {
4 | interface PinEnteredListener {
5 | fun onPinEntered(pinCode: String?)
6 | }
7 |
8 | interface PinMismatchListener {
9 | fun onPinMismatch()
10 | }
11 |
12 | interface PinReEnterListener {
13 | fun onPinReEnterStarted()
14 | }
15 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/goldenpie/devs/pincodeview/core/LockType.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview.core
2 |
3 | enum class LockType {
4 | UNLOCK, ENTER_PIN
5 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.ext.kt:
--------------------------------------------------------------------------------
1 | package com.goldenpie.devs.pincodeview.core
2 |
3 | import android.content.Context
4 | import android.os.Handler
5 | import android.view.View
6 | import android.view.inputmethod.InputMethodManager
7 |
8 | fun View.pxFromDp(dp: Float) = dp * resources.displayMetrics.density
9 |
10 | fun View.showDelayedKeyboard(view: View) = showDelayedKeyboard(view, 100)
11 |
12 | fun View.showDelayedKeyboard(view: View, delay: Int) {
13 | Handler().postDelayed({
14 | val imm = context.getSystemService(
15 | Context.INPUT_METHOD_SERVICE) as InputMethodManager
16 | imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
17 | }, delay.toLong())
18 | }
--------------------------------------------------------------------------------
/library/src/main/res/drawable/circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/pin_code_view_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
25 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/single_pin_view_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
18 |
19 |
31 |
32 |
--------------------------------------------------------------------------------
/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 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #C5CAE9
6 | #FF4081
7 | #212121
8 | #757575
9 | #FFFFFF
10 | #BDBDBD
11 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------