I am working on an Android soft keyboard and was wondering, is there a way for the keyboard to get the current cursor position? I am currently using the following code:
connection.getTextBeforeCursor(Integer.MAX_VALUE, 0).length()
However, this is very slow (even for a small amount of text, it can take up to 50ms -- running on a Galaxy Nexus, so this would likely be even slower for lower end phones). I have also tested it on a Droid Incredible, and the lag is even more severe.
In the function onUpdateSelection, you are given the new cursor position. However, this function is not always called and therefore storing the value provided by it for future use is not reliable.
Since you can set the cursor position and get selected text (but not the position of the selected text), shouldn't there be a function to get the cursor position?
Thanks for the help!