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

Commit 04d613f2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use the correct value when starting animator after seeking" into main

parents 35016bb4 50e10b68
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1381,6 +1381,18 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
            }
            int toId = findLatestEventIdForTime(playTime);
            handleAnimationEvents(-1, toId, playTime);

            if (mSeekState.isActive()) {
                // Pump a frame to the on-going animators
                for (int i = 0; i < mPlayingSet.size(); i++) {
                    Node node = mPlayingSet.get(i);
                    if (!node.mEnded) {
                        pulseFrame(node, getPlayTimeForNodeIncludingDelay(playTime, node));
                    }
                }
            }

            // Remove all the finished anims
            for (int i = mPlayingSet.size() - 1; i >= 0; i--) {
                if (mPlayingSet.get(i).mEnded) {
                    mPlayingSet.remove(i);
+39 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;


@MediumTest
public class AnimatorSetCallsTest {
@@ -447,6 +449,43 @@ public class AnimatorSetCallsTest {
        mActivity.runOnUiThread(() -> {});
    }

    @Test
    public void startAfterSeek() throws Throwable {
        ArrayList<Float> values = new ArrayList<>();
        AtomicReference<CountDownLatch> drawLatch = new AtomicReference<>(new CountDownLatch(1));

        mActivity.runOnUiThread(() -> {
            mAnimator.setDuration(300);
            mAnimator.setInterpolator(null);
            View view = (View) mAnimator.getTarget();
            view.getViewTreeObserver().addOnDrawListener(() -> {
                values.add(view.getTranslationX());
                drawLatch.get().countDown();
            });
            mSet1.setCurrentPlayTime(150);
        });

        assertTrue(drawLatch.get().await(1, TimeUnit.SECONDS));
        drawLatch.set(new CountDownLatch(1));

        mActivity.runOnUiThread(() -> {
            assertEquals(1, values.size());
            assertEquals(50f, values.get(0), 0.01f);
            mSet1.start();
        });

        assertTrue(drawLatch.get().await(1, TimeUnit.SECONDS));

        mActivity.runOnUiThread(() -> {
            assertTrue(values.size() >= 2);
            float lastValue = values.get(0);
            for (int i = 1; i < values.size(); i++) {
                assertTrue(values.get(i) >= lastValue);
                lastValue = values.get(i);
            }
        });
    }

    private void waitForOnUiThread(PollingCheck.PollingCheckCondition condition) {
        final boolean[] value = new boolean[1];
        PollingCheck.waitFor(() -> {