java.lang.Object | |
↳ | android.text.method.MetaKeyKeyListener |
Known Direct Subclasses |
Known Indirect Subclasses |
This base class encapsulates the behavior for tracking the state of meta keys such as SHIFT, ALT and SYM as well as the pseudo-meta state of selecting text.
Key listeners that care about meta state should inherit from this class; you should not instantiate this class directly in a client.
This class provides two mechanisms for tracking meta state that can be used together or independently.
handleKeyDown(long, int, KeyEvent)
and
getMetaState(long)
operate on a meta key state bit mask.onKeyDown(View, Editable, int, KeyEvent)
and
getMetaState(CharSequence, int)
operate on meta key state flags stored
as spans in an Editable
text buffer. The spans only describe the current
meta key state of the text editor; they do not carry any positional information.
The behavior of this class varies according to the keyboard capabilities
described by the KeyCharacterMap
of the keyboard device such as
the key modifier behavior
.
MetaKeyKeyListener
implements chorded and toggled key modifiers.
When key modifiers are toggled into a latched or locked state, the state
of the modifier is stored in the Editable
text buffer or in a
meta state integer managed by the client. These latched or locked modifiers
should be considered to be held in addition to those that the
keyboard already reported as being pressed in getMetaState()
.
In other words, the MetaKeyKeyListener
augments the meta state
provided by the keyboard; it does not replace it. This distinction is important
to ensure that meta keys not handled by MetaKeyKeyListener
such as
KEYCODE_CAPS_LOCK
or KEYCODE_NUM_LOCK
are
taken into consideration.
To ensure correct meta key behavior, the following pattern should be used when mapping key codes to characters:
private char getUnicodeChar(TextKeyListener listener, KeyEvent event, Editable textBuffer) {
// Use the combined meta states from the event and the key listener.
int metaState = event.getMetaState() | listener.getMetaState(textBuffer);
return event.getUnicodeChar(metaState);
}
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | META_ALT_LOCKED | Flag that indicates that the ALT key is locked. | |||||||||
int | META_ALT_ON | Flag that indicates that the ALT key is on. | |||||||||
int | META_CAP_LOCKED | Flag that indicates that the SHIFT key is locked in CAPS mode. | |||||||||
int | META_SHIFT_ON | Flag that indicates that the SHIFT key is on. | |||||||||
int | META_SYM_LOCKED | Flag that indicates that the SYM key is locked. | |||||||||
int | META_SYM_ON | Flag that indicates that the SYM key is on. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Call this method after you handle a keypress so that the meta
state will be reset to unshifted (if it is not still down)
or primed to be reset to unshifted (once it is released).
| |||||||||||
Call this method after you handle a keypress so that the meta
state will be reset to unshifted (if it is not still down)
or primed to be reset to unshifted (once it is released).
| |||||||||||
Clears the state of the specified meta key if it is locked.
| |||||||||||
Gets the state of the meta keys.
| |||||||||||
Gets the state of a particular meta key.
| |||||||||||
Gets the state of the meta keys.
| |||||||||||
Gets the state of a particular meta key.
| |||||||||||
Handles presses of the meta keys.
| |||||||||||
Handles release of the meta keys.
| |||||||||||
Returns true if this object is one that this class would use to
keep track of any meta state in the specified text.
| |||||||||||
Returns true if this object is one that this class would use to
keep track of the selecting meta state in the specified text.
| |||||||||||
Handles presses of the meta keys.
| |||||||||||
Handles release of the meta keys.
| |||||||||||
Call this if you are a method that ignores the locked meta state
(arrow keys, for example) and you handle a key.
| |||||||||||
Resets all meta state to inactive.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Call this if you are a method that ignores the locked meta state
(arrow keys, for example) and you handle a key.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Flag that indicates that the ALT key is locked.
Flag that indicates that the ALT key is on.
Value equals META_ALT_ON
.
Flag that indicates that the SHIFT key is locked in CAPS mode.
Flag that indicates that the SHIFT key is on.
Value equals META_SHIFT_ON
.
Flag that indicates that the SYM key is locked.
Flag that indicates that the SYM key is on.
Value equals META_SYM_ON
.
Call this method after you handle a keypress so that the meta state will be reset to unshifted (if it is not still down) or primed to be reset to unshifted (once it is released). Takes the current state, returns the new state.
Call this method after you handle a keypress so that the meta state will be reset to unshifted (if it is not still down) or primed to be reset to unshifted (once it is released).
Clears the state of the specified meta key if it is locked.
state | the meta key state |
---|---|
which | meta keys to clear, may be a combination of META_SHIFT_ON ,
META_ALT_ON or META_SYM_ON .
|
Gets the state of the meta keys.
text | the buffer in which the meta key would have been pressed. |
---|
Gets the state of a particular meta key.
state | the current state bits. |
---|---|
meta | META_SHIFT_ON, META_ALT_ON, or META_SYM_ON |
Gets the state of the meta keys.
state | the current meta state bits. |
---|
Gets the state of a particular meta key.
text | the buffer in which the meta key would have been pressed. |
---|---|
meta | META_SHIFT_ON, META_ALT_ON, META_SYM_ON, or META_SELECTING |
Handles presses of the meta keys.
Handles release of the meta keys.
Returns true if this object is one that this class would use to keep track of any meta state in the specified text.
Returns true if this object is one that this class would use to keep track of the selecting meta state in the specified text.
Handles presses of the meta keys.
Handles release of the meta keys.
Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.
Resets all meta state to inactive.
Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.