FullyDrawnReporter
public final class FullyDrawnReporter
Manages when to call Activity.reportFullyDrawn. Different parts of the UI may individually indicate when they are ready for interaction. Activity.reportFullyDrawn will only be called by this class when all parts are ready. At least one addReporter or reportWhenComplete must be used before Activity.reportFullyDrawn will be called by this class.
For example, to use coroutines:
val fullyDrawnReporter = componentActivity.fullyDrawnReporter
launch {
fullyDrawnReporter.reportWhenComplete {
dataLoadedMutex.lock()
dataLoadedMutex.unlock()
}
}
Or it can be manually controlled:
// On the UI thread:
fullyDrawnReporter.addReporter()
// Do the loading on worker thread:
fullyDrawnReporter.removeReporter()
Summary
Public constructors |
|---|
FullyDrawnReporter( |
Public methods |
|
|---|---|
final void |
addOnReportDrawnListener(@NonNull Function0<Unit> callback)Registers |
final void |
Adds a lock to prevent calling |
final boolean |
Returns |
final void |
removeOnReportDrawnListener(@NonNull Function0<Unit> callback)Removes a previously registered |
final void |
Removes a lock added in |
Public constructors
Public methods
addOnReportDrawnListener
public final void addOnReportDrawnListener(@NonNull Function0<Unit> callback)
Registers callback to be called when reportFullyDrawn is called by this class. If it has already been called, then callback will be called immediately.
Once callback has been called, it will be removed and removeOnReportDrawnListener does not need to be called to remove it.
addReporter
public final void addReporter()
Adds a lock to prevent calling reportFullyDrawn.
isFullyDrawnReported
public final boolean isFullyDrawnReported()
Returns true after reportFullyDrawn has been called or if backed by a ComponentActivity and ComponentActivity.reportFullyDrawn has been called.
removeOnReportDrawnListener
public final void removeOnReportDrawnListener(@NonNull Function0<Unit> callback)
Removes a previously registered callback so that it won't be called when reportFullyDrawn is called by this class.
removeReporter
public final void removeReporter()
Removes a lock added in addReporter. When all locks have been removed, reportFullyDrawn will be called on the next animation frame.