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

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

Merge "Origin transitions with spring animations" into main

parents 1f58bf79 92771f84
Loading
Loading
Loading
Loading
+35 −19
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
    private final boolean mIsEntry;
    private final UIComponent mOrigin;
    private final TransitionPlayer mPlayer;
    private final long mDuration;
    private final Handler mHandler;

    @Nullable private SurfaceControl.Transaction mStartTransaction;
@@ -74,13 +73,11 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
            boolean isEntry,
            UIComponent origin,
            TransitionPlayer player,
            long duration,
            Handler handler) {
        mContext = context;
        mIsEntry = isEntry;
        mOrigin = origin;
        mPlayer = player;
        mDuration = duration;
        mHandler = handler;
    }

@@ -143,23 +140,25 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
            finishAnimation(/* finished= */ false);
            return;
        }
        // Initialized anim controller and configure for player
        mAnimationController = new TransitionAnimationController(mHandler, this);

        // Notify player that we are starting.
        mPlayer.onStart(info, states, mStartTransaction, mOrigin, mOriginTransaction);
        mPlayer.onStart(mAnimationController,
                info,
                states,
                mStartTransaction,
                mOrigin,
                mOriginTransaction);

        // Apply the initial transactions in case the player forgot to apply them.
        mOriginTransaction.commit();
        mStartTransaction.apply();

        // configure/start animation controller
        mAnimationController = new TransitionAnimationController(mHandler, this);
        mAnimationController.addValueAnimation(
                TAG + (mIsEntry ? "-entryAnimator" : "-exitAnimator"),
                TransitionAnimationController.LINEAR_INTERPOLATOR,
                mDuration,
                0,
                0f,
                1f);
        mAnimationController.startAnimations();
        // start animators which were configured in onStart
        if (!mAnimationController.startAnimations()) {
            finishAnimation(/* finished= */ false);
        }
    }

    /**
@@ -169,8 +168,15 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
     */
    @Override
    public void onAnimationFinished(String animatorId, boolean canceled) {
        Log.d(TAG, "onAnimationFinished: " + animatorId + " canceled: " + canceled);
        maybeFinishAnimation(canceled);
    }

    private void maybeFinishAnimation(boolean canceled) {
        if (!mAnimationController.checkAnimationsRunning()) {
            finishAnimation(/* finished= */ !canceled);
        }
    }

    /**
     * @param animatorId   specific ID associated with a given animator, used to disambiguate.
@@ -180,7 +186,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
     */
    @Override
    public void onAnimationProgressUpdate(String animatorId, float progress, boolean isFirstFrame) {
        mPlayer.onProgress(progress);
        mPlayer.onProgress(animatorId, progress);
    }

    private boolean prepareUIs(TransitionInfo info) {
@@ -442,7 +448,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
                /* visible= */ true,
                /* bounds= */ maxBounds,
                /* baseBounds= */ maxBounds,
                /* enableBackgroundDimming= */ false);
                /* enableBackgroundDimming= */ isOpening);
    }

    private static void applyWindowAnimationStates(
@@ -530,6 +536,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
         * expected to apply the {@link WindowAnimationState} before continuing the transition.
         */
        default void onStart(
                TransitionAnimationController animationController,
                TransitionInfo transitionInfo,
                @Nullable WindowAnimationState[] states,
                SurfaceControl.Transaction sfTransaction,
@@ -550,21 +557,30 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
            applyWindowAnimationStates(transitionInfo, states, closingApp, openingApp);

            // Start.
            onStart(transactions, origin, closingApp, openingApp);
            onStart(animationController, transactions, origin, closingApp, openingApp);
        }

        /**
         * Called when an origin transition starts. This method exposes the opening and closing
         * windows as wrapped {@link UIComponent} to provide simplified interface to clients.
         *
         * Animators associated with the transition/animation should be configured using the
         * TransitionAnimationController provided. Note that animators (easing or spring) are added
         * e controller via {@link TransitionAnimationController#addValueAnimation(String,
         * BaseInterpolator, long, long)} and
         * {@link TransitionAnimationController#addSpringAnimation(String, float, float)}
         * respectively.
         */
        void onStart(
                TransitionAnimationController animationController,
                UIComponent.Transaction transaction,
                UIComponent origin,
                UIComponent closingApp,
                UIComponent openingApp);


        /** Called to update the transition frame. */
        void onProgress(float progress);
        void onProgress(String animatorId, float progress);

        /** Called when the transition ended. */
        void onEnd(boolean finished);
+2 −4
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ public class OriginTransitionSession {

        /** Add an origin entry transition to the builder. */
        public Builder withEntryTransition(
                UIComponent entryOrigin, TransitionPlayer entryPlayer, long entryDuration) {
                UIComponent entryOrigin, TransitionPlayer entryPlayer) {
            mEntryTransitionSupplier =
                    () ->
                            new OriginRemoteTransition(
@@ -319,7 +319,6 @@ public class OriginTransitionSession {
                                    /* isEntry= */ true,
                                    entryOrigin,
                                    entryPlayer,
                                    entryDuration,
                                    mHandler);
            return this;
        }
@@ -332,7 +331,7 @@ public class OriginTransitionSession {

        /** Add an origin exit transition to the builder. */
        public Builder withExitTransition(
                UIComponent exitTarget, TransitionPlayer exitPlayer, long exitDuration) {
                UIComponent exitTarget, TransitionPlayer exitPlayer) {
            mExitTransitionSupplier =
                    () ->
                            new OriginRemoteTransition(
@@ -340,7 +339,6 @@ public class OriginTransitionSession {
                                    /* isEntry= */ false,
                                    exitTarget,
                                    exitPlayer,
                                    exitDuration,
                                    mHandler);
            return this;
        }
+7 −2
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public class TransitionAnimationController {
                                mIsFirstFrame = false;
                            }
                        } catch (Exception e) {
                            Log.e(TAG, "SpringAnimation update error:" + e);
                            Log.e(TAG, "SpringAnimation update error", e);
                        }
                    });

@@ -463,10 +463,15 @@ public class TransitionAnimationController {
    }

    /** Start all animations associated with this controller. */
    public void startAnimations() {
    public boolean startAnimations() {
        if (mAnimationRunners.isEmpty()) {
            Log.w(TAG, "Nothing to run in startAnimations()");
            return false;
        }
        for (AnimationRunner runner : mAnimationRunners.values()) {
            runner.start(mHandler);
        }
        return true;
    }

    /**