ListenerSet
@UnstableApi
class ListenerSet<T : Any?>
A set of listeners.
Events are guaranteed to arrive in the order in which they happened even if a new event is triggered recursively from another listener.
Events are also guaranteed to be only sent to the listeners registered at the time the event was enqueued and haven't been removed since.
All methods must be called on the thread passed to the constructor unless indicated otherwise.
| Parameters | |
|---|---|
<T : Any?> |
The listener type. |
Summary
Nested types |
|---|
interface ListenerSet.Event<T>An event sent to a listener. |
interface ListenerSet.IterationFinishedEvent<T>An event sent to a listener when all other events sent during one |
Public constructors |
|---|
ListenerSet(looper: Looper!)Creates a new listener set. |
ListenerSet(thread: Thread!)Creates a new listener set. |
ListenerSet(Creates a new listener set. |
Public functions |
|
|---|---|
Unit |
add(listener: T!)Adds a listener to the set. |
Unit |
clear()Removes all listeners from the set. |
ListenerSet<T!>! |
Copies the listener set. |
ListenerSet<T!>! |
Copies the listener set. |
ListenerSet<T!>! |
copy(Copies the listener set. |
ListenerSet<T!>! |
copy(Copies the listener set. |
Unit |
Notifies listeners of events previously enqueued with |
Unit |
queueEvent(event: ListenerSet.Event<T!>!)Adds an event that is sent to the listeners when |
Unit |
queueEvent(eventFlag: Int, event: ListenerSet.Event<T!>!)Adds an event that is sent to the listeners when |
Unit |
release()Releases the set of listeners immediately. |
Unit |
remove(listener: T!)Removes a listener from the set. |
Unit |
sendEvent(event: ListenerSet.Event<T!>!)
|
Unit |
sendEvent(eventFlag: Int, event: ListenerSet.Event<T!>!)
|
Unit |
This function is deprecated. Do not use this method and ensure all calls are made from the correct thread. |
Int |
size()Returns the number of added listeners. |
Public constructors
ListenerSet
ListenerSet(looper: Looper!)
Creates a new listener set.
This listener set will not send an IterationFinishedEvent when all other events sent during one Looper message queue iteration were handled by the listeners.
ListenerSet
ListenerSet(thread: Thread!)
Creates a new listener set.
This listener set will not send an IterationFinishedEvent.
ListenerSet
ListenerSet(
looper: Looper!,
clock: Clock!,
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>?
)
Creates a new listener set.
| Parameters | |
|---|---|
looper: Looper! |
A |
clock: Clock! |
A |
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>? |
An |
Public functions
add
fun add(listener: T!): Unit
Adds a listener to the set.
If a listener is already present, it will not be added again.
This method can be called from any thread.
| Parameters | |
|---|---|
listener: T! |
The listener to be added. |
copy
fun copy(clock: Clock!): ListenerSet<T!>!
Copies the listener set.
This method can be called from any thread.
| Returns | |
|---|---|
ListenerSet<T!>! |
The copied listener set. |
copy
fun copy(looper: Looper!): ListenerSet<T!>!
Copies the listener set.
This method can be called from any thread.
| Returns | |
|---|---|
ListenerSet<T!>! |
The copied listener set. |
copy
fun copy(
looper: Looper!,
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>?
): ListenerSet<T!>!
Copies the listener set.
This method can be called from any thread.
| Parameters | |
|---|---|
looper: Looper! |
The new |
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>? |
The new |
| Returns | |
|---|---|
ListenerSet<T!>! |
The copied listener set. |
copy
fun copy(
looper: Looper!,
clock: Clock?,
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>?
): ListenerSet<T!>!
Copies the listener set.
This method can be called from any thread.
| Parameters | |
|---|---|
looper: Looper! |
The new |
clock: Clock? |
The new |
iterationFinishedEvent: ListenerSet.IterationFinishedEvent<T!>? |
The new |
| Returns | |
|---|---|
ListenerSet<T!>! |
The copied listener set. |
flushEvents
fun flushEvents(): Unit
Notifies listeners of events previously enqueued with queueEvent.
queueEvent
fun queueEvent(event: ListenerSet.Event<T!>!): Unit
Adds an event that is sent to the listeners when flushEvents is called.
This call does not set an integer flag for this event to be reported in the IterationFinishedEvent. Use queueEvent instead if this is required.
| Parameters | |
|---|---|
event: ListenerSet.Event<T!>! |
The event. |
queueEvent
fun queueEvent(eventFlag: Int, event: ListenerSet.Event<T!>!): Unit
Adds an event that is sent to the listeners when flushEvents is called.
| Parameters | |
|---|---|
eventFlag: Int |
An integer indicating the type of the event to be reported in the |
event: ListenerSet.Event<T!>! |
The event. |
release
fun release(): Unit
Releases the set of listeners immediately.
This will ensure no events are sent to any listener after this method has been called.
remove
fun remove(listener: T!): Unit
Removes a listener from the set.
If the listener is not present, nothing happens.
| Parameters | |
|---|---|
listener: T! |
The listener to be removed. |
sendEvent
fun sendEvent(event: ListenerSet.Event<T!>!): Unit
Queues a single event and immediately flushes the event queue to notify all listeners.
This call does not set an integer flag for this event to be reported in the IterationFinishedEvent. Use sendEvent instead if this is required.
| Parameters | |
|---|---|
event: ListenerSet.Event<T!>! |
The event. |
sendEvent
fun sendEvent(eventFlag: Int, event: ListenerSet.Event<T!>!): Unit
Queues a single event and immediately flushes the event queue to notify all listeners.
| Parameters | |
|---|---|
eventFlag: Int |
An integer flag indicating the type of the event to be reported in the |
event: ListenerSet.Event<T!>! |
The event. |
setThrowsWhenUsingWrongThread
funsetThrowsWhenUsingWrongThread(throwsWhenUsingWrongThread: Boolean): Unit
Sets whether methods throw when using the wrong thread.
Do not use this method unless to support legacy use cases.
| Parameters | |
|---|---|
throwsWhenUsingWrongThread: Boolean |
Whether to throw when using the wrong thread. |