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:
Check Your Keyboard Settings Make sure Gboard is set as your default keyboard. If your Android device automatically switched to a different keyboard, that might explain why Gboard disappeared from your keyboard list. By the way, this often happens shortly after you install a new Android version on your device.
It has to do with the touch input on the phone's screen. When a Galaxy device has an edge display, touch input is available along the screen's edges. Because of this, the keyboard may accidentally disappear if you unintentionally touch the edge while typing with the keyboard.
If you don't find the Samsung Keyboard settings via the above steps, go to “Settings -> General Management -> Language and input -> On-screen keyboard -> Samsung Keyboard.” Alternatively, open the Samsung Keyboard while using any app, then tap on the Settings icon on the keyboard to go to its settings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With