diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java b/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java index f8655cc44d2a..52a2cecec6b1 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java @@ -3,7 +3,9 @@ package com.android.systemui.qs; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; +import android.graphics.drawable.Animatable2; import android.graphics.drawable.AnimatedVectorDrawable; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.View; @@ -44,6 +46,24 @@ public class PageIndicator extends ViewGroup { private int mPosition = -1; private boolean mAnimating; + private final Animatable2.AnimationCallback mAnimationCallback = + new Animatable2.AnimationCallback() { + + @Override + public void onAnimationEnd(Drawable drawable) { + super.onAnimationEnd(drawable); + if (DEBUG) Log.d(TAG, "onAnimationEnd - queued: " + mQueuedPositions.size()); + if (drawable instanceof AnimatedVectorDrawable) { + ((AnimatedVectorDrawable) drawable).unregisterAnimationCallback( + mAnimationCallback); + } + mAnimating = false; + if (mQueuedPositions.size() != 0) { + setPosition(mQueuedPositions.remove(0)); + } + } + }; + public PageIndicator(Context context, AttributeSet attrs) { super(context, attrs); @@ -197,10 +217,8 @@ public class PageIndicator extends ViewGroup { final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getContext().getDrawable(res); imageView.setImageDrawable(avd); avd.forceAnimationOnUI(); + avd.registerAnimationCallback(mAnimationCallback); avd.start(); - // TODO: Figure out how to user an AVD animation callback instead, which doesn't - // seem to be working right now... - postDelayed(mAnimationDone, ANIMATION_DURATION); } private int getTransition(boolean fromB, boolean isMajorAState, boolean isMajor) { @@ -264,15 +282,4 @@ public class PageIndicator extends ViewGroup { getChildAt(i).layout(left, 0, mPageIndicatorWidth + left, mPageIndicatorHeight); } } - - private final Runnable mAnimationDone = new Runnable() { - @Override - public void run() { - if (DEBUG) Log.d(TAG, "onAnimationEnd - queued: " + mQueuedPositions.size()); - mAnimating = false; - if (mQueuedPositions.size() != 0) { - setPosition(mQueuedPositions.remove(0)); - } - } - }; } |