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

Commit d4e9e66e authored by Andrii Kulian's avatar Andrii Kulian Committed by Automerger Merge Worker
Browse files

Merge changes from topic "sticky_placeholders_custom_finishing_behavior" into...

Merge changes from topic "sticky_placeholders_custom_finishing_behavior" into sc-v2-dev am: d2fceab0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16178839

Change-Id: Ic06afcf70cf5f63c68b3679f04f0fa9f40058f53
parents 8f2a800d d2fceab0
Loading
Loading
Loading
Loading
+33 −2
Original line number Diff line number Diff line
@@ -73,17 +73,48 @@ class SplitContainer {
    static boolean shouldFinishPrimaryWithSecondary(@NonNull SplitRule splitRule) {
        final boolean isPlaceholderContainer = splitRule instanceof SplitPlaceholderRule;
        final boolean shouldFinishPrimaryWithSecondary = (splitRule instanceof SplitPairRule)
                && ((SplitPairRule) splitRule).shouldFinishPrimaryWithSecondary();
                && ((SplitPairRule) splitRule).getFinishPrimaryWithSecondary()
                != SplitRule.FINISH_NEVER;
        return shouldFinishPrimaryWithSecondary || isPlaceholderContainer;
    }

    static boolean shouldFinishSecondaryWithPrimary(@NonNull SplitRule splitRule) {
        final boolean isPlaceholderContainer = splitRule instanceof SplitPlaceholderRule;
        final boolean shouldFinishSecondaryWithPrimary = (splitRule instanceof SplitPairRule)
                && ((SplitPairRule) splitRule).shouldFinishSecondaryWithPrimary();
                && ((SplitPairRule) splitRule).getFinishSecondaryWithPrimary()
                != SplitRule.FINISH_NEVER;
        return shouldFinishSecondaryWithPrimary || isPlaceholderContainer;
    }

    static boolean shouldFinishAssociatedContainerWhenStacked(int finishBehavior) {
        return finishBehavior == SplitRule.FINISH_ALWAYS;
    }

    static boolean shouldFinishAssociatedContainerWhenAdjacent(int finishBehavior) {
        return finishBehavior == SplitRule.FINISH_ALWAYS
                || finishBehavior == SplitRule.FINISH_ADJACENT;
    }

    static int getFinishPrimaryWithSecondaryBehavior(@NonNull SplitRule splitRule) {
        if (splitRule instanceof SplitPlaceholderRule) {
            return ((SplitPlaceholderRule) splitRule).getFinishPrimaryWithSecondary();
        }
        if (splitRule instanceof SplitPairRule) {
            return ((SplitPairRule) splitRule).getFinishPrimaryWithSecondary();
        }
        return SplitRule.FINISH_NEVER;
    }

    static int getFinishSecondaryWithPrimaryBehavior(@NonNull SplitRule splitRule) {
        if (splitRule instanceof SplitPlaceholderRule) {
            return SplitRule.FINISH_ALWAYS;
        }
        if (splitRule instanceof SplitPairRule) {
            return ((SplitPairRule) splitRule).getFinishSecondaryWithPrimary();
        }
        return SplitRule.FINISH_NEVER;
    }

    static boolean isStickyPlaceholderRule(@NonNull SplitRule splitRule) {
        if (!(splitRule instanceof SplitPlaceholderRule)) {
            return false;
+18 −8
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

package androidx.window.extensions.embedding;

import static androidx.window.extensions.embedding.SplitContainer.getFinishPrimaryWithSecondaryBehavior;
import static androidx.window.extensions.embedding.SplitContainer.getFinishSecondaryWithPrimaryBehavior;
import static androidx.window.extensions.embedding.SplitContainer.isStickyPlaceholderRule;
import static androidx.window.extensions.embedding.SplitContainer.shouldFinishAssociatedContainerWhenAdjacent;
import static androidx.window.extensions.embedding.SplitContainer.shouldFinishAssociatedContainerWhenStacked;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -665,15 +669,21 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
            // Containers are not in the same split, no need to retain.
            return false;
        }

        if (!isStickyPlaceholderRule(splitContainer.getSplitRule())) {
            // Currently only the containers associated with sticky placeholders can be retained.
            return false;
        // Find the finish behavior for the associated container
        int finishBehavior;
        SplitRule splitRule = splitContainer.getSplitRule();
        if (finishingContainer == splitContainer.getPrimaryContainer()) {
            finishBehavior = getFinishSecondaryWithPrimaryBehavior(splitRule);
        } else {
            finishBehavior = getFinishPrimaryWithSecondaryBehavior(splitRule);
        }
        // Decide whether the associated container should be retained based on the current
        // presentation mode.
        if (mPresenter.shouldShowSideBySide(splitContainer)) {
            return !shouldFinishAssociatedContainerWhenAdjacent(finishBehavior);
        } else {
            return !shouldFinishAssociatedContainerWhenStacked(finishBehavior);
        }

        // When sticky placeholder is stacked on top of the main container it should not cause the
        // destruction of the primary one.
        return !mPresenter.shouldShowSideBySide(splitContainer);
    }

    /**