OtpinVerification
OtpinVerification & Dialog
Description:
Extremely useful library for validating EditText inputs whether by using just the validator (OtpinVerification) for your custom view or using library's extremely resizable & customisable dialog (OtpinDialogCreator)
Features:
- OtpinVerification for validating your EditTexts from your own layout view
- OtpinDialogCreator (library's customisable dialog)
Setup.
To get a Git project into your build:
- Add the JitPack repository to you root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.EhmaUgbogo:OtpinVerification:1.0.3'
}
Usage
1. OtpinVerification (Use to power your own custom layout view)
val yourEditTexts = listOf(yourEditText1, yourEditText2, yourEditText3,...)
val inputType = OtpInputType.DIGIT // Library default. if used can be ommited
otpin = OtpinVerification(yourEditTexts, inputType) { validated, percent, otp ->
// Your code here
}//.startCountDown(5, countDownListener)
otpin.setOtpInputsText(yourOtpText) //SetText at runtime
otpin.clearInputs() //Clear edittexts at runtime
Add CountDown
otpin.startCountDown(minutes, object :OtpCountDownListener{
override fun onCountDown(sec: Int, minutes: Int, timeFormat: String, onFinish: Boolean) {
// your code here
if(onFinish){
// your code here
}
}
})
2. OtpinDialogCreator
// All operations that can be done on the dialog
otpDialog = OtpinDialogCreator.with(this)
//.title(title)
//.customSubtitle("Please provide your card cvv")
//.customBtnText("Submit")
//.logo(R.drawable.ic_logo)
//.cancelable(false)
//.otpFields(OtpFields.THREE)
//.inputType(OtpInputType.DIGIT)
.countDown(5)
.setCountDownFinishListener { showToast("Count Down completed") }
.setContinueListener { otpDialog, otp -> continueClicked(otpDialog, otp) }
.setResendListener {resendClicked(it)}
.setCancelListener { showToast("Task Cancelled") }
//.displayMode(OtpDisplay.FullScreen(showToolbar = true))
//.autoSubmitOnComplete(hideContinueBtn = false)
//.excludeResend()
//.displayOnlyInputFields()
//.theme(R.style.myOtpDialogTheme)
//.windowAnimation(R.style.yourWindowStyle)
//.disableWindowAnimation()
//.boxShape() // Use styles instead // Not available via runtime now
.start()
otpDialog.setOtpInputsText(yourOtpText) //SetText at runtime
otpDialog.dismissDialog() //Dismiss OtpinDialog
otpDialog.showMessage(msg, useSnackInsteadOfToast = true) //Show message via SnackBar or Toast
otpDialog.hideProgress() // Hide otpDialog progressBar
Styling Used Underneath
OtpinDialogCreator uses the following attr and styles under the hood with values that you can easily adjust to suit your brand
<item name="otpDialogTitleTextAppearance">@style/OtpDialogTitleAppearanceitem>
<item name="otpDialogSubtitleTextAppearance">@style/OtpDialogSubTitleAppearanceitem>
<item name="otpDialogCounterTextAppearance">@style/OtpDialogCounterTextAppearanceitem>
<item name="otpDialogResendTextAppearance">@style/OtpDialogResendTextAppearanceitem>
<item name="otpDialogLayoutPadding">4dpitem>
<item name="otpDialogLayoutCornerRadius">16dpitem>
<item name="otpDialogBoxWidth">48dpitem>
<item name="otpDialogBoxHeight">48dpitem>
<item name="otpDialogBoxStrokeWidth">1dpitem>
<item name="otpDialogBoxStrokeWidthFocused">2dpitem>
<item name="otpDialogBoxSpacing">8dpitem>
<item name="otpDialogBoxStyle">@style/BoxStyle.Outlineitem>
<item name="otpDialogBoxShape">@style/OtpBoxShape.Normalitem>
<item name="otpDialogBoxEditTextStyle">@style/BoxEditTextStyleitem>
<item name="otpDialogButtonStyle">@style/OtpDialogButtonStyle.Roundeditem>
<item name="otpDialogToolbarColor">@color/otp_color_toolbaritem>
<item name="otpDialogToolbarIconColor">@color/otp_color_toolbar_iconitem>
<item name="otpDialogLayoutPadding">4dpitem>
<item name="otpDialogLayoutCornerRadius">16dpitem>
<item name="otpDialogIsFloating">falseitem>
Styling Yours
So to style yours simply create a theme that extends otpDialogTheme then use any precreated styles or extend them for further customization. for example to change the title font & size, see titleAppearance and buttonStyle below.
<style name="myOtpDialogThemeFloating" parent="myOtpDialogTheme">
<item name="otpDialogIsFloating">trueitem>
style>
<style name="myOtpDialogTheme" parent="OtpDialogTheme">
<item name="otpDialogBoxStyle">@style/BoxStyle.Underlineitem>
<item name="otpDialogBoxShape">@style/OtpBoxShape.Roundeditem>
<item name="otpDialogButtonStyle">@style/OtpDialogButtonStyleitem>
<item name="otpDialogBoxSpacing">12dpitem>
<item name="otpDialogTitleTextAppearance">@style/titleAppearanceitem>
<item name="otpDialogButtonStyle">@style/buttonStyleitem>
style>
<style name="titleAppearance" parent="OtpDialogTitleAppearance">
<item name="fontFamily">@font/poppins_blackitem>
style>
<style name="buttonStyle" parent="OtpDialogButtonStyle">
<item name="fontFamily">@font/poppins_mediumitem>
<item name="cornerRadius">8dpitem>
style>
// Apply your fullscreen theme
otpDialog = OtpinDialogCreator.with(this)
.title(title)
.theme(R.style.myOtpDialogTheme)
.start()
// Apply your floating screen theme
otpDialog = OtpinDialogCreator.with(this)
.title(title)
.displayMode(OtpDisplay.Float)
.theme(R.style.myOtpDialogThemeFloating)
.start()
Color
For colors add these below to your color.xml
<color name="otp_color_status_bar">@color/your_color_herecolor>
<color name="otp_color_toolbar">@color/your_color_herecolor>
<color name="otp_color_toolbar_icon">@color/your_color_herecolor>
<color name="otp_color_primary">@color/your_color_herecolor>
<color name="otp_color_widget_active">@color/your_color_herecolor>
<color name="otp_title_color">@color/your_color_herecolor>
<color name="otp_subtitle_color">@color/your_color_herecolor>
Licence
MIT Licence
Copyright (c) [2021] Ehma Ugbogo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.