mukeshsolanki / android-otpview-pinview

A custom view to enter otp of different sizes used usually in cases of authentication.
MIT License
707 stars 207 forks source link

Requesting focus not working #90

Closed Skullper closed 2 years ago

Skullper commented 4 years ago

Subject of the issue

None of the existing methods for requesting focus not working, even perform click didn't help

Steps to reproduce

Open screen with otpView and try to request focus and show digit keyboard

Expected behaviour

The screen opens with digit keyboard(set in xml) and otpView has focused

Actual behaviour

The screen opens without keyboard and request focus not working

dthib commented 4 years ago

Hi, I am facing the same issue in my app. But the sample given in the repo is working well... Still trying to understand why. Any suggestion apreciated :) Best

heinzan commented 4 years ago

same here

heinzan commented 4 years ago

I added OTP View Dialog.I want when dialog.open,keyboard open but cann't

jonasgsvensson commented 4 years ago

Working for me if I add android:focusableInTouchMode="true"

Skullper commented 4 years ago

@jonasgsvensson not working for me. Here is my setup:

<style name="OtpWidget.OtpView.TfaPinViewStyle">
        <item name="android:cursorVisible">false</item>
        <item name="android:fontFamily">@font/roboto_regular</item>
        <item name="android:inputType">numberSigned</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:textColor">@color/text_primary</item>
        <item name="android:textSize">40sp</item>
        <item name="android:importantForAutofill" tools:targetApi="o">no</item>
        <item name="lineColor">@color/text_primary</item>
        <item name="lineWidth">@dimen/divider_height</item>
        <item name="itemCount">6</item>
        <item name="itemHeight">100dp</item>
        <item name="itemRadius">12dp</item>
        <item name="itemSpacing">0dp</item>
        <item name="viewType">rectangle</item>
</style>
heinzan commented 4 years ago

NOBODY HELP

KgotsoK commented 4 years ago

I added android:focusableInTouchMode="true" and it worked for me too

heinzan commented 4 years ago

not work for me

Skullper commented 4 years ago

not working for me either

TuanDi-SEMC commented 4 years ago

i got same issue. I cannot focus even through touch on view

Nikunj2505 commented 4 years ago

tried all solutions. Not working either.

heinzan commented 4 years ago

someone can solved

Nikunj2505 commented 4 years ago

I resolved using

Handler().postDelayed({
            otpView.dispatchTouchEvent(MotionEvent.obtain(uptimeMillis(), uptimeMillis(), MotionEvent.ACTION_DOWN, 0f, 0f, 0))
            otpView.dispatchTouchEvent(MotionEvent.obtain(uptimeMillis(), uptimeMillis(), MotionEvent.ACTION_UP, 0f, 0f, 0))
        }, 200)
Skullper commented 4 years ago

@Nikunj2505 I dunno why and how but it works)

Skullper commented 4 years ago

But I suppose it is still an issue

n-droidev commented 4 years ago

Just add this line to your OtpView in xml code: style="@style/OtpWidget.OtpView"

I know it is weird.

Skullper commented 4 years ago

@techwizard1 Nope, not working for my case :(

vincent-paing commented 4 years ago

@Nikunj2505 thanks you so much, that works for me

mukeshsolanki commented 4 years ago

Can anyone send me a working example of this one?? I'll try to fix the issue if I have an example to work with

Skullper commented 4 years ago

@mukeshsolanki Hi, here is my xml:

<com.mukesh.OtpView
        android:id="@+id/pin_view_confirm"
        style="@style/OtpWidget.OtpView.TfaPinViewStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_margin_12dp"/>

This is style which I'm using:

<style name="OtpWidget.OtpView.TfaPinViewStyle">
        <item name="android:cursorVisible">false</item>
        <item name="android:fontFamily">@font/roboto_regular</item>
        <item name="android:inputType">numberSigned</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:textColor">@color/text_primary</item>
        <item name="android:textSize">40sp</item>
        <item name="android:importantForAutofill" tools:targetApi="o">no</item>
        <item name="lineColor">@color/text_primary</item>
        <item name="lineWidth">@dimen/divider_height</item>
        <item name="itemCount">6</item>
        <item name="itemHeight">100dp</item>
        <item name="itemRadius">12dp</item>
        <item name="itemSpacing">0dp</item>
        <item name="viewType">rectangle</item>
    </style>

And code:

pin_view_confirm?.apply {
            hint = "0".repeat(PIN_CODE_SIZE)
            updateItemWidth(PIN_CODE_SIZE)
            setOnDoneActionListener {
                sendPin(email, pass)
                true
            }
            textWatcher = InputTextTextWatcher {
                this.setLineColor(ContextCompat.getColor(this@TfaActivity, R.color.text_primary))
            }
            addTextChangedListener(textWatcher)
        }

Hope it helps to reproduce.

mukeshsolanki commented 4 years ago

Have you tried adding <item name="otpViewStyle">@style/OtpWidget.OtpView</item> inside your apptheme??

anunkwp commented 4 years ago

@Nikunj2505 He is my Hero.

Skullper commented 4 years ago

@mukeshsolanki Yes. It is overridden in my app theme. But I have overridden @style/OtpWidget.OtpView, not my custom one. I will try with my custom and comment here

Skullper commented 4 years ago

@mukeshsolanki Nope :( I added my custom style(attached above) into app theme:

<item name="otpViewStyle">@style/OtpWidget.OtpView.TfaPinViewStyle</item>

And requested focus for otpView during initialization, but it didn't help. As I understand you cannot reproduce this bug, yes?

mukeshsolanki commented 4 years ago

Yes I'm unable to reproduce this issue could you send a sample app?

mukeshsolanki commented 4 years ago

@Skullper any update?

Skullper commented 3 years ago

@mukeshsolanki Sorry, I was busy at work. Yeah, I will send you sample in a few days. Thanks

lsuski commented 3 years ago

OtpView by default uses otpViewStyle attribute which have to be defined in theme. It overrides editTextStyle attribute from AppCompatEditText

absolute-vijju commented 2 years ago

1. Add this property (android:windowSoftInputMode="stateVisible") into your manifest's activity tag like this:

<activity android:name=".ui.AuthActivity" android:exported="true" android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible" />

2. Add this line into your Activity class when you want to open keyboard:

mBinding.otpView.requestFocus()

That's all you need to do :)

Skullper commented 2 years ago

1. Add this property (android:windowSoftInputMode="stateVisible") into your manifest's activity tag like this:

<activity android:name=".ui.AuthActivity" android:exported="true" android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible" />

2. Add this line into your Activity class when you want to open keyboard:

mBinding.otpView.requestFocus()

That's all you need to do :)

Interesting but how it should help? And what if I don't want to make my activity exported or my screenOrientation is not locked for portrait?

Maybe the key is android:windowSoftInputMode="stateVisible"?

absolute-vijju commented 2 years ago

1. Add this property (android:windowSoftInputMode="stateVisible") into your manifest's activity tag like this: <activity android:name=".ui.AuthActivity" android:exported="true" android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible" /> 2. Add this line into your Activity class when you want to open keyboard: mBinding.otpView.requestFocus() That's all you need to do :)

Interesting but how it should help? And what if I don't want to make my activity exported or my screenOrientation is not locked for portrait?

Maybe the key is android:windowSoftInputMode="stateVisible"?

Yes.

mukeshsolanki commented 2 years ago

Please check the latest version of the lib