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

Commit 83360dbd authored by Todd Lee's avatar Todd Lee
Browse files

Refactor transition utility methods to utility class

Bug: b/391862078
Test: presubmits
Flag: NONE exempt refactor
Change-Id: Ibb50bd4cdc99bd3d9c0ebd013865c6c47bf56d56
parent 39d38ede
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -126,6 +126,46 @@ public class TransitionUtil {
                        || change.getLastParent().equals(change.getParent()));
    }

    /**
     * Check if all changes in this transition are only ordering changes. If so, we won't animate.
     */
    public static boolean isAllOrderOnly(TransitionInfo info) {
        for (int i = info.getChanges().size() - 1; i >= 0; --i) {
            if (!isOrderOnly(info.getChanges().get(i))) return false;
        }
        return true;
    }

    /**
     * Look through a transition and see if all non-closing changes are no-animation. If so, no
     * animation should play.
     */
    public static boolean isAllNoAnimation(TransitionInfo info) {
        if (isClosingType(info.getType())) {
            // no-animation is only relevant for launching (open) activities.
            return false;
        }
        boolean hasNoAnimation = false;
        final int changeSize = info.getChanges().size();
        for (int i = changeSize - 1; i >= 0; --i) {
            final TransitionInfo.Change change = info.getChanges().get(i);
            if (isClosingType(change.getMode())) {
                // ignore closing apps since they are a side-effect of the transition and don't
                // animate.
                continue;
            }
            if (change.hasFlags(TransitionInfo.FLAG_NO_ANIMATION)) {
                hasNoAnimation = true;
            } else if (!isOrderOnly(change) && !change.hasFlags(TransitionInfo.FLAG_IS_OCCLUDED)) {
                // Ignore the order only or occluded changes since they shouldn't be visible during
                // animation. For anything else, we need to animate if at-least one relevant
                // participant *is* animated,
                return false;
            }
        }
        return hasNoAnimation;
    }

    /**
     * Filter that selects leaf-tasks only. THIS IS ORDER-DEPENDENT! For it to work properly, you
     * MUST call `test` in the same order that the changes appear in the TransitionInfo.
+1 −1
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
        }

        // Early check if the transition doesn't warrant an animation.
        if (Transitions.isAllNoAnimation(info) || Transitions.isAllOrderOnly(info)
        if (TransitionUtil.isAllNoAnimation(info) || TransitionUtil.isAllOrderOnly(info)
                || (info.getFlags() & WindowManager.TRANSIT_FLAG_INVISIBLE) != 0) {
            startTransaction.apply();
            finishTransaction.apply();
+0 −40
Original line number Diff line number Diff line
@@ -672,46 +672,6 @@ public class Transitions implements RemoteCallable<Transitions>,
        return -1;
    }

    /**
     * Look through a transition and see if all non-closing changes are no-animation. If so, no
     * animation should play.
     */
    static boolean isAllNoAnimation(TransitionInfo info) {
        if (isClosingType(info.getType())) {
            // no-animation is only relevant for launching (open) activities.
            return false;
        }
        boolean hasNoAnimation = false;
        final int changeSize = info.getChanges().size();
        for (int i = changeSize - 1; i >= 0; --i) {
            final TransitionInfo.Change change = info.getChanges().get(i);
            if (isClosingType(change.getMode())) {
                // ignore closing apps since they are a side-effect of the transition and don't
                // animate.
                continue;
            }
            if (change.hasFlags(FLAG_NO_ANIMATION)) {
                hasNoAnimation = true;
            } else if (!TransitionUtil.isOrderOnly(change) && !change.hasFlags(FLAG_IS_OCCLUDED)) {
                // Ignore the order only or occluded changes since they shouldn't be visible during
                // animation. For anything else, we need to animate if at-least one relevant
                // participant *is* animated,
                return false;
            }
        }
        return hasNoAnimation;
    }

    /**
     * Check if all changes in this transition are only ordering changes. If so, we won't animate.
     */
    static boolean isAllOrderOnly(TransitionInfo info) {
        for (int i = info.getChanges().size() - 1; i >= 0; --i) {
            if (!TransitionUtil.isOrderOnly(info.getChanges().get(i))) return false;
        }
        return true;
    }

    private Track getOrCreateTrack(int trackId) {
        while (trackId >= mTracks.size()) {
            mTracks.add(new Track());