IT. Expert System.

Android Reference

Choreographer


android.view

Class Choreographer



  • public final class Choreographer
    extends Object
    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.

    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 postFrameCallback(android.view.Choreographer.FrameCallback).
    • ... 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.

    • Field Detail

      • CALLBACK_INPUT

        public static final int CALLBACK_INPUT
        Callback type: Input callback. Runs first.
        See Also:
        Constant Field Values
      • CALLBACK_ANIMATION

        public static final int CALLBACK_ANIMATION
        Callback type: Animation callback. Runs before traversals.
        See Also:
        Constant Field Values
      • CALLBACK_TRAVERSAL

        public static final int CALLBACK_TRAVERSAL
        Callback type: Traversal callback. Handles layout and draw. Runs last after all other asynchronous messages have been handled.
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static Choreographer getInstance()
        Gets the choreographer for the calling thread. Must be called from a thread that already has a Looper associated with it.
        Returns:
        The choreographer for this thread.
        Throws:
        IllegalStateException - if the thread does not have a looper.
      • getFrameDelay

        public static long getFrameDelay()
        The amount of time, in milliseconds, between each frame of the animation.

        This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop.

        The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations.

        Returns:
        the requested time between frames, in milliseconds
      • setFrameDelay

        public static void setFrameDelay(long frameDelay)
        The amount of time, in milliseconds, between each frame of the animation.

        This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop.

        The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations.

        Parameters:
        frameDelay - the requested time between frames, in milliseconds
      • subtractFrameDelay

        public static long subtractFrameDelay(long delayMillis)
        Subtracts typical frame delay time from a delay interval in milliseconds.

        This method can be used to compensate for animation delay times that have baked in assumptions about the frame delay. For example, it's quite common for code to assume a 60Hz frame time and bake in a 16ms delay. When we call #postAnimationCallbackDelayed we want to know how long to wait before posting the animation callback but let the animation timer take care of the remaining frame delay time.

        This method is somewhat conservative about how much of the frame delay it subtracts. It uses the same value returned by getFrameDelay() which by default is 10ms even though many parts of the system assume 16ms. Consequently, we might still wait 6ms before posting an animation callback that we want to run on the next frame, but this is much better than waiting a whole 16ms and likely missing the deadline.

        Parameters:
        delayMillis - The original delay time including an assumed frame delay.
        Returns:
        The adjusted delay time with the assumed frame delay subtracted out.
      • postCallback

        public void postCallback(int callbackType,
                        Runnable action,
                        Object token)
        Posts a callback to run on the next frame.

        The callback runs once then is automatically removed.

        Parameters:
        callbackType - The callback type.
        action - The callback action to run during the next frame.
        token - The callback token, or null if none.
        See Also:
        removeCallbacks(int, java.lang.Runnable, java.lang.Object)
      • postCallbackDelayed

        public void postCallbackDelayed(int callbackType,
                               Runnable action,
                               Object token,
                               long delayMillis)
        Posts a callback to run on the next frame after the specified delay.

        The callback runs once then is automatically removed.

        Parameters:
        callbackType - The callback type.
        action - The callback action to run during the next frame after the specified delay.
        token - The callback token, or null if none.
        delayMillis - The delay time in milliseconds.
        See Also:
        #removeCallback
      • getFrameTime

        public long getFrameTime()
        Gets the time when the current frame started.

        This method provides the time in nanoseconds when the frame started being rendered. The frame time provides a stable time base for synchronizing animations and drawing. It should be used instead of SystemClock.uptimeMillis() or System.nanoTime() for animations and drawing in the UI. Using the frame time helps to reduce inter-frame jitter because the frame time is fixed at the time the frame was scheduled to start, regardless of when the animations or drawing callback actually runs. All callbacks that run as part of rendering a frame will observe the same frame time so using the frame time also helps to synchronize effects that are performed by different callbacks.

        Please note that the framework already takes care to process animations and drawing using the frame time as a stable time base. Most applications should not need to use the frame time information directly.

        This method should only be called from within a callback.

        Returns:
        The frame start time, in the SystemClock.uptimeMillis() time base.
        Throws:
        IllegalStateException - if no frame is in progress.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 3526 / . Delta: 0.13601 с