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)