GithubHelp home page GithubHelp logo

aabhasr1 / otpview Goto Github PK

View Code? Open in Web Editor NEW
358.0 9.0 97.0 2.46 MB

A custom view to enter otp/pin of different sizes used usually in cases of authentication.

License: MIT License

Kotlin 100.00%
otp pinview android android-library pinview-library android-application java-8 xml java library

otpview's Introduction

OtpView

Note: Help Needed in Maintainance. Please raise PR if you think some changes are needed and i will merge them.

An OTP Box implementation for case when a single digit should be entered Individually.

     

     

Installation in your Project

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.aabhasr1:OtpView:v1.1.2-ktx' // kotlin
}

or

dependencies {
        implementation 'com.github.aabhasr1:OtpView:v1.1.2'
}

How to use the library?

Just add the following to your xml design to show the otpview

.....
<in.aabhasjindal.otptextview.OtpTextView
	android:id="@+id/otp_view"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:textColor="#ffffff"
	app:height="40dp"
	app:width="40dp"
	app:bar_enabled="true"
	app:bar_height="2dp"
	app:length="4"
	app:otp="1234"
	app:otp_text_size="24dp"/>
.....

To get a callback when the user enters the otp make use of OTPListener Interface

private OtpTextView otpTextView;
otpTextView = findViewById(R.id.otp_view);
otpTextView.setOtpListener(new OTPListener() {
	@Override
	public void onInteractionListener() {
	// fired when user types something in the Otpbox
	}
	@Override
	public void onOTPComplete(String otp) {
	// fired when user has entered the OTP fully.
	    Toast.makeText(MainActivity.this, "The OTP is " + otp,  Toast.LENGTH_SHORT).show();
    }
});

you also get some additional methods like :

otpTextView.getOtpListener();  // retrieves the current OTPListener (null if nothing is set)
otpTextView.requestFocusOTP();	//sets the focus to OTP box (does not open the keyboard)
otpTextView.setOTP(otpString);	// sets the entered otpString in the Otp box (for case when otp is retreived from SMS)
otpTextView.getOTP();	// retrieves the OTP entered by user (works for partial otp input too)
otpTextView.showSuccess();	// shows the success state to the user (can be set a bar color or drawable)
otpTextView.showError();	// shows the success state to the user (can be set a bar color or drawable)
otpTextView.resetState();	// brings the views back to default state (the state it was at input)

Thats all for now but new additions will be made frequently.

OtpView Attributes

Attribute Use
android:textColor sets the color of the otp text
app:otp sets the otp in the otp view
app:length sets the no of otp box in the otp view
app:otp_text_size sets the otp text size in the otp view
app:text_typeface sets the otp text typeface in the otp view
app:hide_otp sets if the otp entered is to be shown to the user
app:hide_otp_drawable replaces the pin bullet which is shown to the user when hide_otp is enabled
app:height sets the height of each box inside the otp view
app:width sets the width of each box inside the otp view
app:box_margin sets the space between each box in otp view
app:box_margin_left sets the left space between each box in otp view
app:box_margin_right sets the right space between each box in otp view
app:box_margin_top sets the top space of each box in otp view
app:box_margin_bottom sets the bottom space of each box in otp view
app:bar_enabled shows a bar below each otp box to the user
app:bar_height sets the bar height
app:bar_margin sets the bar margin within each box in otp view
app:bar_margin_left sets the bar left margin within each box in otp view
app:bar_margin_right sets the bar right margin within each box in otp view
app:bar_margin_top sets the bar top margin within each box in otp view
app:bar_margin_bottom sets the bar bottom margin within each box in otp view
app:bar_active_color sets the bar color when the cursor is on the box in otp view
app:bar_inactive_color sets the bar color when the cursor is not on the box in otp view
app:bar_error_color sets the bar color for error state in otp view
app:bar_success_color sets the bar color for success state in otp view
app:otp_box_background sets the box background in otp view
app:otp_box_background_active sets the box background when the cursor is on the box in otp view
app:otp_box_background_inactive sets the box background when the cursor is not on the box in otp view
app:otp_box_background_error sets the box background for error state in otp view
app:otp_box_background_success sets the box background for success state in otp view

Author

Maintained by Aabhas Jindal

Contribution

License

MIT License

Copyright (c) 2019 Aabhas Jindal

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.

otpview's People

Contributors

aabhasr1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

otpview's Issues

android:textColor property not working

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.

Can not find com.github.aabhasr1:OtpView:v1.1.2-ktx

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.

How to prevent keyboard showing after click otpTextView

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

Not working on below Android 6.0

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) 

how to change text_typeFace

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?

Text Color not change

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

Needs post-inflation setter for otp_length

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.

Can't work whit the animateLayoutChanges

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)

App crashing when app:hide_otp is set to "true"

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

showSuccess() not working

     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

how to change font in otpView

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

Unable to enter OTP

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" />

Full sreen view

Is there any possibility to make view match screen width? The view is not adaptive at all

Does it support custom keypad android

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!

Error with Kotlin

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?

Two way databinding on otp field

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.

Fill not working on Android 13 running on Samsung 22

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.

Disable Click

How should I restrict user to click and type value in otp view?

First box background focused by default

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?

Suggestions

box_margin according width of view?
First box left margin & last box right margin = 0

Error inflating class

Error inflating class in.aabhasjindal.otptextview.OtpTextView

It seems the R class is not found in the init and other subsequent methods

Error inflating class in.aabhasjindal.otptextview.OtpTextView

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?

app:hide_otp_drawable=""

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>

2021-02-23_111846

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.