Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6671f99 authored by Robert Snoeberger's avatar Robert Snoeberger Committed by Android (Google) Code Review
Browse files

Merge "Clean up onAnimationEnd handling"

parents 56ab09fb bd774689
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
@@ -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));
            }
        }
    };
}