aabhasr1 / otpview Goto Github PK
View Code? Open in Web Editor NEWA custom view to enter otp/pin of different sizes used usually in cases of authentication.
License: MIT License
A custom view to enter otp/pin of different sizes used usually in cases of authentication.
License: MIT License
I expect that if I have a check for instance
if(otp=="123456"){
otpTextView?.showSuccess()
}
else {
otpTextView?.showError()
}
But it's not updating the state, it only updates the state when I tap on a button and set the state.
hello, thanks for your great library
i would like to ask, how do i change font in otpView? i see there's attribute called app:text_typeface, but i dont know how to use it programmatically / directly from xml..
thank you
04-04 22:16:01.952 31908-31908/com.spinapp.spinapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.spinapp.spinapp, PID: 31908
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spinapp.spinapp/com.spinapp.spinapp.activity.otplogin.VerifyPhoneActivity}: android.view.InflateException: Binary XML file line #73: Binary XML file line #73: Error inflating class in.aabhasjindal.otptextview.OtpTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2560)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5740)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
Caused by: android.view.InflateException: Binary XML file line #73: Binary XML file line #73: Error inflating class in.aabhasjindal.otptextview.OtpTextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.spinapp.spinapp.activity.otplogin.VerifyPhoneActivity.onCreate(VerifyPhoneActivity.kt:51)
at android.app.Activity.performCreate(Activity.java:6543)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5740)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
Caused by: android.view.InflateException: Binary XML file line #73: Error inflating class in.aabhasjindal.otptextview.OtpTextView
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.spinapp.spinapp.activity.otplogin.VerifyPhoneActivity.onCreate(VerifyPhoneActivity.kt:51)
at android.app.Activity.performCreate(Activity.java:6543)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5740)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.spinapp.spinapp.activity.otplogin.VerifyPhoneActivity.onCreate(VerifyPhoneActivity.kt:51)
at android.app.Activity.performCreate(Activity.java:6543)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5740)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0801e4
at android.content.res.Resources.getValue(Resources.java:1552)
at android.content.res.Resources.getDrawable(Resources.java:926)
at android.content.Context.getDrawable(Context.java:463)
at android.view.View.setBackgroundResource(View.java:17558)
at in.aabhasjindal.otptextview.ItemView.generateViews(ItemView.kt:80)
at in.aabhasjindal.otptextview.ItemView.init(ItemView.kt:46)
at in.aabhasjindal.otptextview.ItemView.(ItemView.kt:36)
at in.aabhasjindal.otptextview.OtpTextView.generateViews(OtpTextView.kt:96)
at in.aabhasjindal.otptextview.OtpTextView.styleEditTexts(OtpTextView.kt:61)
at in.aabhasjindal.otptextview.OtpTextView.init(OtpTextView.kt:55)
at in.aabhasjindal.otptextview.OtpTextView.(OtpTextView.kt:46)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.spinapp.spinapp.activity.otplogin.VerifyPhoneActivity.onCreate(VerifyPhoneActivity.kt:51)
at android.app.Activity.performCreate(Activity.java:6543)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5740)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
Used the java code but was unable to enter the values(when clicked, the keyboard also not visible)
<in.aabhasjindal.otptextview.OtpTextView
android:id="@+id/otp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
app:height="40dp"
app:width="40dp"
app:length="6"
app:otp="123456"
app:otp_text_size="@dimen/size_20"
app:otp_box_background="@drawable/otp_box_bg"
android:focusableInTouchMode="true"
android:inputType="number"
android:layout_marginTop="@dimen/cmn_margin" />
The OTPViiew remains enabled and focusable even when we set otpView.isEnabled = false & otpView.isFocusable = false
.
First of all, great job with the library, I love it.
However, I've noted that the first box's background gives the impression of being focused by default which is misleading for instances where there is another view (Edittext) in focus at the time. Users thinking the pinview is focused type out the pin in the wrong view. Is it possible to only have the focused background either once a user clicks on it or once it is focused on?
How should I restrict user to click and type value in otp view?
Hi dude, first nice work with the library, second have been test a little bit and see that when you have a animated layout, the keyboard appear but the focus is not on the EditText,,, for fix it, you must force the keyboard like this for example
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
otpView.setOtpListener(object : OTPListener {
override fun onInteractionListener() {
}
override fun onOTPComplete(otp: String) {
}
})
Error: Unresolved reference: setOtpListner when using in Kotlin
Whereas I had also tried this
otpView.otpListener = (object : OTPListener {
override fun onInteractionListener() {
}
override fun onOTPComplete(otp: String) {
}
})
But the control won't go at listener if OTP text changed.
Can you please help?
box_margin according width of view?
First box left margin & last box right margin = 0
My OTP is 6 digits long and I want to have a little bit extra space after 3 digits. Is it feature available?
If not, can you add this feature in next release?
I'm trying to enable that it takes text as input as well but only accepts to take only numbers?
and I found here
inputType = InputType.TYPE_CLASS_NUMBER
how I can enable taking text as well ?
I want to set android:inputType="numberPassword"
in xml but it's not working. Any help would be appreciated.
There is no Wiki on hide_otp_drawable
settings. How to change the color of the masked numbers?
Please suggest something.
is:issue if screen is launched with view as GONE , setting view programmatically as VISIBLE wont show the otp view
When I use this attribute .. the shape will fill whole the box even if I make the vector width and height ="1dp"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1dp"
android:height="1dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M24,24m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0"
android:fillColor="#241F20"/>
</vector>
Also, please branch development out for people who can't use AndroidX yet so you deploy two artifacts please. Or, at least, backport this change into 1.1.1, I can't use AndroidX.
Hi I have two languages to support, RTL and LTR. can you please tell me how to support that ?
I am faced in "Error inflating class in.aabhasjindal.otptextview.OtpTextView" this issue when import the
dependencies {
implementation 'com.github.aabhasr1:OtpView:v1.1.2'
}
library file.
I am also implement OtpTextView library file source code in my project.
How can i fix it?
Hello,
First, great job for this library !!!!
Is it possible to add two way data binding on "app:otp" field ?
If you want i can make de changes in a PR.
how can I change app:text_typeface.
I did it like this. -> app:text_typeface: "myFont.ttf".
but it didn't work.
is there any solution?
i want to create an otp input like this one..
https://github.com/aabhasr1/OtpView/raw/master/screenshots/otp_view_1.gif
but how?
which attribute that i must use?
android:textColor="@color/colorPrimaryDark"
thie property already Added.
I want to change the color of pin Text, try many colors doesn't work.
please tell which property use for color change of text
Display only White color text only
i want to set box view for this otpview, please help
I have a custom keypad for OTP fields but this OTPtextview open default android number keypad and it is not triggered in touch or click event. Does it has the support?
Thanks in advance!
I try to set android:textColor="@color/red", its not working, after typing the dot color of box is always white, which is not visible if I change the activity color to white.
Please check, I want when I type in the box, the color of the text(which is dot right now) should be black, which is coming white as of now.
As you also shown in attached gif demo file, but what if the screen is white and when I type in the box, the text is not visible.
Error inflating class in.aabhasjindal.otptextview.OtpTextView
It seems the R class is not found in the init and other subsequent methods
how to give box borders, as in th ebackground is white but the borders of the box are red? all I can chnage is the background.
Is there any possibility to make view match screen width? The view is not adaptive at all
Is there any way with which I can change the background text color of filled text box?
On Samsung devices when an OTP text message is sent to the device, it appears as a shortcut in the keyboard to fill the field. This causes the app to freeze on Android 13 running on Samsung 22. On the same device before the update there was no issue. Can supply video.
It's crashing when app:hide_otp is set to "true". Working perfectly when it's set to "false".
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.aku.myreferrals, PID: 14571
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aku.myreferrals/com.aku.myreferrals.activities.PinCodeActivity}: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class in.aabhasjindal.otptextview.OtpTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #76: Binary XML file line #76: Error inflating class in.aabhasjindal.otptextview.OtpTextView
Caused by: android.view.InflateException: Binary XML file line #76: Error inflating class in.aabhasjindal.otptextview.OtpTextView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.aku.myreferrals.activities.PinCodeActivity.onCreate(PinCodeActivity.java:25)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffff
at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:225)
at android.content.res.Resources.getDrawableForDensity(Resources.java:887)
at android.content.res.Resources.getDrawable(Resources.java:827)
at android.content.Context.getDrawable(Context.java:626)
at android.view.View.setBackgroundResource(View.java:21451)
at in.aabhasjindal.otptextview.ItemView.setText(ItemView.java:145)
at in.aabhasjindal.otptextview.OtpTextView.setOTP(OtpTextView.java:177)
at in.aabhasjindal.otptextview.OtpTextView$1.onTextChanged(OtpTextView.java:142)
at android.widget.TextView.sendOnTextChanged(TextView.java:9754)
at android.widget.TextView.setText(TextView.java:5733)
at android.widget.TextView.setText(TextView.java:5571)
at android.widget.EditText.setText(EditText.java:122)
at android.widget.TextView.setText(TextView.java:5528)
at in.aabhasjindal.otptextview.OtpTextView.setOTP(OtpTextView.java:235)
at in.aabhasjindal.otptextview.OtpTextView.generateViews(OtpTextView.java:112)
at in.aabhasjindal.otptextview.OtpTextView.styleEditTexts(OtpTextView.java:69)
at in.aabhasjindal.otptextview.OtpTextView.init(OtpTextView.java:63)
at in.aabhasjindal.otptextview.OtpTextView.(OtpTextView.java:52)
... 28 more
Error inflating class in.aabhasjindal.otptextview.OtpTextView
unable to change the input type
It supports only digit input type
i have tried using this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
or android:windowSoftInputMode="stateHidden|adjustResize"
in manifest but after tapping otpTextView, the keyboard still showing
OTP numeric value is always in English. Can't change it to any device specific language.
How can i toggle the visibility of the numbers?
I need to toggle between numbers and bullets, when user do not want to show the numbers in the rectangles.
Thank you
otpTextView?.otpListener = object : OTPListener {
override fun onInteractionListener() {
}
override fun onOTPComplete(otp: String) {
Toasty.success(this@MainActivity, "The OTP is $otp", Toast.LENGTH_SHORT).show()
otpTextView?.showSuccess()
}
}
not working as expected in your sample
if you are using ktx lib showSuccess() working perfectly
app:text_typeface is not working at all
any update?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.