FileDocCategorySizeDatePackage
RenderNodeAnimator.javaAPI DocAndroid 5.1 API17692Thu Mar 12 22:22:10 GMT 2015android.view

RenderNodeAnimator

public class RenderNodeAnimator extends android.animation.Animator
hide

Fields Summary
public static final int
TRANSLATION_X
public static final int
TRANSLATION_Y
public static final int
TRANSLATION_Z
public static final int
SCALE_X
public static final int
SCALE_Y
public static final int
ROTATION
public static final int
ROTATION_X
public static final int
ROTATION_Y
public static final int
X
public static final int
Y
public static final int
Z
public static final int
ALPHA
public static final int
LAST_VALUE
public static final int
PAINT_STROKE_WIDTH
public static final int
PAINT_ALPHA
Field for the Paint alpha channel, which should be specified as a value between 0 and 255.
private static final android.util.SparseIntArray
sViewPropertyAnimatorMap
private com.android.internal.util.VirtualRefBasePtr
mNativePtr
private RenderNode
mTarget
private View
mViewTarget
private int
mRenderProperty
private float
mFinalValue
private android.animation.TimeInterpolator
mInterpolator
private static final int
STATE_PREPARE
private static final int
STATE_DELAYED
private static final int
STATE_RUNNING
private static final int
STATE_FINISHED
private int
mState
private long
mUnscaledDuration
private long
mUnscaledStartDelay
private final boolean
mUiThreadHandlesDelay
private long
mStartDelay
private long
mStartTime
private static ThreadLocal
sAnimationHelper
Constructors Summary
public RenderNodeAnimator(int property, float finalValue)

        mRenderProperty = property;
        mFinalValue = finalValue;
        mUiThreadHandlesDelay = true;
        init(nCreateAnimator(property, finalValue));
    
public RenderNodeAnimator(android.graphics.CanvasProperty property, float finalValue)

        init(nCreateCanvasPropertyFloatAnimator(
                property.getNativeContainer(), finalValue));
        mUiThreadHandlesDelay = false;
    
public RenderNodeAnimator(android.graphics.CanvasProperty property, int paintField, float finalValue)
Creates a new render node animator for a field on a Paint property.

param
property The paint property to target
param
paintField Paint field to animate, one of {@link #PAINT_ALPHA} or {@link #PAINT_STROKE_WIDTH}
param
finalValue The target value for the property

        init(nCreateCanvasPropertyPaintAnimator(
                property.getNativeContainer(), paintField, finalValue));
        mUiThreadHandlesDelay = false;
    
public RenderNodeAnimator(int x, int y, float startRadius, float endRadius)

        init(nCreateRevealAnimator(x, y, startRadius, endRadius));
        mUiThreadHandlesDelay = true;
    
Methods Summary
private voidapplyInterpolator()

        if (mInterpolator == null) return;

        long ni;
        if (isNativeInterpolator(mInterpolator)) {
            ni = ((NativeInterpolatorFactory)mInterpolator).createNativeInterpolator();
        } else {
            long duration = nGetDuration(mNativePtr.get());
            ni = FallbackLUTInterpolator.createNativeInterpolator(mInterpolator, duration);
        }
        nSetInterpolator(mNativePtr.get(), ni);
    
private static voidcallOnFinished(android.view.RenderNodeAnimator animator)

        animator.onFinished();
    
public voidcancel()

        if (mState != STATE_PREPARE && mState != STATE_FINISHED) {
            if (mState == STATE_DELAYED) {
                getHelper().removeDelayedAnimation(this);
                moveToRunningState();
            }

            final ArrayList<AnimatorListener> listeners = cloneListeners();
            final int numListeners = listeners == null ? 0 : listeners.size();
            for (int i = 0; i < numListeners; i++) {
                listeners.get(i).onAnimationCancel(this);
            }

            end();
        }
    
private voidcheckMutable()

        if (mState != STATE_PREPARE) {
            throw new IllegalStateException("Animator has already started, cannot change it now!");
        }
        if (mNativePtr == null) {
            throw new IllegalStateException("Animator's target has been destroyed "
                    + "(trying to modify an animation after activity destroy?)");
        }
    
public android.animation.Animatorclone()

        throw new IllegalStateException("Cannot clone this animator");
    
private java.util.ArrayListcloneListeners()

        ArrayList<AnimatorListener> listeners = getListeners();
        if (listeners != null) {
            listeners = (ArrayList<AnimatorListener>) listeners.clone();
        }
        return listeners;
    
private voiddoStart()

        // Alpha is a special snowflake that has the canonical value stored
        // in mTransformationInfo instead of in RenderNode, so we need to update
        // it with the final value here.
        if (mRenderProperty == RenderNodeAnimator.ALPHA) {
            // Don't need null check because ViewPropertyAnimator's
            // ctor calls ensureTransformationInfo()
            mViewTarget.mTransformationInfo.mAlpha = mFinalValue;
        }

        moveToRunningState();

        if (mViewTarget != null) {
            // Kick off a frame to start the process
            mViewTarget.invalidateViewProperty(true, false);
        }
    
public voidend()

        if (mState != STATE_FINISHED) {
            if (mState < STATE_RUNNING) {
                getHelper().removeDelayedAnimation(this);
                doStart();
            }
            if (mNativePtr != null) {
                nEnd(mNativePtr.get());
                if (mViewTarget != null) {
                    // Kick off a frame to flush the state change
                    mViewTarget.invalidateViewProperty(true, false);
                }
            } else {
                // It's already dead, jump to onFinish
                onFinished();
            }
        }
    
public longgetDuration()

        return mUnscaledDuration;
    
private static android.view.RenderNodeAnimator$DelayedAnimationHelpergetHelper()

        DelayedAnimationHelper helper = sAnimationHelper.get();
        if (helper == null) {
            helper = new DelayedAnimationHelper();
            sAnimationHelper.set(helper);
        }
        return helper;
    
public android.animation.TimeInterpolatorgetInterpolator()

        return mInterpolator;
    
longgetNativeAnimator()

        return mNativePtr.get();
    
public longgetStartDelay()

        return mUnscaledStartDelay;
    
private voidinit(long ptr)

        mNativePtr = new VirtualRefBasePtr(ptr);
    
static booleanisNativeInterpolator(android.animation.TimeInterpolator interpolator)

        return interpolator.getClass().isAnnotationPresent(HasNativeInterpolator.class);
    
public booleanisRunning()

        return mState == STATE_DELAYED || mState == STATE_RUNNING;
    
public booleanisStarted()

        return mState != STATE_PREPARE;
    
public static intmapViewPropertyToRenderProperty(int viewProperty)


         
        return sViewPropertyAnimatorMap.get(viewProperty);
    
private voidmoveToRunningState()

        mState = STATE_RUNNING;
        if (mNativePtr != null) {
            nStart(mNativePtr.get());
        }
        notifyStartListeners();
    
private static native longnCreateAnimator(int property, float finalValue)

private static native longnCreateCanvasPropertyFloatAnimator(long canvasProperty, float finalValue)

private static native longnCreateCanvasPropertyPaintAnimator(long canvasProperty, int paintField, float finalValue)

private static native longnCreateRevealAnimator(int x, int y, float startRadius, float endRadius)

private static native voidnEnd(long animPtr)

private static native longnGetDuration(long nativePtr)

private static native voidnSetAllowRunningAsync(long animPtr, boolean mayRunAsync)

private static native voidnSetDuration(long nativePtr, long duration)

private static native voidnSetInterpolator(long animPtr, long interpolatorPtr)

private static native voidnSetListener(long animPtr, android.view.RenderNodeAnimator listener)

private static native voidnSetStartDelay(long nativePtr, long startDelay)

private static native voidnSetStartValue(long nativePtr, float startValue)

private static native voidnStart(long animPtr)

private voidnotifyStartListeners()

        final ArrayList<AnimatorListener> listeners = cloneListeners();
        final int numListeners = listeners == null ? 0 : listeners.size();
        for (int i = 0; i < numListeners; i++) {
            listeners.get(i).onAnimationStart(this);
        }
    
protected voidonFinished()

        if (mState == STATE_PREPARE) {
            // Unlikely but possible, the native side has been destroyed
            // before we have started.
            releaseNativePtr();
            return;
        }
        if (mState == STATE_DELAYED) {
            getHelper().removeDelayedAnimation(this);
            notifyStartListeners();
        }
        mState = STATE_FINISHED;

        final ArrayList<AnimatorListener> listeners = cloneListeners();
        final int numListeners = listeners == null ? 0 : listeners.size();
        for (int i = 0; i < numListeners; i++) {
            listeners.get(i).onAnimationEnd(this);
        }

        // Release the native object, as it has a global reference to us. This
        // breaks the cyclic reference chain, and allows this object to be
        // GC'd
        releaseNativePtr();
    
public voidpause()

        throw new UnsupportedOperationException();
    
private booleanprocessDelayed(long frameTimeMs)

return
true if the animator was started, false if still delayed

        if (mStartTime == 0) {
            mStartTime = frameTimeMs;
        } else if ((frameTimeMs - mStartTime) >= mStartDelay) {
            doStart();
            return true;
        }
        return false;
    
private voidreleaseNativePtr()

        if (mNativePtr != null) {
            mNativePtr.release();
            mNativePtr = null;
        }
    
public voidresume()

        throw new UnsupportedOperationException();
    
public voidsetAllowRunningAsynchronously(boolean mayRunAsync)

        checkMutable();
        nSetAllowRunningAsync(mNativePtr.get(), mayRunAsync);
    
public android.view.RenderNodeAnimatorsetDuration(long duration)

        checkMutable();
        if (duration < 0) {
            throw new IllegalArgumentException("duration must be positive; " + duration);
        }
        mUnscaledDuration = duration;
        nSetDuration(mNativePtr.get(), (long) (duration * ValueAnimator.getDurationScale()));
        return this;
    
public voidsetInterpolator(android.animation.TimeInterpolator interpolator)

        checkMutable();
        mInterpolator = interpolator;
    
public voidsetStartDelay(long startDelay)

        checkMutable();
        if (startDelay < 0) {
            throw new IllegalArgumentException("startDelay must be positive; " + startDelay);
        }
        mUnscaledStartDelay = startDelay;
        mStartDelay = (long) (ValueAnimator.getDurationScale() * startDelay);
    
public voidsetStartValue(float startValue)

        checkMutable();
        nSetStartValue(mNativePtr.get(), startValue);
    
public voidsetTarget(View view)

        mViewTarget = view;
        setTarget(mViewTarget.mRenderNode);
    
public voidsetTarget(android.graphics.Canvas canvas)

        if (!(canvas instanceof GLES20RecordingCanvas)) {
            throw new IllegalArgumentException("Not a GLES20RecordingCanvas");
        }
        final GLES20RecordingCanvas recordingCanvas = (GLES20RecordingCanvas) canvas;
        setTarget(recordingCanvas.mNode);
    
private voidsetTarget(RenderNode node)

        checkMutable();
        if (mTarget != null) {
            throw new IllegalStateException("Target already set!");
        }
        nSetListener(mNativePtr.get(), this);
        mTarget = node;
        mTarget.addAnimator(this);
    
public voidstart()

        if (mTarget == null) {
            throw new IllegalStateException("Missing target!");
        }

        if (mState != STATE_PREPARE) {
            throw new IllegalStateException("Already started!");
        }

        mState = STATE_DELAYED;
        applyInterpolator();

        if (mNativePtr == null) {
            // It's dead, immediately cancel
            cancel();
        } else if (mStartDelay <= 0 || !mUiThreadHandlesDelay) {
            nSetStartDelay(mNativePtr.get(), mStartDelay);
            doStart();
        } else {
            getHelper().addDelayedAnimation(this);
        }