RampAnimatorpublic final class RampAnimator extends Object A custom animator that progressively updates a property value at
a given variable rate until it reaches a particular target value. |
Fields Summary |
---|
private final T | mObject | private final android.util.IntProperty | mProperty | private final android.view.Choreographer | mChoreographer | private int | mCurrentValue | private int | mTargetValue | private int | mRate | private boolean | mAnimating | private float | mAnimatedValue | private long | mLastFrameTimeNanos | private boolean | mFirstTime | private Listener | mListener | private final Runnable | mAnimationCallback |
Constructors Summary |
---|
public RampAnimator(T object, android.util.IntProperty property)
mObject = object;
mProperty = property;
mChoreographer = Choreographer.getInstance();
|
Methods Summary |
---|
public boolean | animateTo(int target, int rate)Starts animating towards the specified value.
If this is the first time the property is being set or if the rate is 0,
the value jumps directly to the target.
// Immediately jump to the target the first time.
if (mFirstTime || rate <= 0) {
if (mFirstTime || target != mCurrentValue) {
mFirstTime = false;
mRate = 0;
mTargetValue = target;
mCurrentValue = target;
mProperty.setValue(mObject, target);
if (mAnimating) {
mAnimating = false;
cancelAnimationCallback();
}
if (mListener != null) {
mListener.onAnimationEnd();
}
return true;
}
return false;
}
// Adjust the rate based on the closest target.
// If a faster rate is specified, then use the new rate so that we converge
// more rapidly based on the new request.
// If a slower rate is specified, then use the new rate only if the current
// value is somewhere in between the new and the old target meaning that
// we will be ramping in a different direction to get there.
// Otherwise, continue at the previous rate.
if (!mAnimating
|| rate > mRate
|| (target <= mCurrentValue && mCurrentValue <= mTargetValue)
|| (mTargetValue <= mCurrentValue && mCurrentValue <= target)) {
mRate = rate;
}
final boolean changed = (mTargetValue != target);
mTargetValue = target;
// Start animating.
if (!mAnimating && target != mCurrentValue) {
mAnimating = true;
mAnimatedValue = mCurrentValue;
mLastFrameTimeNanos = System.nanoTime();
postAnimationCallback();
}
return changed;
| private void | cancelAnimationCallback()
mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);
| public boolean | isAnimating()Returns true if the animation is running.
return mAnimating;
| private void | postAnimationCallback()
mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);
| public void | setListener(com.android.server.display.RampAnimator$Listener listener)Sets a listener to watch for animation events.
mListener = listener;
|
|