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

Commit 08dfb0b0 authored by Todd Lee's avatar Todd Lee
Browse files

Migrate Wear transition animation controller to platform anim lib

This provides a direct drop in replacement for the current value
animator used in origin remote transitions, but also adds support
for the use of spring animations as an alternate form of control.

Bug: b/409008756
Flag: NONE exempt pure refactor
Test: atest PlatformAnimationLibCoreTests
      atest ClockworkSystemUiRoboTests
      atest WearSdkRoboTests
Change-Id: Ic6e86a1e3d1cb8ad342c9f33ba284bf04af0e067
parent c383a48c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@ package {
java_library {
    name: "PlatformAnimationLib-server",
    srcs: [
        "src/com/android/systemui/animation/server/*.java",
        ":PlatformAnimationLib-aidl",
        "src/com/android/systemui/animation/server/*.java",
    ],
    static_libs: [
        "WindowManager-Shell-shared",
@@ -39,8 +39,8 @@ java_library {
java_library {
    name: "PlatformAnimationLib-core",
    srcs: [
        "src/com/android/systemui/animation/*.java",
        ":PlatformAnimationLib-aidl",
        "src/com/android/systemui/animation/*.java",
    ],
    static_libs: [
        "WindowManager-Shell-shared",
@@ -50,13 +50,14 @@ java_library {
filegroup {
    name: "PlatformAnimationLib-client-srcs",
    srcs: [
        ":PlatformAnimationLib-aidl",
        "src/com/android/systemui/animation/OriginRemoteTransition.java",
        "src/com/android/systemui/animation/OriginTransitionSession.java",
        "src/com/android/systemui/animation/SurfaceUIComponent.java",
        "src/com/android/systemui/animation/Transactions.java",
        "src/com/android/systemui/animation/TransitionAnimationController.java",
        "src/com/android/systemui/animation/UIComponent.java",
        "src/com/android/systemui/animation/ViewUIComponent.java",
        ":PlatformAnimationLib-aidl",
    ],
}

+42 −39
Original line number Diff line number Diff line
@@ -18,9 +18,6 @@ package com.android.systemui.animation;

import static android.view.WindowManager.TRANSIT_CHANGE;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Rect;
@@ -51,7 +48,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 *
 * @hide
 */
public class OriginRemoteTransition extends IRemoteTransition.Stub {
public class OriginRemoteTransition extends IRemoteTransition.Stub implements
        TransitionAnimationController.AnimationRunnerListener {
    private static final String TAG = "OriginRemoteTransition";
    private static final long FINISH_ANIMATION_TIMEOUT_MS = 100;

@@ -65,9 +63,8 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
    @Nullable private SurfaceControl.Transaction mStartTransaction;
    @Nullable private IRemoteTransitionFinishedCallback mFinishCallback;
    @Nullable private UIComponent.Transaction mOriginTransaction;
    @Nullable private ValueAnimator mAnimator;
    @Nullable private TransitionAnimationController mAnimationController;
    @Nullable private SurfaceControl mOriginLeash;
    private boolean mCancelled;

    OriginRemoteTransition(
            Context context,
@@ -146,32 +143,37 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
        mOriginTransaction.commit();
        mStartTransaction.apply();

        // Start the animator.
        mAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
        mAnimator.setDuration(mDuration);
        mAnimator.addListener(
                new AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator a) {}

                    @Override
                    public void onAnimationEnd(Animator a) {
                        finishAnimation(/* finished= */ !mCancelled);
        // configure/start animation controller
        mAnimationController = new TransitionAnimationController(mHandler, this);
        mAnimationController.addValueAnimation(
                TAG + (mIsEntry ? "-entryAnimator" : "-exitAnimator"),
                TransitionAnimationController.LINEAR_INTERPOLATOR,
                mDuration,
                0,
                0f,
                1f);
        mAnimationController.startAnimations();
    }

    /**
     * @param animatorId specific ID associated with a given animator, used to disambiguate.
     * @param canceled   whether or not the animation was canceled (terminated) or ran to
     *                   completion.
     */
    @Override
                    public void onAnimationCancel(Animator a) {
                        mCancelled = true;
    public void onAnimationFinished(String animatorId, boolean canceled) {
        finishAnimation(/* finished= */ !canceled);
    }

    /**
     * @param animatorId   specific ID associated with a given animator, used to disambiguate.
     * @param progress     representative value of the current state of progress, start to finish.
     * @param isFirstFrame whether or not the current update represents the drawing of the
     *                     *first* frame of the animation.
     */
    @Override
                    public void onAnimationRepeat(Animator a) {}
                });
        mAnimator.addUpdateListener(
                a -> {
                    mPlayer.onProgress((float) a.getAnimatedValue());
                });
        mAnimator.start();
    public void onAnimationProgressUpdate(String animatorId, float progress, boolean isFirstFrame) {
        mPlayer.onProgress(progress);
    }

    private boolean prepareUIs(TransitionInfo info) {
@@ -304,7 +306,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
                    mHandler.removeCallbacks(timeoutRunnable);
                    finishInternalRunnable.run();
                };
        if (mAnimator == null) {
        if (mAnimationController == null) {
            // The transition didn't start. Ensure we apply the start transaction and report
            // finish afterwards.
            mStartTransaction
@@ -314,7 +316,8 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
            mHandler.postDelayed(timeoutRunnable, FINISH_ANIMATION_TIMEOUT_MS);
            return;
        }
        mAnimator = null;
        mAnimationController = null;

        // Notify client that we have ended.
        mPlayer.onEnd(finished);
        // Detach the origin from the transition leash and report finish after it's done.
@@ -346,8 +349,8 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
        logD("cancel()");
        mHandler.post(
          () -> {
                    if (mAnimator != null) {
                        mAnimator.cancel();
              if (mAnimationController != null) {
                  mAnimationController.cancelAnimations();
              }
          });
    }
+492 −0

File added.

Preview size limit exceeded, changes collapsed.