7

My app uses a PIN-based login. I have four EditText views in a row and set a separate instance of the following TextWatcher on each of them:

private class PinDigitWatcher implements TextWatcher {

    private final EditText digit;

    public PinDigitWatcher(EditText digit) {
        this.digit = digit;
    }

    @Override
    public void afterTextChanged(Editable s) {
        if (s.length() <= 0)
            return;
        switch (digit.getId()) {
        case R.id.pin_digit_a:
            mPinDigitB.setFocusableInTouchMode(true);
            mPinDigitB.requestFocus();
            mPinDigitA.setFocusable(false);
            break;
        case R.id.pin_digit_b:
            mPinDigitC.setFocusableInTouchMode(true);
            mPinDigitC.requestFocus();
            mPinDigitB.setFocusable(false);
            break;
        case R.id.pin_digit_c:
            mPinDigitD.setFocusableInTouchMode(true);
            mPinDigitD.requestFocus();
            mPinDigitC.setFocusable(false);
            break;
        case R.id.pin_digit_d:
            mPinDigitD.setFocusable(false);
            onSubmitPin();
            break;
        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) { }
}

Each time the user enters text into one of the EditText views the TextWatcher moves focus to the "next" one. If the user enters text on the last one the request is sent to the server.

This work great on all the devices I've tested except for the Samsung S3 and S4. On these devices there's a half-second delay after the focus change when the user taps a key on the soft keyboard. The result is that if the user taps the first EditText to bring up the keyboard then taps a digit four times in quick succession (e.g. if his PIN is "1111") the first digit is registered, focus changes, but the other three digits are dropped.

I went into the "Samsung keyboard settings" and disabled predictive text, auto replacement, auto capitalization, auto spacing and auto punctuate. Didn't seem to make a difference.

Both my S3 and S4 are running Android 4.3 so, unfortunately, I can't tell whether this is a "Samsung issue" or a "Android 4.3 issue". I've verified that it doesn't happen on a Galaxy Nexus running 4.2.2 and a Nexus 4 running 4.4.2.

Any thoughts on a work-around?

EDIT:

I recreated the issue on a Samsung S4 running Android 4.2.2 so it appears to be a Samsung problem and not Android 4.3 specifically. Here is a working project that illustrates the behavior:

https://drive.google.com/file/d/0B6DvDY2BvxUTRUxZNE5DNXJJM2c

Tap on the fist EditText to bring up the soft keyboard then tap any number key four times in quick succession. Only the first tap will be registered. At the conclusion of the four taps the focus will be on the second EditText (from the left).

EDIT:

More info on the two phones that exhibit the problem:

  • S4: Samsung SGH-I337, Android 4.3, Build: JSS15J.I337UCUEMK2, Kernel: 3.4.0-1921628 Nov 16 2013)
  • S3: Samsung SGH-I747, Android 4.3, Build: JSS15J.I747UCUEMJB, Kernel: 3.0.31-2024954 Oct 31 2013)
ozbek
  • 20,955
  • 5
  • 61
  • 84
jph
  • 2,181
  • 3
  • 30
  • 55
  • I can not reproduce the problem on GT-I9506 with Android 4.3; Samsung keyboard (it says version 4.0 in App info screen), input language: English (UK). – ozbek Feb 11 '14 at 04:25
  • Try tapping a single number as quickly as you can. I did four taps on the number "1" in about 1 second and only two of them made it into the EditTexts. I think the hangup is with the Samsung soft keyboard. It's doing doing something on a tap that's causing it to ignore additional taps until it finishes whatever it's doing. I've edited the question to include more detailed info on the phones where I'm seeing the problem. – jph Feb 11 '14 at 17:40
  • Any update on this? Having same issue for a long time on Samsung devices. Once I connect TextWatcher input becomes really slow. – Mikhail Sep 25 '17 at 18:24

2 Answers2

3

A quick guess: Try doing your check in the onTextChanged(CharSequence s, int start, int before, int count) method of TextWatcher.

As onTextChanged() is called before afterTextChanged(), it may cause the Samsung devices to recognize the focus switch faster and therefore avoid the delay that causes your trouble.

Also, try playing around with the inputType attribute of your EditText (e.g. set it to number or textNoSuggestions) to further improve speed.

saschoar
  • 8,150
  • 5
  • 43
  • 46
  • Good thoughts. Will try when I'm back in to the office on Tuesday. – jph Feb 15 '14 at 03:24
  • So I tried putting the check in beforeTextChanged(). No change. Then I tried changing the input type to "numberPassword"; no change. Previously inputType was "number" and "password" was "true". I guess I'll write this off as a goof on Samsung's part and not worry about it anymore. The PIN entry functionality is still usable, the lag is just annoying. – jph Feb 17 '14 at 14:23
0

Use folowing link and in which use Thread in side on text changed listner

Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34