Merge "Fix NPE for checking for whether animators should play together" into nyc-mr1-dev

This commit is contained in:
Doris Liu
2016-06-24 17:47:43 +00:00
committed by Android (Google) Code Review
2 changed files with 5 additions and 5 deletions

View File

@@ -1064,15 +1064,15 @@ public final class AnimatorSet extends Animator {
/** /**
* @hide * @hide
* TODO: For animatorSet defined in XML, we can use a flag to indicate what the play order * TODO: For animatorSet defined in XML, we can use a flag to indicate what the play order
* if defined (i.e. sequential or together), then we can use the flag instead of calculate * if defined (i.e. sequential or together), then we can use the flag instead of calculating
* dynamically. * dynamically. Note that when AnimatorSet is empty this method returns true.
* @return whether all the animators in the set are supposed to play together * @return whether all the animators in the set are supposed to play together
*/ */
public boolean shouldPlayTogether() { public boolean shouldPlayTogether() {
updateAnimatorsDuration(); updateAnimatorsDuration();
createDependencyGraph(); createDependencyGraph();
// All the child nodes are set out to play right after the delay animation // All the child nodes are set out to play right after the delay animation
return mRootNode.mChildNodes.size() == mNodes.size() - 1; return mRootNode.mChildNodes == null || mRootNode.mChildNodes.size() == mNodes.size() - 1;
} }
@Override @Override

View File

@@ -29,7 +29,6 @@ void PropertyValuesAnimatorSet::addPropertyAnimator(PropertyValuesHolder* proper
PropertyAnimator* animator = new PropertyAnimator(propertyValuesHolder, PropertyAnimator* animator = new PropertyAnimator(propertyValuesHolder,
interpolator, startDelay, duration, repeatCount); interpolator, startDelay, duration, repeatCount);
mAnimators.emplace_back(animator); mAnimators.emplace_back(animator);
setListener(new PropertyAnimatorSetListener(this));
// Check whether any child animator is infinite after adding it them to the set. // Check whether any child animator is infinite after adding it them to the set.
if (repeatCount == -1) { if (repeatCount == -1) {
@@ -42,6 +41,7 @@ PropertyValuesAnimatorSet::PropertyValuesAnimatorSet()
setStartValue(0); setStartValue(0);
mLastFraction = 0.0f; mLastFraction = 0.0f;
setInterpolator(new LinearInterpolator()); setInterpolator(new LinearInterpolator());
setListener(new PropertyAnimatorSetListener(this));
} }
void PropertyValuesAnimatorSet::onFinished(BaseRenderNodeAnimator* animator) { void PropertyValuesAnimatorSet::onFinished(BaseRenderNodeAnimator* animator) {
@@ -115,7 +115,7 @@ void PropertyValuesAnimatorSet::init() {
std::sort(mAnimators.begin(), mAnimators.end(), [](auto& a, auto&b) { std::sort(mAnimators.begin(), mAnimators.end(), [](auto& a, auto&b) {
return a->getTotalDuration() < b->getTotalDuration(); return a->getTotalDuration() < b->getTotalDuration();
}); });
mDuration = mAnimators[mAnimators.size() - 1]->getTotalDuration(); mDuration = mAnimators.empty() ? 0 : mAnimators[mAnimators.size() - 1]->getTotalDuration();
mInitialized = true; mInitialized = true;
} }