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

Commit aace9a8f authored by Annie Lin's avatar Annie Lin Committed by Android (Google) Code Review
Browse files

Merge "Allow setting open/close/change animations for ActivityEmbedding (AE)...

Merge "Allow setting open/close/change animations for ActivityEmbedding (AE) from SplitAttributes behind a flag." into main
parents 8cdc4aca 78464d48
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public final class TaskFragmentAnimationParams implements Parcelable {
     */
    public boolean hasOverrideAnimation() {
        return mOpenAnimationResId != DEFAULT_ANIMATION_RESOURCES_ID
                || mChangeAnimationResId != DEFAULT_ANIMATION_BACKGROUND_COLOR
                || mChangeAnimationResId != DEFAULT_ANIMATION_RESOURCES_ID
                || mCloseAnimationResId != DEFAULT_ANIMATION_RESOURCES_ID;
    }

+18 −5
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;

import java.util.Map;
import java.util.concurrent.Executor;
@@ -393,19 +394,31 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
        if (splitAttributes == null) {
            return TaskFragmentAnimationParams.DEFAULT;
        }
        final TaskFragmentAnimationParams.Builder builder =
                new TaskFragmentAnimationParams.Builder();
        final int animationBackgroundColor = getAnimationBackgroundColor(splitAttributes);
        TaskFragmentAnimationParams.Builder builder = new TaskFragmentAnimationParams.Builder();
        if (animationBackgroundColor != DEFAULT_ANIMATION_BACKGROUND_COLOR) {
        builder.setAnimationBackgroundColor(animationBackgroundColor);
        if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
            final int openAnimationResId =
                    splitAttributes.getAnimationParams().getOpenAnimationResId();
            builder.setOpenAnimationResId(openAnimationResId);
            final int closeAnimationResId =
                    splitAttributes.getAnimationParams().getCloseAnimationResId();
            builder.setCloseAnimationResId(closeAnimationResId);
            final int changeAnimationResId =
                    splitAttributes.getAnimationParams().getChangeAnimationResId();
            builder.setChangeAnimationResId(changeAnimationResId);
        }
        // TODO(b/293658614): Allow setting custom open/close/changeAnimationResId.
        return builder.build();
    }

    @ColorInt
    private static int getAnimationBackgroundColor(@NonNull SplitAttributes splitAttributes) {
        int animationBackgroundColor = DEFAULT_ANIMATION_BACKGROUND_COLOR;
        final AnimationBackground animationBackground = splitAttributes.getAnimationBackground();
        AnimationBackground animationBackground = splitAttributes.getAnimationBackground();
        if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
            animationBackground = splitAttributes.getAnimationParams().getAnimationBackground();
        }
        if (animationBackground instanceof AnimationBackground.ColorBackground colorBackground) {
            animationBackgroundColor = colorBackground.getColor();
        }
+9 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.WindowManager;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.window.extensions.embedding.AnimationBackground;
import androidx.window.extensions.embedding.AnimationParams;
import androidx.window.extensions.embedding.SplitAttributes;

import org.junit.Before;
@@ -112,5 +113,13 @@ public class WindowExtensionsTest {
                .isEqualTo(new SplitAttributes.SplitType.RatioSplitType(0.5f));
        assertThat(splitAttributes.getAnimationBackground())
                .isEqualTo(AnimationBackground.ANIMATION_BACKGROUND_DEFAULT);
        assertThat(splitAttributes.getAnimationParams().getAnimationBackground())
                .isEqualTo(AnimationBackground.ANIMATION_BACKGROUND_DEFAULT);
        assertThat(splitAttributes.getAnimationParams().getOpenAnimationResId())
                .isEqualTo(AnimationParams.DEFAULT_ANIMATION_RESOURCES_ID);
        assertThat(splitAttributes.getAnimationParams().getCloseAnimationResId())
                .isEqualTo(AnimationParams.DEFAULT_ANIMATION_RESOURCES_ID);
        assertThat(splitAttributes.getAnimationParams().getChangeAnimationResId())
                .isEqualTo(AnimationParams.DEFAULT_ANIMATION_RESOURCES_ID);
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -266,6 +266,9 @@ class ActivityEmbeddingAnimationRunner {
            final Animation animation =
                    animationProvider.get(info, change, openingWholeScreenBounds);
            if (shouldUseJumpCutForAnimation(animation)) {
                if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
                    return new ArrayList<>();
                }
                continue;
            }
            final ActivityEmbeddingAnimationAdapter adapter = createOpenCloseAnimationAdapter(
@@ -291,6 +294,9 @@ class ActivityEmbeddingAnimationRunner {
            final Animation animation =
                    animationProvider.get(info, change, closingWholeScreenBounds);
            if (shouldUseJumpCutForAnimation(animation)) {
                if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
                    return new ArrayList<>();
                }
                continue;
            }
            final ActivityEmbeddingAnimationAdapter adapter = createOpenCloseAnimationAdapter(
+15 −9
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ class ActivityEmbeddingAnimationSpec {
    Animation createChangeBoundsOpenAnimation(@NonNull TransitionInfo info,
            @NonNull TransitionInfo.Change change, @NonNull Rect parentBounds) {
        if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
            final Animation customAnimation = loadCustomAnimation(info, change);
            final Animation customAnimation = loadCustomAnimation(info, change, TRANSIT_CHANGE);
            if (customAnimation != null) {
                return customAnimation;
            }
@@ -131,7 +131,7 @@ class ActivityEmbeddingAnimationSpec {
    Animation createChangeBoundsCloseAnimation(@NonNull TransitionInfo info,
            @NonNull TransitionInfo.Change change, @NonNull Rect parentBounds) {
        if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
            final Animation customAnimation = loadCustomAnimation(info, change);
            final Animation customAnimation = loadCustomAnimation(info, change, TRANSIT_CHANGE);
            if (customAnimation != null) {
                return customAnimation;
            }
@@ -172,7 +172,7 @@ class ActivityEmbeddingAnimationSpec {
            // TODO(b/293658614): Support more complicated animations that may need more than a noop
            // animation as the start leash.
            final Animation noopAnimation = createNoopAnimation(change);
            final Animation customAnimation = loadCustomAnimation(info, change);
            final Animation customAnimation = loadCustomAnimation(info, change, TRANSIT_CHANGE);
            if (customAnimation != null) {
                return new Animation[]{noopAnimation, customAnimation};
            }
@@ -227,7 +227,7 @@ class ActivityEmbeddingAnimationSpec {
    Animation loadOpenAnimation(@NonNull TransitionInfo info,
            @NonNull TransitionInfo.Change change, @NonNull Rect wholeAnimationBounds) {
        final boolean isEnter = TransitionUtil.isOpeningType(change.getMode());
        final Animation customAnimation = loadCustomAnimation(info, change);
        final Animation customAnimation = loadCustomAnimation(info, change, change.getMode());
        final Animation animation;
        if (customAnimation != null) {
            animation = customAnimation;
@@ -254,7 +254,7 @@ class ActivityEmbeddingAnimationSpec {
    Animation loadCloseAnimation(@NonNull TransitionInfo info,
            @NonNull TransitionInfo.Change change, @NonNull Rect wholeAnimationBounds) {
        final boolean isEnter = TransitionUtil.isOpeningType(change.getMode());
        final Animation customAnimation = loadCustomAnimation(info, change);
        final Animation customAnimation = loadCustomAnimation(info, change, change.getMode());
        final Animation animation;
        if (customAnimation != null) {
            animation = customAnimation;
@@ -287,14 +287,14 @@ class ActivityEmbeddingAnimationSpec {

    @Nullable
    private Animation loadCustomAnimation(@NonNull TransitionInfo info,
            @NonNull TransitionInfo.Change change) {
            @NonNull TransitionInfo.Change change, @WindowManager.TransitionType int mode) {
        final TransitionInfo.AnimationOptions options;
        if (Flags.moveAnimationOptionsToChange()) {
            options = change.getAnimationOptions();
        } else {
            options = info.getAnimationOptions();
        }
        return loadCustomAnimationFromOptions(options, change.getMode());
        return loadCustomAnimationFromOptions(options, mode);
    }

    @Nullable
@@ -319,8 +319,14 @@ class ActivityEmbeddingAnimationSpec {
            return null;
        }

        final Animation anim = mTransitionAnimation.loadAnimationRes(options.getPackageName(),
                resId);
        final Animation anim;
        if (Flags.activityEmbeddingAnimationCustomizationFlag()) {
            // TODO(b/293658614): Consider allowing custom animations from non-default packages.
            // Enforce limiting to animations from the default "android" package for now.
            anim = mTransitionAnimation.loadDefaultAnimationRes(resId);
        } else {
            anim = mTransitionAnimation.loadAnimationRes(options.getPackageName(), resId);
        }
        if (anim != null) {
            return anim;
        }