5

we are implementing custom input method service and we are interested in receiving cursor update events. The documentation of InputMethodSession's updateCursor() says: "This method is called when cursor location of the target input field has changed within its window. This is not normally called, but will only be reported if requested by the input method."

How the input method can request this event?

Thanks in advance,

Andriy

starblue
  • 55,348
  • 14
  • 97
  • 151
uaaquarius
  • 663
  • 5
  • 9

2 Answers2

4

It looks like this is unimplemented. In the TextView implementation, calling updateCursor is conditional on InputMethodManager.isWatchingCursor, which is helpfully defined as follows:

/**
 * Returns true if the current input method wants to watch the location
 * of the input editor's cursor in its window.
 */
public boolean isWatchingCursor(View view) {
    return false;
}

Luckily, you can detect cursor movements using onUpdateSelection, although they will be given to you as a logical position within the text rather than a Rect.

mhsmith
  • 6,675
  • 3
  • 41
  • 58
  • 1
    `onSelectionChanged()` does not suit to me because I need to know the precise position of cursor on the screen, not relative cursor position in the text :) On the other hand `isWatchingCursor()` returns `false` only in Google's default implementation. Some Android vendors do return `true` there. E.g. HTC and LG. – uaaquarius Apr 16 '11 at 09:06
  • Can you link to the source code of those alternative implementations? – mhsmith Apr 17 '11 at 17:21
1

From API level 21 (Lollipop) there is a way to do it:

after you got the inputConnection.

The onUpdateCursorAnchorInfo will be called every time the cursor's position has changed.

bendaf
  • 2,981
  • 5
  • 27
  • 62