Added in API level 1

MetaKeyKeyListener


abstract class MetaKeyKeyListener
kotlin.Any
   ↳ android.text.method.MetaKeyKeyListener

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.

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 KeyEvent.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 KeyEvent.KEYCODE_CAPS_LOCK or KeyEvent.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); }

Summary

Constants
static Int

Flag that indicates that the ALT key is locked.

static Int

Flag that indicates that the ALT key is on.

static Int

Flag that indicates that the SHIFT key is locked in CAPS mode.

static Int

Flag that indicates that the SHIFT key is on.

static Int

Flag that indicates that the SYM key is locked.

static Int

Flag that indicates that the SYM key is on.

Public constructors

Public methods
open static Unit

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).

open static Long

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).

open Unit
clearMetaKeyState(view: View!, content: Editable!, states: Int)

open Long
clearMetaKeyState(state: Long, which: Int)

Clears the state of the specified meta key if it is locked.

open static Unit
clearMetaKeyState(content: Editable!, states: Int)

static Int

Gets the state of the meta keys.

static Int

Gets the state of the meta keys for a specific key event.

static Int
getMetaState(text: CharSequence!, meta: Int)

Gets the state of a particular meta key.

static Int
getMetaState(text: CharSequence!, meta: Int, event: KeyEvent!)

Gets the state of a particular meta key to use with a particular key event.

static Int

Gets the state of the meta keys.

static Int
getMetaState(state: Long, meta: Int)

Gets the state of a particular meta key.

open static Long
handleKeyDown(state: Long, keyCode: Int, event: KeyEvent!)

Handles presses of the meta keys.

open static Long
handleKeyUp(state: Long, keyCode: Int, event: KeyEvent!)

Handles release of the meta keys.

open static Boolean
isMetaTracker(text: CharSequence!, what: Any!)

Returns true if this object is one that this class would use to keep track of any meta state in the specified text.

open static Boolean

Returns true if this object is one that this class would use to keep track of the selecting meta state in the specified text.

open Boolean
onKeyDown(view: View!, content: Editable!, keyCode: Int, event: KeyEvent!)

Handles presses of the meta keys.

open Boolean
onKeyUp(view: View!, content: Editable!, keyCode: Int, event: KeyEvent!)

Handles release of the meta keys.

open static Long

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.

open static Unit

Resets all meta state to inactive.

Protected methods
open static Unit

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.

Constants

META_ALT_LOCKED

Added in API level 1
static val META_ALT_LOCKED: Int

Flag that indicates that the ALT key is locked.

Value: 512

META_ALT_ON

Added in API level 1
static val META_ALT_ON: Int

Flag that indicates that the ALT key is on. Value equals KeyEvent.META_ALT_ON.

Value: 2

META_CAP_LOCKED

Added in API level 1
static val META_CAP_LOCKED: Int

Flag that indicates that the SHIFT key is locked in CAPS mode.

Value: 256

META_SHIFT_ON

Added in API level 1
static val META_SHIFT_ON: Int

Flag that indicates that the SHIFT key is on. Value equals KeyEvent.META_SHIFT_ON.

Value: 1

META_SYM_LOCKED

Added in API level 1
static val META_SYM_LOCKED: Int

Flag that indicates that the SYM key is locked.

Value: 1024

META_SYM_ON

Added in API level 1
static val META_SYM_ON: Int

Flag that indicates that the SYM key is on. Value equals KeyEvent.META_SYM_ON.

Value: 4

Public constructors

MetaKeyKeyListener

MetaKeyKeyListener()

Public methods

adjustMetaAfterKeypress

Added in API level 1
open static fun adjustMetaAfterKeypress(content: Spannable!): Unit

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).

adjustMetaAfterKeypress

Added in API level 3
open static fun adjustMetaAfterKeypress(state: Long): Long

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.

clearMetaKeyState

Added in API level 3
open fun clearMetaKeyState(
    view: View!,
    content: Editable!,
    states: Int
): Unit

clearMetaKeyState

Added in API level 3
open fun clearMetaKeyState(
    state: Long,
    which: Int
): Long

Clears the state of the specified meta key if it is locked.

Parameters
state Long: the meta key state
which Int: meta keys to clear, may be a combination of META_SHIFT_ON, META_ALT_ON or META_SYM_ON.

clearMetaKeyState

Added in API level 3
open static fun clearMetaKeyState(
    content: Editable!,
    states: Int
): Unit

getMetaState

Added in API level 1
static fun getMetaState(text: CharSequence!): Int

Gets the state of the meta keys.

Parameters
text CharSequence!: the buffer in which the meta key would have been pressed.
Return
Int an integer in which each bit set to one represents a pressed or locked meta key.

getMetaState

Added in API level 19
static fun getMetaState(
    text: CharSequence!,
    event: KeyEvent!
): Int

Gets the state of the meta keys for a specific key event. For input devices that use toggled key modifiers, the `toggled' state is stored into the text buffer. This method retrieves the meta state for this event, accounting for the stored state. If the event has been created by a device that does not support toggled key modifiers, like a virtual device for example, the stored state is ignored.

Parameters
text CharSequence!: the buffer in which the meta key would have been pressed.
event KeyEvent!: the event for which to evaluate the meta state.
Return
Int an integer in which each bit set to one represents a pressed or locked meta key.

getMetaState

Added in API level 1
static fun getMetaState(
    text: CharSequence!,
    meta: Int
): Int

Gets the state of a particular meta key.

Parameters
meta Int: META_SHIFT_ON, META_ALT_ON, META_SYM_ON
text CharSequence!: the buffer in which the meta key would have been pressed.
Return
Int 0 if inactive, 1 if active, 2 if locked.

getMetaState

Added in API level 19
static fun getMetaState(
    text: CharSequence!,
    meta: Int,
    event: KeyEvent!
): Int

Gets the state of a particular meta key to use with a particular key event. If the key event has been created by a device that does not support toggled key modifiers, like a virtual keyboard for example, only the meta state in the key event is considered.

Parameters
meta Int: META_SHIFT_ON, META_ALT_ON, META_SYM_ON
text CharSequence!: the buffer in which the meta key would have been pressed.
event KeyEvent!: the event for which to evaluate the meta state.
Return
Int 0 if inactive, 1 if active, 2 if locked.

getMetaState

Added in API level 3
static fun getMetaState(state: Long): Int

Gets the state of the meta keys.

Parameters
state Long: the current meta state bits.
Return
Int an integer in which each bit set to one represents a pressed or locked meta key.

getMetaState

Added in API level 3
static fun getMetaState(
    state: Long,
    meta: Int
): Int

Gets the state of a particular meta key.

Parameters
state Long: the current state bits.
meta Int: META_SHIFT_ON, META_ALT_ON, or META_SYM_ON
Return
Int 0 if inactive, 1 if active, 2 if locked.

handleKeyDown

Added in API level 3
open static fun handleKeyDown(
    state: Long,
    keyCode: Int,
    event: KeyEvent!
): Long

Handles presses of the meta keys.

handleKeyUp

Added in API level 3
open static fun handleKeyUp(
    state: Long,
    keyCode: Int,
    event: KeyEvent!
): Long

Handles release of the meta keys.

isMetaTracker

Added in API level 1
open static fun isMetaTracker(
    text: CharSequence!,
    what: Any!
): Boolean

Returns true if this object is one that this class would use to keep track of any meta state in the specified text.

isSelectingMetaTracker

Added in API level 3
open static fun isSelectingMetaTracker(
    text: CharSequence!,
    what: Any!
): Boolean

Returns true if this object is one that this class would use to keep track of the selecting meta state in the specified text.

onKeyDown

Added in API level 1
open fun onKeyDown(
    view: View!,
    content: Editable!,
    keyCode: Int,
    event: KeyEvent!
): Boolean

Handles presses of the meta keys.

onKeyUp

Added in API level 1
open fun onKeyUp(
    view: View!,
    content: Editable!,
    keyCode: Int,
    event: KeyEvent!
): Boolean

Handles release of the meta keys.

resetLockedMeta

Added in API level 3
open static fun resetLockedMeta(state: Long): Long

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.

resetMetaState

Added in API level 1
open static fun resetMetaState(text: Spannable!): Unit

Resets all meta state to inactive.

Protected methods

resetLockedMeta

Added in API level 1
protected open static fun resetLockedMeta(content: Spannable!): Unit

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.