PinView - Kotlin library
A customizable Pin Code entry view that can be used as a user login authentication method in your project.
Installation
- in project's build.gradle , add jitPack.io as following
allprojects {
repositories {
.....
.....
maven { url "https://jitpack.io" }
}
}
- in module's build.gradle , add the implementation as following
dependencies {
.....
.....
implementation 'com.github.khaled2252:pin-view:1.0.0'
}
Usage
- Add PinView to your acivity/fragment.xml
<com.khaledahmedelsayed.pinview.PinView
android:id="@+id/pinView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:errorMessageText="Invalid Pin Code"
app:dotProgressColor="@android:color/holo_purple"
app:titleName="Enter Pin Code">
</com.khaledahmedelsayed.pinview.PinView>
-
Reference it in your activity/fragment class
pinView.clearPin() pinView.deleteLastPin()
Methods
pinView.clearPin()
-> clears current pin progresspinView.deletePin()
-> deletes last pin code numberpinView.showError(true)
-> displays an error messagepinView.showError(false)
-> hides the error messagepinView.isErrorVisible()
-> returns true if the error message is visibleListeners
There are 2 listeners that can be used as following :-
- OnCompletedListener() which is called when user enters the 4th pin number
pinView.setOnCompletedListener = { pinCode -> if(pinCode == "1234") startActivity(Intent(this,HomeActivity::class.java)) else pinView.showError(true) pinView.clearPin() }
- onPinKeyClickedListener() which is called when user clicks on any key in the pin keyboard (except for the 4th pin number)
pinView.setOnPinKeyClickListener = { keyPressed -> Toast.makeText(this,"Key pressed was $keyPressed",Toast.LENGTH_SHORT).show() }
Customization
You can customize PinView's attributes using app namespace in xml as following :-
app:titleTextColor=""
app:titleTextSize=""
app:dotProgressColor=""
app:dotUnProgressColor=""
app:dotRadius=""
app:numbersTextColor=""
app:numbersTextSize=""
app:deleteButtonColor=""
app:clearButtonColor=""
app:errorMessageText=""
app:errorMessageTextSize=""
app:errorMessageColor=""
Changelog
Version: 1.0
- Initial Build
License
Copyright 2020 Khaled
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.