Choreographer
class Choreographer
kotlin.Any | |
↳ | android.view.Choreographer |
Coordinates the timing of animations, input and drawing.
The choreographer receives timing pulses (such as vertical synchronization) from the display subsystem then schedules work to occur as part of rendering the next display frame.
Applications typically interact with the choreographer indirectly using higher level abstractions in the animation framework or the view hierarchy. Here are some examples of things you can do using the higher-level APIs.
- To post an animation to be processed on a regular time basis synchronized with display frame rendering, use
android.animation.ValueAnimator#start
. - To post a
Runnable
to be invoked once at the beginning of the next display frame, useView#postOnAnimation
. - To post a
Runnable
to be invoked once at the beginning of the next display frame after a delay, useView#postOnAnimationDelayed
. - To post a call to
View#invalidate()
to occur once at the beginning of the next display frame, useView#postInvalidateOnAnimation()
orView#postInvalidateOnAnimation(int, int, int, int)
. - To ensure that the contents of a
View
scroll smoothly and are drawn in sync with display frame rendering, do nothing. This already happens automatically.View#onDraw
will be called at the appropriate time.
However, there are a few cases where you might want to use the functions of the choreographer directly in your application. Here are some examples.
- If your application does its rendering in a different thread, possibly using GL, or does not use the animation framework or view hierarchy at all and you want to ensure that it is appropriately synchronized with the display, then use
Choreographer#postFrameCallback
. - ... and that's about it.
Each Looper
thread has its own choreographer. Other threads can post callbacks to run on the choreographer but they will run on the Looper
to which the choreographer belongs.
Summary
Nested classes | |
---|---|
abstract |
Implement this interface to receive a callback when a new display frame is being rendered. |
The payload for |
|
Holds data that describes one possible VSync frame event to render at. |
|
abstract |
Implement this interface to receive a callback to start the next frame. |
Public methods | |
---|---|
static Choreographer! |
Gets the choreographer for the calling thread. |
Unit |
postFrameCallback(callback: Choreographer.FrameCallback!) Posts a frame callback to run on the next frame. |
Unit |
postFrameCallbackDelayed(callback: Choreographer.FrameCallback!, delayMillis: Long) Posts a frame callback to run on the next frame after the specified delay. |
Unit |
postVsyncCallback(callback: Choreographer.VsyncCallback) Posts a vsync callback to run on the next frame. |
Unit |
removeFrameCallback(callback: Choreographer.FrameCallback!) Removes a previously posted frame callback. |
Unit |
removeVsyncCallback(callback: Choreographer.VsyncCallback?) Removes a previously posted vsync callback. |
Public methods
getInstance
static fun getInstance(): Choreographer!
Gets the choreographer for the calling thread. Must be called from a thread that already has a android.os.Looper
associated with it.
Return | |
---|---|
Choreographer! |
The choreographer for this thread. |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the thread does not have a looper. |
postFrameCallback
fun postFrameCallback(callback: Choreographer.FrameCallback!): Unit
Posts a frame callback to run on the next frame.
The callback runs once then is automatically removed.
Parameters | |
---|---|
callback |
Choreographer.FrameCallback!: The frame callback to run during the next frame. |
postFrameCallbackDelayed
fun postFrameCallbackDelayed(
callback: Choreographer.FrameCallback!,
delayMillis: Long
): Unit
Posts a frame callback to run on the next frame after the specified delay.
The callback runs once then is automatically removed.
Parameters | |
---|---|
callback |
Choreographer.FrameCallback!: The frame callback to run during the next frame. |
delayMillis |
Long: The delay time in milliseconds. |
See Also
postVsyncCallback
fun postVsyncCallback(callback: Choreographer.VsyncCallback): Unit
Posts a vsync callback to run on the next frame.
The callback runs once then is automatically removed.
Parameters | |
---|---|
callback |
Choreographer.VsyncCallback: The vsync callback to run during the next frame. This value cannot be null . |
See Also
removeFrameCallback
fun removeFrameCallback(callback: Choreographer.FrameCallback!): Unit
Removes a previously posted frame callback.
Parameters | |
---|---|
callback |
Choreographer.FrameCallback!: The frame callback to remove. |
removeVsyncCallback
fun removeVsyncCallback(callback: Choreographer.VsyncCallback?): Unit
Removes a previously posted vsync callback.
Parameters | |
---|---|
callback |
Choreographer.VsyncCallback?: The vsync callback to remove. This value may be null . |
See Also