From 853b23d1fa625436b30dfab9b6cb7293c6c328b9 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Tue, 16 Aug 2016 16:54:10 -0700 Subject: [PATCH] Fix listeners not getting called when AVD falls back on UI thread When AVD fall back on UI thread, in addition to transfer the pending actions from RT animator to UI animator, we also need to transfer the listener, if any. BUG: 30901495 Change-Id: Ib4a7ebb2996a02596bb5789704617c894a5dd474 --- .../drawable/AnimatedVectorDrawable.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index c6a45c1a677f6..c836204486b05 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -244,10 +244,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { // to UI thread animation for AVD. if (!mAnimatorSet.isRunning() && ((VectorDrawableAnimatorRT) mAnimatorSet).mPendingAnimationActions.size() > 0) { - VectorDrawableAnimatorRT oldAnim = (VectorDrawableAnimatorRT) mAnimatorSet; - mAnimatorSet = new VectorDrawableAnimatorUI(this); - mAnimatorSet.init(mAnimatorSetFromXml); - oldAnim.transferPendingActions(mAnimatorSet); + fallbackOntoUI(); } } mAnimatorSet.onDraw(canvas); @@ -490,10 +487,22 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { throw new UnsupportedOperationException("Cannot force Animated Vector Drawable to" + " run on UI thread when the animation has started on RenderThread."); } + fallbackOntoUI(); + } + } + + private void fallbackOntoUI() { + if (mAnimatorSet instanceof VectorDrawableAnimatorRT) { + VectorDrawableAnimatorRT oldAnim = (VectorDrawableAnimatorRT) mAnimatorSet; mAnimatorSet = new VectorDrawableAnimatorUI(this); if (mAnimatorSetFromXml != null) { mAnimatorSet.init(mAnimatorSetFromXml); } + // Transfer the listener from RT animator to UI animator + if (oldAnim.mListener != null) { + mAnimatorSet.setListener(oldAnim.mListener); + } + oldAnim.transferPendingActions(mAnimatorSet); } }