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

Commit 68a3f51f authored by Yi-Ling Chuang's avatar Yi-Ling Chuang Committed by Automerger Merge Worker
Browse files

Merge "Support fragment transition" into sc-dev am: eda0e624

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

Change-Id: I3b63cafffb19d3170b29f07ac12bbd4796758143
parents 7c87bdf1 eda0e624
Loading
Loading
Loading
Loading
+48 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;

import androidx.core.os.BuildCompat;
import androidx.fragment.app.Fragment;

import com.google.android.material.transition.platform.FadeThroughProvider;
import com.google.android.material.transition.platform.MaterialSharedAxis;
@@ -92,7 +93,7 @@ public class SettingsTransitionHelper {
     * triggered when the page is launched/entering.
     */
    public static void applyForwardTransition(Activity activity) {
        if (!BuildCompat.isAtLeastS()) {
        if (!isSettingsTransitionEnabled()) {
            return;
        }
        if (activity == null) {
@@ -118,7 +119,7 @@ public class SettingsTransitionHelper {
     * previously-started Activity.
     */
    public static void applyBackwardTransition(Activity activity) {
        if (!BuildCompat.isAtLeastS()) {
        if (!isSettingsTransitionEnabled()) {
            return;
        }
        if (activity == null) {
@@ -134,4 +135,49 @@ public class SettingsTransitionHelper {
        window.setReturnTransition(backward);
        window.setReenterTransition(backward);
    }

    /**
     * Apply the forward transition to the {@link Fragment}, including Exit Transition and Enter
     * Transition.
     *
     * The Exit Transition takes effect when leaving the page, while the Enter Transition is
     * triggered when the page is launched/entering.
     */
    public static void applyForwardTransition(Fragment fragment) {
        if (!isSettingsTransitionEnabled()) {
            return;
        }
        if (fragment == null) {
            Log.w(TAG, "applyForwardTransition: Invalid fragment!");
            return;
        }
        final MaterialSharedAxis forward = createSettingsSharedAxis(fragment.getContext(), true);
        fragment.setExitTransition(forward);
        fragment.setEnterTransition(forward);
    }

    /**
     * Apply the backward transition to the {@link Fragment}, including Return Transition and
     * Reenter Transition.
     *
     * Return Transition will be used to move Views out of the scene when the Window is preparing
     * to close. Reenter Transition will be used to move Views in to the scene when returning from a
     * previously-started Fragment.
     */
    public static void applyBackwardTransition(Fragment fragment) {
        if (!isSettingsTransitionEnabled()) {
            return;
        }
        if (fragment == null) {
            Log.w(TAG, "applyBackwardTransition: Invalid fragment!");
            return;
        }
        final MaterialSharedAxis backward = createSettingsSharedAxis(fragment.getContext(), false);
        fragment.setReturnTransition(backward);
        fragment.setReenterTransition(backward);
    }

    private static boolean isSettingsTransitionEnabled() {
        return BuildCompat.isAtLeastS();
    }
}