package android.view;
import android.animation.TimeInterpolator;
import android.view.ViewPropertyAnimator.NameValuesHolder;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.android.internal.view.animation.FallbackLUTInterpolator;
import java.util.ArrayList;
class ViewPropertyAnimatorRT {
private static final Interpolator sLinearInterpolator = new LinearInterpolator();
private final View mView;
private RenderNodeAnimator mAnimators[] = new RenderNodeAnimator[RenderNodeAnimator.LAST_VALUE + 1];
ViewPropertyAnimatorRT(View view) {
mView = view;
}
public boolean startAnimation(ViewPropertyAnimator parent) {
cancelAnimators(parent.mPendingAnimations);
if (!canHandleAnimator(parent)) {
return false;
}
doStartAnimation(parent);
return true;
}
public void cancelAll() {
for (int i = 0; i < mAnimators.length; i++) {
if (mAnimators[i] != null) {
mAnimators[i].cancel();
mAnimators[i] = null;
}
}
}
private void doStartAnimation(ViewPropertyAnimator parent) {
int size = parent.mPendingAnimations.size();
long startDelay = parent.getStartDelay();
long duration = parent.getDuration();
TimeInterpolator interpolator = parent.getInterpolator();
if (interpolator == null) {
interpolator = sLinearInterpolator;
}
if (!RenderNodeAnimator.isNativeInterpolator(interpolator)) {
interpolator = new FallbackLUTInterpolator(interpolator, duration);
}
for (int i = 0; i < size; i++) {
NameValuesHolder holder = parent.mPendingAnimations.get(i);
int property = RenderNodeAnimator.mapViewPropertyToRenderProperty(holder.mNameConstant);
final float finalValue = holder.mFromValue + holder.mDeltaValue;
RenderNodeAnimator animator = new RenderNodeAnimator(property, finalValue);
animator.setStartDelay(startDelay);
animator.setDuration(duration);
animator.setInterpolator(interpolator);
animator.setTarget(mView);
animator.start();
mAnimators[property] = animator;
}
parent.mPendingAnimations.clear();
}
private boolean canHandleAnimator(ViewPropertyAnimator parent) {
if (parent.getUpdateListener() != null) {
return false;
}
if (parent.getListener() != null) {
return false;
}
if (!mView.isHardwareAccelerated()) {
return false;
}
if (parent.hasActions()) {
return false;
}
return true;
}
private void cancelAnimators(ArrayList<NameValuesHolder> mPendingAnimations) {
int size = mPendingAnimations.size();
for (int i = 0; i < size; i++) {
NameValuesHolder holder = mPendingAnimations.get(i);
int property = RenderNodeAnimator.mapViewPropertyToRenderProperty(holder.mNameConstant);
if (mAnimators[property] != null) {
mAnimators[property].cancel();
mAnimators[property] = null;
}
}
}
}