Android 4.3.1
Nexus 7 (2013)
When in a text field, backspace on the Google US English keyboard (I believe it's default for this device) does nothing.
I wrote the below code in an InputProcessor to try to chase the bug, but it never even catches the backspace.
public boolean keyDown(int keycode) {
Tools.log.debug("keyDown: " + keycode);
I switched to another keyboard and backspace was caught just fine.
Also verified google keyboard backspace works in other apps.
However, I'm not sure the problem is with libgdx.
Not sure on this one, the backspace works correctly on my Nexus 4 and Nexus 5 with the same keyboard.
Alright, I'll close then.
Someone on IRC had same issue and gave more details, I can now reproduce and will look into it.
For clarity:
Default text added when constructing the textfield, or text set via setText cannot be deleted via backspace. If the same text is selected first (along with at least 1 character actually typed into the textfield), backspace will delete the selected text.
I have this filter on TextField:
public boolean acceptChar(TextField f, char c) {
return Character.isLetterOrDigit(c);
}
When I try to put the letter in other language it doesnt typed, its OK. But than i can delete the text EXACTLY on the length of typed chars.
Example:
When the OnScreenKeyboard is shown when entering the TextField, I notice the following message in LogCat:
11-25 06:49:15.112: E/InputMethodService(1027): Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper@42889b40
And when starting the activity:
11-25 06:49:14.932: E/InputMethodService(1027): Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper@42889b40
11-25 06:49:14.932: E/InputMethodService(1027): Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper@42889b40
11-25 06:49:14.952: W/SubtypeSwitcher(1027): Can't find Emoji subtype
11-25 06:49:14.952: W/SubtypeSwitcher(1027): No input method subtype found; return dummy subtype: android.view.inputmethod.InputMethodSubtype@19dab005
It seems only text you input during that particular input session (showing of the keyboard) will work with backspace. If you close the keyboard then go back to edit, the previous entry cannot be deleted.
Your clarification is correct. My problem is being unable to delete text set by setText method
I believe there is a relevant discussion of the problem on the android issue tracker.
The participating project member promised that the issue should be fixed (at least in the short term) with the next update of Google Keyboard.
Cool, thanks for the info @justasm. I still hadn't found how to work around this. Will keep an eye on that issue.
Edit: Actually, that issue does tell us what we need to do to fix it, it would just require a decent amount of changes in how we set up key inputs. Hopefully their fix is easier on us.
Well, after following the discussion at the link above, it seems to be that Google is not going to be implementing the fix they had indicated and are instead taking the stance that any app needing this behavior is just inherently broken. So... I'll implement a short term fix for libgdx, then we'll need to change how we interface with the keyboard for the long term.
Alrighty, here is my quick workaround that at least lets the backspace key work with the Google keyboard.
https://github.com/MobiDevelop/libgdx/commit/83b4b4d9a0c3934985d31242ff4ce2056fe9cfb0
Not sure if there are unintended consequences with doing this in the near term, so please test it and report back before I merge it in.
Sorry for quadruple posting here, but I just got an updated Google Keyboard and it appears to be working now. Anyone want to confirm so we can close this out?
Appears to be working over here too.
Fixed.
There problems with the Android on-screen keyboard still exist. The proposed patch from MobiDevelop does not seem to have been included in master and does not exist in libgdx currently. The reports here claim it's a bug in the Google keyboard app, but there are reports that the "bug" is intentional and WILL NOT be fixed; https://code.google.com/p/android/issues/detail?id=42904 . Until it does get fixed, TextFields in libgdx are not usable on Android. An empty TextField will work as normal, allowing text input and backspace. A pre-populated TextField (set with setText for instance) will show the correct text, but the user can not backspace and remove any text. Adding and removing text to the pre-populated text will work, but the original text will persist.
If the proposed fix actually works (I haven't tested myself) I suggest it gets applied to master. At least until Google changes it's mind and do allow backspace keyboard events to propagate regardless of whether the keyboard app is aware of any text or not.
@mariusk try the nightly build it is there and it solves this issue for me.
Nex and I were unable to reproduce the bug on our devices, but mariusk was able to reproduce it on multiple devices. It remains a mystery.
My proposed workaround was not merged, due to the new Google keyboard seeming to work... But apparently it doesn't work for everyone.
For the record, I tested and was able to observe the bug on Nexus 4, Nexus 5 and Nexus 7 (2013), all running Android 4.4.2. I'm pretty sure the nightlies are being used, as I'm using gradle and it seems to pull updated jars every day.
Just tested on an S4 running Android 4.3. No bug there.
Nexus 7 (2012&2013) with 4.4.2 and Nexus S with 4.1.2 - no bugs.
far, exactly what have you tested? You've made sure you're testing with a pre-populated TextField (i.e. call setText("something");) before trying to backspace? It's kind of unbelievable if we are running the same hardware and OS versions and getting different results. Also, the keyboard bug also exist outside of libgdx according to lots of other reports from Android devs (for Jelly Bean and later revisions using the stock Google keyboard). Anyway, I hope to do more testing later today.
The explanation for why this is probably not a "Google/Android" bug can be found under "Class Overview" here: http://developer.android.com/reference/android/view/KeyEvent.html .
@mariusk yes, i have a prepopulated textfield and attempt to delete the chars from the end. exactly.
check the topic starter's post, he has nexus 7 2013 and the bug was fixed for him too.
I compared notes with nexsoftware, who suggested checking out the Google Keyboard version. Mine was 2.0.19003.937116a, his (and he did not experience the bug) was more recent at version 2.0.19133.927933a. I have updated everything on my devices and have never been offered to update Google Keyboard. When I searched for "Google Keyboard" in the Play Store it wasn't even found. But googling "Google Keyboard", I got the link for the Play Store, which said I had installed it already. I selected "Install" anyway and it was updated to the more recent version. And the best news is that with the new version the bug went away! I have no ideas why Google Keyboard is not being offered to my devices (N4, N5 and N7); it could be a regional thing.
Most helpful comment
I have this filter on TextField:
When I try to put the letter in other language it doesnt typed, its OK. But than i can delete the text EXACTLY on the length of typed chars.
Example: