public class TextKeyListener extends BaseKeyListener implements SpanWatcher
KeyListener
, this class is only concerned
with hardware keyboards. Software input methods have no obligation to trigger
the methods in this class.Modifier and Type | Class and Description |
---|---|
static class |
TextKeyListener.Capitalize |
NoCopySpan.Concrete
META_ALT_LOCKED, META_ALT_ON, META_CAP_LOCKED, META_SELECTING, META_SHIFT_ON, META_SYM_LOCKED, META_SYM_ON
Constructor and Description |
---|
TextKeyListener(TextKeyListener.Capitalize cap,
boolean autotext)
Creates a new TextKeyListener with the specified capitalization
and correction properties.
|
Modifier and Type | Method and Description |
---|---|
static void |
clear(Editable e)
Clear all the input state (autotext, autocap, multitap, undo)
from the specified Editable, going beyond Editable.clear(), which
just clears the text but not the input state.
|
int |
getInputType()
Return the type of text that this key listener is manipulating,
as per
InputType . |
static TextKeyListener |
getInstance()
Returns a new or existing instance with no automatic capitalization
or correction.
|
static TextKeyListener |
getInstance(boolean autotext,
TextKeyListener.Capitalize cap)
Returns a new or existing instance with the specified capitalization
and correction properties.
|
boolean |
onKeyDown(View view,
Editable content,
int keyCode,
KeyEvent event)
Handles presses of the meta keys.
|
boolean |
onKeyOther(View view,
Editable content,
KeyEvent event)
Base implementation handles ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting
the event's text into the content.
|
boolean |
onKeyUp(View view,
Editable content,
int keyCode,
KeyEvent event)
Handles release of the meta keys.
|
void |
onSpanAdded(Spannable s,
Object what,
int start,
int end)
This method is called to notify you that the specified object
has been attached to the specified range of the text.
|
void |
onSpanChanged(Spannable s,
Object what,
int start,
int end,
int st,
int en)
This method is called to notify you that the specified object
has been relocated from the range
ostart…oend
to the new range nstart…nend of the text. |
void |
onSpanRemoved(Spannable s,
Object what,
int start,
int end)
This method is called to notify you that the specified object
has been detached from the specified range of the text.
|
void |
release() |
static boolean |
shouldCap(TextKeyListener.Capitalize cap,
CharSequence cs,
int off)
Returns whether it makes sense to automatically capitalize at the
specified position in the specified text, with the specified rules.
|
backspace, forwardDelete
adjustMetaAfterKeypress, adjustMetaAfterKeypress, clearMetaKeyState, clearMetaKeyState, clearMetaKeyState, getMetaState, getMetaState, getMetaState, getMetaState, getMetaState, getMetaState, handleKeyDown, handleKeyUp, isMetaTracker, isSelectingMetaTracker, resetLockedMeta, resetLockedMeta, resetMetaState, startSelecting, stopSelecting
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearMetaKeyState
public TextKeyListener(TextKeyListener.Capitalize cap, boolean autotext)
cap
- when, if ever, to automatically capitalize.autotext
- whether to automatically do spelling corrections.public static TextKeyListener getInstance(boolean autotext, TextKeyListener.Capitalize cap)
cap
- when, if ever, to automatically capitalize.autotext
- whether to automatically do spelling corrections.public static TextKeyListener getInstance()
public static boolean shouldCap(TextKeyListener.Capitalize cap, CharSequence cs, int off)
cap
- the capitalization rules to consider.cs
- the text in which an insertion is being made.off
- the offset into that text where the insertion is being made.public int getInputType()
KeyListener
InputType
. This is used to
determine the mode of the soft keyboard that is shown for the editor.
If you return
InputType.TYPE_NULL
then no soft keyboard will provided. In other words, you
must be providing your own key pad for on-screen input and the key
listener will be used to handle input from a hard keyboard.
If you return any other value, a soft input method will be created when the user puts focus in the editor, which will provide a keypad and also consume hard key events. This means that the key listener will generally not be used, instead the soft input method will take care of managing key input as per the content type returned here.
getInputType
in interface KeyListener
public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event)
MetaKeyKeyListener
onKeyDown
in interface KeyListener
onKeyDown
in class BaseKeyListener
public boolean onKeyUp(View view, Editable content, int keyCode, KeyEvent event)
MetaKeyKeyListener
onKeyUp
in interface KeyListener
onKeyUp
in class MetaKeyKeyListener
public boolean onKeyOther(View view, Editable content, KeyEvent event)
BaseKeyListener
onKeyOther
in interface KeyListener
onKeyOther
in class BaseKeyListener
public static void clear(Editable e)
e
- the buffer whose text and state are to be cleared.public void onSpanAdded(Spannable s, Object what, int start, int end)
SpanWatcher
onSpanAdded
in interface SpanWatcher
public void onSpanRemoved(Spannable s, Object what, int start, int end)
SpanWatcher
onSpanRemoved
in interface SpanWatcher
public void onSpanChanged(Spannable s, Object what, int start, int end, int st, int en)
SpanWatcher
ostart…oend
to the new range nstart…nend
of the text.onSpanChanged
in interface SpanWatcher
public void release()