Clean up onAnimationEnd handling

Unfortunately, this doesn't fix the issue. It does help with code
health, however. This change is based on the change made to the
wallpaper picker's version of the QS PageIndicator in ag/5872070.

Bug: 152093000
Test: manual - check page indicator for both QS tiles and media controls with >3 pages.
Change-Id: I23e6b5a03ab06f167407baffb4dc77f51b58926f
This commit is contained in:
Robert Snoeberger
2020-08-07 14:17:01 -04:00
parent 97e02fa146
commit bd7746897e

View File

@@ -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));
}
}
};
}