Stay organized with collections
Save and categorize content based on your preferences.
DispatcherState
open class DispatcherState
Use with KeyEvent.dispatch(Callback, DispatcherState, Object)
for more advanced key dispatching, such as long presses.
Summary
Public methods |
open Unit |
Handle key up event to stop tracking.
|
open Boolean |
Return true if the key event is for a key code that is currently being tracked by the dispatcher.
|
open Unit |
Keep track of the given event's key code as having performed an action with a long press, so no action should occur on the up.
|
open Unit |
Reset back to initial state.
|
open Unit |
Stop any tracking associated with this target.
|
open Unit |
Start tracking the key code associated with the given event.
|
Public constructors
DispatcherState
DispatcherState()
Public methods
handleUpEvent
open fun handleUpEvent(event: KeyEvent!): Unit
Handle key up event to stop tracking. This resets the dispatcher state, and updates the key event state based on it.
This is only needed if you are directly dispatching events, rather than handling them in Callback.onKeyUp
.
isTracking
open fun isTracking(event: KeyEvent!): Boolean
Return true if the key event is for a key code that is currently being tracked by the dispatcher.
open fun performedLongPress(event: KeyEvent!): Unit
Keep track of the given event's key code as having performed an action with a long press, so no action should occur on the up.
This is only needed if you are directly dispatching events, rather than handling them in Callback.onKeyLongPress
.
reset
open fun reset(): Unit
Reset back to initial state.
reset
open fun reset(target: Any!): Unit
Stop any tracking associated with this target.
startTracking
open fun startTracking(
event: KeyEvent!,
target: Any!
): Unit
Start tracking the key code associated with the given event. This can only be called on a key down. It will allow you to see any long press associated with the key, and will result in KeyEvent.isTracking
return true on the long press and up events.
This is only needed if you are directly dispatching events, rather than handling them in Callback.onKeyDown
.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# KeyEvent.DispatcherState\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nDispatcherState\n===============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/view/KeyEvent.DispatcherState \"View this page in Java\") \n\n```\nopen class DispatcherState\n```\n\n|---|--------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.view.KeyEvent.DispatcherState](#) |\n\nUse with [KeyEvent.dispatch(Callback, DispatcherState, Object)](/reference/kotlin/android/view/KeyEvent#dispatch(android.view.KeyEvent.Callback,%20android.view.KeyEvent.DispatcherState,%20kotlin.Any)) for more advanced key dispatching, such as long presses.\n\nSummary\n-------\n\n| Public constructors ||\n|--------------------------------------------------|---|\n| [DispatcherState](#DispatcherState())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [handleUpEvent](#handleUpEvent(android.view.KeyEvent))`(`event:` `[KeyEvent](/reference/kotlin/android/view/KeyEvent)!`)` Handle key up event to stop tracking. |\n| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isTracking](#isTracking(android.view.KeyEvent))`(`event:` `[KeyEvent](/reference/kotlin/android/view/KeyEvent)!`)` Return true if the key event is for a key code that is currently being tracked by the dispatcher. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [performedLongPress](#performedLongPress(android.view.KeyEvent))`(`event:` `[KeyEvent](/reference/kotlin/android/view/KeyEvent)!`)` Keep track of the given event's key code as having performed an action with a long press, so no action should occur on the up. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [reset](#reset())`()` Reset back to initial state. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [reset](#reset(kotlin.Any))`(`target:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Stop any tracking associated with this target. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [startTracking](#startTracking(android.view.KeyEvent,%20kotlin.Any))`(`event:` `[KeyEvent](/reference/kotlin/android/view/KeyEvent)!`, `target:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Start tracking the key code associated with the given event. |\n\nPublic constructors\n-------------------\n\n### DispatcherState\n\n```\nDispatcherState()\n```\n\nPublic methods\n--------------\n\n### handleUpEvent\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun handleUpEvent(event: KeyEvent!): Unit\n```\n\nHandle key up event to stop tracking. This resets the dispatcher state, and updates the key event state based on it.\n\nThis is only needed if you are directly dispatching events, rather than handling them in [Callback.onKeyUp](/reference/kotlin/android/view/KeyEvent.Callback#onKeyUp(kotlin.Int,%20android.view.KeyEvent)). \n\n### isTracking\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun isTracking(event: KeyEvent!): Boolean\n```\n\nReturn true if the key event is for a key code that is currently being tracked by the dispatcher. \n\n### performedLongPress\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun performedLongPress(event: KeyEvent!): Unit\n```\n\nKeep track of the given event's key code as having performed an action with a long press, so no action should occur on the up.\n\nThis is only needed if you are directly dispatching events, rather than handling them in [Callback.onKeyLongPress](/reference/kotlin/android/view/KeyEvent.Callback#onKeyLongPress(kotlin.Int,%20android.view.KeyEvent)). \n\n### reset\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun reset(): Unit\n```\n\nReset back to initial state. \n\n### reset\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun reset(target: Any!): Unit\n```\n\nStop any tracking associated with this target. \n\n### startTracking\n\nAdded in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun startTracking(\n event: KeyEvent!, \n target: Any!\n): Unit\n```\n\nStart tracking the key code associated with the given event. This can only be called on a key down. It will allow you to see any long press associated with the key, and will result in [KeyEvent.isTracking](/reference/kotlin/android/view/KeyEvent#isTracking()) return true on the long press and up events.\n\nThis is only needed if you are directly dispatching events, rather than handling them in [Callback.onKeyDown](/reference/kotlin/android/view/KeyEvent.Callback#onKeyDown(kotlin.Int,%20android.view.KeyEvent))."]]