public interface TextInputClient
Known subtypesEditField, CodeView, EditorView, RichView
A low level text input client, the counterpart to a platform text input source (soft keyboard, IME,
autocorrect and hardware keyboard). A component that wants to own text editing itself - rendering
text with its own Graphics code instead of a native text widget - implements this interface and
binds it through com.codename1.impl.CodenameOneImplementation#startTextInput. From then on the
platform routes committed text, IME composition (marked text), deletions and key commands directly
into the client, and the client answers back with the surrounding text and caret geometry the
platform needs to place candidate windows, the selection loupe and predictions.
This is the same pattern high end custom editors use (a hidden input surface driving a
custom rendered document). Codename One’s pure RichTextArea / CodeEditor are the primary
consumers, but the API is deliberately general so any component can capture raw text input.
All offsets exchanged with the platform are UTF-16 character indices. All callbacks are delivered on the EDT.
Fields
Methods
public abstract void commitText(String text) | Commits final text at the caret, replacing the active selection. |
public abstract void setComposingText(String text, int relativeCaret) | Updates the in progress IME composition (marked text) at the caret. |
public abstract void finishComposing() | Finalizes any active IME composition, committing the current marked text. |
public abstract void deleteSurroundingText(int before, int after) | Deletes text around the caret, the primary deletion path used by soft keyboards. |
public abstract void onKeyCommand(int command, int modifiers) | Delivers a non text key command (navigation, deletion, clipboard, undo). |
public abstract void onEditorAction(int action) | Delivers the keyboard return key action (done / next / search / send) configured through TextInputConfig. |
public abstract TextInputState getEditingState() | Returns the current editing state (surrounding text, selection and composition) so the platform can seed autocorrect and prediction. |
public abstract int[] getCaretRect() | Returns the caret rectangle in absolute screen pixels {x, y, width, height}, used by the platform to anchor the IME candidate window and the selection loupe near the rendered caret. |
public abstract TextInputConfig getConfig() | Returns the configuration describing the desired keyboard type and input behavior. |
public abstract void inputFocusGained() | Notifies the client that it gained the platform input focus (became first responder). |
public abstract void inputFocusLost() | Notifies the client that it lost the platform input focus. |
public abstract int getTextLength() | Returns the total number of UTF-16 characters in the document. |
public abstract String getTextRange(int start, int end) | Returns the text in [start, end). |
public abstract int[] rectForOffset(int offset) | Returns the caret rectangle for an arbitrary offset in absolute screen pixels {x, y, w, h}. |
public abstract int offsetAtPoint(int x, int y) | Returns the document offset nearest an absolute screen point (pixels). |
public abstract int[] selectionRects(int start, int end) | Returns the selection rectangles covering [start, end) as a flat array of absolute-pixel rectangles {x, y, w, h, x, y, w, h, ...} (one entry per visual line the range spans). |
public abstract void replaceRange(int start, int end, String text) | Replaces the range [start, end) with text (a direct, range based edit from the platform). |
public abstract void setSelectionRange(int start, int end) | Sets the selection to [start, end) (a caret when equal). |
Field details
KEY_LEFT
public static final int KEY_LEFT = 1KEY_RIGHT
public static final int KEY_RIGHT = 2KEY_UP
public static final int KEY_UP = 3KEY_DOWN
public static final int KEY_DOWN = 4KEY_HOME
public static final int KEY_HOME = 5KEY_END
public static final int KEY_END = 6KEY_PAGE_UP
public static final int KEY_PAGE_UP = 7KEY_PAGE_DOWN
public static final int KEY_PAGE_DOWN = 8KEY_BACKSPACE
public static final int KEY_BACKSPACE = 9KEY_DELETE
public static final int KEY_DELETE = 10KEY_ESCAPE
public static final int KEY_ESCAPE = 11KEY_COPY
public static final int KEY_COPY = 12KEY_CUT
public static final int KEY_CUT = 13KEY_PASTE
public static final int KEY_PASTE = 14KEY_SELECT_ALL
public static final int KEY_SELECT_ALL = 15KEY_UNDO
public static final int KEY_UNDO = 16KEY_REDO
public static final int KEY_REDO = 17KEY_TAB
public static final int KEY_TAB = 18#MOD_SHIFT this is a dedent (shift-tab); otherwise an indent. A plain
editor with no indentation behavior may treat it as inserting a tab character.MOD_SHIFT
public static final int MOD_SHIFT = 1MOD_CTRL
public static final int MOD_CTRL = 2MOD_ALT
public static final int MOD_ALT = 4Method details
commitText
public abstract void commitText(String text)Parameters
textString- the committed text
setComposingText
public abstract void setComposingText(String text, int relativeCaret)#setComposingText and
finalized by #finishComposing.Parameters
textString- the current marked text
relativeCaretint- caret position relative to the marked text (platform convention)
finishComposing
public abstract void finishComposing()deleteSurroundingText
public abstract void deleteSurroundingText(int before, int after)Parameters
beforeint- number of UTF-16 units to delete before the caret
afterint- number of UTF-16 units to delete after the caret
onKeyCommand
public abstract void onKeyCommand(int command, int modifiers)#commitText instead.Parameters
commandint- one of the
KEY_*constants modifiersint- a bit mask of the
MOD_*constants
onEditorAction
public abstract void onEditorAction(int action)TextInputConfig.Parameters
actionint- one of the
TextInputConfigACTION_*constants
getEditingState
public abstract TextInputState getEditingState()getCaretRect
public abstract int[] getCaretRect(){x, y, width, height}, used by the
platform to anchor the IME candidate window and the selection loupe near the rendered caret.getConfig
public abstract TextInputConfig getConfig()inputFocusGained
public abstract void inputFocusGained()inputFocusLost
public abstract void inputFocusLost()getTextLength
public abstract int getTextLength()getTextRange
public abstract String getTextRange(int start, int end)[start, end).rectForOffset
public abstract int[] rectForOffset(int offset){x, y, w, h}.offsetAtPoint
public abstract int offsetAtPoint(int x, int y)selectionRects
public abstract int[] selectionRects(int start, int end)[start, end) as a flat array of absolute-pixel
rectangles {x, y, w, h, x, y, w, h, ...} (one entry per visual line the range spans).replaceRange
public abstract void replaceRange(int start, int end, String text)[start, end) with text (a direct, range based edit from the platform).setSelectionRange
public abstract void setSelectionRange(int start, int end)[start, end) (a caret when equal).