Asus Zenfone (Android) TextView\\TextWatcher keybo

2019-05-23 09:26发布

问题:

Update: actually, this is not a problem with Asus Phones, it's a problem with Asus ZenUI's keyboard. You can install a keyboard you like to walk around the problem. I have tested Zenfone 2 with Google Keyboard installed. Everything in my TextWatcher works fine. But it is not a bug fix or problem solution.

I have two InputFilters and one TextWatcher attached to my EditText.

InputFilters: standard InputFilter.AllCaps() filter and custom 'alphabet characetrs only'. They works as magic.

TextWatcher makes some text transofrmations (transliterates symbols from Russian into English). TextWatcher also works fine but not on Asus phones (tested on Zenfone 4 and 5). Nexus 5, Genymotion emulator and Samsung device is OK.

The problem is that Asus phone not allows to enter more than one symbol. Probably, there is a problem with TextWatcher or setSelection() (everything works fine on Asus when TextWatcher is disabled).

Listing for TextView:

etCardholder.setFilters(new InputFilter[]{new InputFilter.AllCaps(), new NameInputeFilter(false)});

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

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        etCardholder.removeTextChangedListener(twTransliterator);
        etCardholder.setText(StringTools.transliterateCharacterRuToEn(s.toString()));
        etCardholder.addTextChangedListener(twTransliterator);
    }

    @Override
    public void afterTextChanged(Editable s) {
        etCardholder.setSelection(etCardholder.getText().length());
        validateCardData();
    }
};

etCardholder.addTextChangedListener(twTransliterator);

I've tried not to set cursor's position with setSelection(), but use append() instead. Same results here.

Do you have any ideas what probably it can be? And how to walk around it?

回答1:

I found a solution for this problem, in my case was the inputType attribute on EditText was with the param: textCapCharacters, and i resolve using the textNoSuggestions. You can also use both with the pipe operator '|'.

 android:inputType="textCapCharacters|textNoSuggestions"


回答2:

For future googlers!

the bug is from Asus ZenUI's keyboard, as mentioned in the question. And workaround suggested by @Gabriel Correra totally solves the issue, however you may not want to put this flag for all the users since not everyone is using this buggy keyboard.

with this snippet you can find out if user's default keyboard is Asus ZenUI's keyboard and if so add the mentioned flag programmatically and let the other users enjoy their suggestions!

String def = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
if(def.equals("com.asus.ime/.IME")) {
   setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}