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

Commit c03da0e7 authored by George Mount's avatar George Mount
Browse files

Make Fragment Transitions match Acitivty Transitions API

Bug 17188255

Change-Id: I506a097be4010d7156caf465c95295c58612c16e
parent 8fd81249
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -612,12 +612,20 @@ package android {
    field public static final int format12Hour = 16843722; // 0x10103ca
    field public static final int format24Hour = 16843723; // 0x10103cb
    field public static final int fragment = 16843491; // 0x10102e3
    field public static final int fragmentAllowEnterTransitionOverlap = 16843977; // 0x10104c9
    field public static final int fragmentAllowReturnTransitionOverlap = 16843978; // 0x10104ca
    field public static final int fragmentCloseEnterAnimation = 16843495; // 0x10102e7
    field public static final int fragmentCloseExitAnimation = 16843496; // 0x10102e8
    field public static final int fragmentEnterTransition = 16843972; // 0x10104c4
    field public static final int fragmentExitTransition = 16843971; // 0x10104c3
    field public static final int fragmentFadeEnterAnimation = 16843497; // 0x10102e9
    field public static final int fragmentFadeExitAnimation = 16843498; // 0x10102ea
    field public static final int fragmentOpenEnterAnimation = 16843493; // 0x10102e5
    field public static final int fragmentOpenExitAnimation = 16843494; // 0x10102e6
    field public static final int fragmentReenterTransition = 16843976; // 0x10104c8
    field public static final int fragmentReturnTransition = 16843974; // 0x10104c6
    field public static final int fragmentSharedElementEnterTransition = 16843973; // 0x10104c5
    field public static final int fragmentSharedElementReturnTransition = 16843975; // 0x10104c7
    field public static final int freezesText = 16843116; // 0x101016c
    field public static final int fromAlpha = 16843210; // 0x10101ca
    field public static final int fromDegrees = 16843187; // 0x10101b3
@@ -1418,7 +1426,7 @@ package android {
    field public static final int windowActionBarOverlay = 16843492; // 0x10102e4
    field public static final int windowActionModeOverlay = 16843485; // 0x10102dd
    field public static final int windowAllowEnterTransitionOverlap = 16843836; // 0x101043c
    field public static final int windowAllowExitTransitionOverlap = 16843835; // 0x101043b
    field public static final int windowAllowReturnTransitionOverlap = 16843835; // 0x101043b
    field public static final int windowAnimationStyle = 16842926; // 0x10100ae
    field public static final int windowBackground = 16842836; // 0x1010054
    field public static final int windowClipToOutline = 16843948; // 0x10104ac
@@ -4245,14 +4253,22 @@ package android.app {
    method public void dump(java.lang.String, java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
    method public final boolean equals(java.lang.Object);
    method public final android.app.Activity getActivity();
    method public boolean getAllowEnterTransitionOverlap();
    method public boolean getAllowReturnTransitionOverlap();
    method public final android.os.Bundle getArguments();
    method public final android.app.FragmentManager getChildFragmentManager();
    method public android.transition.Transition getEnterTransition();
    method public android.transition.Transition getExitTransition();
    method public final android.app.FragmentManager getFragmentManager();
    method public final int getId();
    method public android.app.LoaderManager getLoaderManager();
    method public final android.app.Fragment getParentFragment();
    method public android.transition.Transition getReenterTransition();
    method public final android.content.res.Resources getResources();
    method public final boolean getRetainInstance();
    method public android.transition.Transition getReturnTransition();
    method public android.transition.Transition getSharedElementEnterTransition();
    method public android.transition.Transition getSharedElementReturnTransition();
    method public final java.lang.String getString(int);
    method public final java.lang.String getString(int, java.lang.Object...);
    method public final java.lang.String getTag();
@@ -4301,11 +4317,21 @@ package android.app {
    method public void onViewCreated(android.view.View, android.os.Bundle);
    method public void onViewStateRestored(android.os.Bundle);
    method public void registerForContextMenu(android.view.View);
    method public void setAllowEnterTransitionOverlap(boolean);
    method public void setAllowReturnTransitionOverlap(boolean);
    method public void setArguments(android.os.Bundle);
    method public void setEnterSharedElementTransitionListener(android.app.SharedElementListener);
    method public void setEnterTransition(android.transition.Transition);
    method public void setExitSharedElementTransitionListener(android.app.SharedElementListener);
    method public void setExitTransition(android.transition.Transition);
    method public void setHasOptionsMenu(boolean);
    method public void setInitialSavedState(android.app.Fragment.SavedState);
    method public void setMenuVisibility(boolean);
    method public void setReenterTransition(android.transition.Transition);
    method public void setRetainInstance(boolean);
    method public void setReturnTransition(android.transition.Transition);
    method public void setSharedElementEnterTransition(android.transition.Transition);
    method public void setSharedElementReturnTransition(android.transition.Transition);
    method public void setTargetFragment(android.app.Fragment, int);
    method public void setUserVisibleHint(boolean);
    method public void startActivity(android.content.Intent);
@@ -4405,7 +4431,6 @@ package android.app {
    method public abstract android.app.FragmentTransaction setBreadCrumbTitle(java.lang.CharSequence);
    method public abstract android.app.FragmentTransaction setCustomAnimations(int, int);
    method public abstract android.app.FragmentTransaction setCustomAnimations(int, int, int, int);
    method public abstract android.app.FragmentTransaction setCustomTransition(int, int);
    method public abstract android.app.FragmentTransaction setTransition(int);
    method public abstract android.app.FragmentTransaction setTransitionStyle(int);
    method public abstract android.app.FragmentTransaction show(android.app.Fragment);
@@ -34864,7 +34889,7 @@ package android.view {
    method public abstract void closePanel(int);
    method public android.view.View findViewById(int);
    method public boolean getAllowEnterTransitionOverlap();
    method public boolean getAllowExitTransitionOverlap();
    method public boolean getAllowReturnTransitionOverlap();
    method public final android.view.WindowManager.LayoutParams getAttributes();
    method public final android.view.Window.Callback getCallback();
    method public final android.view.Window getContainer();
@@ -34913,7 +34938,7 @@ package android.view {
    method public abstract void restoreHierarchyState(android.os.Bundle);
    method public abstract android.os.Bundle saveHierarchyState();
    method public void setAllowEnterTransitionOverlap(boolean);
    method public void setAllowExitTransitionOverlap(boolean);
    method public void setAllowReturnTransitionOverlap(boolean);
    method public void setAttributes(android.view.WindowManager.LayoutParams);
    method public abstract void setBackgroundDrawable(android.graphics.drawable.Drawable);
    method public void setBackgroundDrawableResource(int);
+624 −139

File changed.

Preview size limit exceeded, changes collapsed.

+461 −122
Original line number Diff line number Diff line
@@ -23,10 +23,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.transition.TransitionSet;
import android.util.AndroidRuntimeException;
import android.util.ArrayMap;
import android.util.AttributeSet;
@@ -356,6 +360,8 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
    static final int STARTED = 4;          // Created and started, not resumed.
    static final int RESUMED = 5;          // Created started and resumed.

    private static final Transition USE_DEFAULT_TRANSITION = new TransitionSet();

    int mState = INITIALIZING;

    // Non-null if the fragment's view hierarchy is currently animating away,
@@ -480,6 +486,18 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
    boolean mLoadersStarted;
    boolean mCheckedForLoaderManager;

    private Transition mEnterTransition = null;
    private Transition mReturnTransition = USE_DEFAULT_TRANSITION;
    private Transition mExitTransition = null;
    private Transition mReenterTransition = USE_DEFAULT_TRANSITION;
    private Transition mSharedElementEnterTransition = null;
    private Transition mSharedElementReturnTransition = USE_DEFAULT_TRANSITION;
    private Boolean mAllowReturnTransitionOverlap;
    private Boolean mAllowEnterTransitionOverlap;

    SharedElementListener mEnterTransitionListener = SharedElementListener.NULL_LISTENER;
    SharedElementListener mExitTransitionListener = SharedElementListener.NULL_LISTENER;

    /**
     * State information that has been retrieved from a fragment instance
     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
@@ -1169,6 +1187,31 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
        onInflate(attrs, savedInstanceState);
        mCalled = true;

        TypedArray a = activity.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.Fragment);
        mEnterTransition = loadTransition(activity, a, mEnterTransition, null,
                com.android.internal.R.styleable.Fragment_fragmentEnterTransition);
        mReturnTransition = loadTransition(activity, a, mReturnTransition, USE_DEFAULT_TRANSITION,
                com.android.internal.R.styleable.Fragment_fragmentReturnTransition);
        mExitTransition = loadTransition(activity, a, mExitTransition, null,
                com.android.internal.R.styleable.Fragment_fragmentExitTransition);
        mReenterTransition = loadTransition(activity, a, mReenterTransition, USE_DEFAULT_TRANSITION,
                com.android.internal.R.styleable.Fragment_fragmentReenterTransition);
        mSharedElementEnterTransition = loadTransition(activity, a, mSharedElementEnterTransition,
                null, com.android.internal.R.styleable.Fragment_fragmentSharedElementEnterTransition);
        mSharedElementReturnTransition = loadTransition(activity, a, mSharedElementReturnTransition,
                USE_DEFAULT_TRANSITION,
                com.android.internal.R.styleable.Fragment_fragmentSharedElementReturnTransition);
        if (mAllowEnterTransitionOverlap == null) {
            mAllowEnterTransitionOverlap = a.getBoolean(
                    com.android.internal.R.styleable.Fragment_fragmentAllowEnterTransitionOverlap, true);
        }
        if (mAllowReturnTransitionOverlap == null) {
            mAllowReturnTransitionOverlap = a.getBoolean(
                    com.android.internal.R.styleable.Fragment_fragmentAllowReturnTransitionOverlap, true);
        }
        a.recycle();
    }

    /**
@@ -1577,6 +1620,283 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
        return false;
    }

    /**
     * When custom transitions are used with Fragments, the enter transition listener
     * is called when this Fragment is attached or detached when not popping the back stack.
     *
     * @param listener Used to manipulate the shared element transitions on this Fragment
     *                 when added not as a pop from the back stack.
     */
    public void setEnterSharedElementTransitionListener(SharedElementListener listener) {
        if (listener == null) {
            listener = SharedElementListener.NULL_LISTENER;
        }
        mEnterTransitionListener = listener;
    }

    /**
     * When custom transitions are used with Fragments, the exit transition listener
     * is called when this Fragment is attached or detached when popping the back stack.
     *
     * @param listener Used to manipulate the shared element transitions on this Fragment
     *                 when added as a pop from the back stack.
     */
    public void setExitSharedElementTransitionListener(SharedElementListener listener) {
        if (listener == null) {
            listener = SharedElementListener.NULL_LISTENER;
        }
        mExitTransitionListener = listener;
    }

    /**
     * Sets the Transition that will be used to move Views into the initial scene. The entering
     * Views will be those that are regular Views or ViewGroups that have
     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as entering is governed by changing visibility from
     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
     * entering Views will remain unaffected.
     *
     * @param transition The Transition to use to move Views into the initial Scene.
     * @attr ref android.R.styleable#Fragment_fragmentEnterTransition
     */
    public void setEnterTransition(Transition transition) {
        mEnterTransition = transition;
    }

    /**
     * Returns the Transition that will be used to move Views into the initial scene. The entering
     * Views will be those that are regular Views or ViewGroups that have
     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as entering is governed by changing visibility from
     * {@link View#INVISIBLE} to {@link View#VISIBLE}.
     *
     * @return the Transition to use to move Views into the initial Scene.
     * @attr ref android.R.styleable#Fragment_fragmentEnterTransition
     */
    public Transition getEnterTransition() {
        return mEnterTransition;
    }

    /**
     * Sets the Transition that will be used to move Views out of the scene when the Fragment is
     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
     * Views will be those that are regular Views or ViewGroups that have
     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as entering is governed by changing visibility from
     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
     * entering Views will remain unaffected. If nothing is set, the default will be to
     * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
     *
     * @param transition The Transition to use to move Views out of the Scene when the Fragment
     *                   is preparing to close.
     * @attr ref android.R.styleable#Fragment_fragmentExitTransition
     */
    public void setReturnTransition(Transition transition) {
        mReturnTransition = transition;
    }

    /**
     * Returns the Transition that will be used to move Views out of the scene when the Fragment is
     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
     * Views will be those that are regular Views or ViewGroups that have
     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as entering is governed by changing visibility from
     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
     * entering Views will remain unaffected.
     *
     * @return the Transition to use to move Views out of the Scene when the Fragment
     *         is preparing to close.
     * @attr ref android.R.styleable#Fragment_fragmentExitTransition
     */
    public Transition getReturnTransition() {
        return mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition()
                : mReturnTransition;
    }

    /**
     * Sets the Transition that will be used to move Views out of the scene when the
     * fragment is removed, hidden, or detached when not popping the back stack.
     * The exiting Views will be those that are regular Views or ViewGroups that
     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as exiting is governed by changing visibility
     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
     * remain unaffected.
     *
     * @param transition The Transition to use to move Views out of the Scene when the Fragment
     *                   is being closed not due to popping the back stack.
     * @attr ref android.R.styleable#Fragment_fragmentExitTransition
     */
    public void setExitTransition(Transition transition) {
        mExitTransition = transition;
    }

    /**
     * Returns the Transition that will be used to move Views out of the scene when the
     * fragment is removed, hidden, or detached when not popping the back stack.
     * The exiting Views will be those that are regular Views or ViewGroups that
     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
     * {@link android.transition.Visibility} as exiting is governed by changing visibility
     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
     * remain unaffected.
     *
     * @return the Transition to use to move Views out of the Scene when the Fragment
     *         is being closed not due to popping the back stack.
     * @attr ref android.R.styleable#Fragment_fragmentExitTransition
     */
    public Transition getExitTransition() {
        return mExitTransition;
    }

    /**
     * Sets the Transition that will be used to move Views in to the scene when returning due
     * to popping a back stack. The entering Views will be those that are regular Views
     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
     * will extend {@link android.transition.Visibility} as exiting is governed by changing
     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
     * the views will remain unaffected. If nothing is set, the default will be to use the same
     * transition as {@link #setExitTransition(android.transition.Transition)}.
     *
     * @param transition The Transition to use to move Views into the scene when reentering from a
     *                   previously-started Activity.
     * @attr ref android.R.styleable#Fragment_fragmentReenterTransition
     */
    public void setReenterTransition(Transition transition) {
        mReenterTransition = transition;
    }

    /**
     * Returns the Transition that will be used to move Views in to the scene when returning due
     * to popping a back stack. The entering Views will be those that are regular Views
     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
     * will extend {@link android.transition.Visibility} as exiting is governed by changing
     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
     * the views will remain unaffected. If nothing is set, the default will be to use the same
     * transition as {@link #setExitTransition(android.transition.Transition)}.
     *
     * @return the Transition to use to move Views into the scene when reentering from a
     *                   previously-started Activity.
     * @attr ref android.R.styleable#Fragment_fragmentReenterTransition
     */
    public Transition getReenterTransition() {
        return mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition()
                : mReenterTransition;
    }

    /**
     * Sets the Transition that will be used for shared elements transferred into the content
     * Scene. Typical Transitions will affect size and location, such as
     * {@link android.transition.ChangeBounds}. A null
     * value will cause transferred shared elements to blink to the final position.
     *
     * @param transition The Transition to use for shared elements transferred into the content
     *                   Scene.
     * @attr ref android.R.styleable#Fragment_fragmentSharedElementEnterTransition
     */
    public void setSharedElementEnterTransition(Transition transition) {
        mSharedElementEnterTransition = transition;
    }

    /**
     * Returns the Transition that will be used for shared elements transferred into the content
     * Scene. Typical Transitions will affect size and location, such as
     * {@link android.transition.ChangeBounds}. A null
     * value will cause transferred shared elements to blink to the final position.
     *
     * @return The Transition to use for shared elements transferred into the content
     *                   Scene.
     * @attr ref android.R.styleable#Fragment_fragmentSharedElementEnterTransition
     */
    public Transition getSharedElementEnterTransition() {
        return mSharedElementEnterTransition;
    }

    /**
     * Sets the Transition that will be used for shared elements transferred back during a
     * pop of the back stack. This Transition acts in the leaving Fragment.
     * Typical Transitions will affect size and location, such as
     * {@link android.transition.ChangeBounds}. A null
     * value will cause transferred shared elements to blink to the final position.
     * If no value is set, the default will be to use the same value as
     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
     *
     * @param transition The Transition to use for shared elements transferred out of the content
     *                   Scene.
     * @attr ref android.R.styleable#Fragment_fragmentSharedElementReturnTransition
     */
    public void setSharedElementReturnTransition(Transition transition) {
        mSharedElementReturnTransition = transition;
    }

    /**
     * Return the Transition that will be used for shared elements transferred back during a
     * pop of the back stack. This Transition acts in the leaving Fragment.
     * Typical Transitions will affect size and location, such as
     * {@link android.transition.ChangeBounds}. A null
     * value will cause transferred shared elements to blink to the final position.
     * If no value is set, the default will be to use the same value as
     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
     *
     * @return The Transition to use for shared elements transferred out of the content
     *                   Scene.
     * @attr ref android.R.styleable#Fragment_fragmentSharedElementReturnTransition
     */
    public Transition getSharedElementReturnTransition() {
        return mSharedElementReturnTransition == USE_DEFAULT_TRANSITION ?
                getSharedElementEnterTransition() : mSharedElementReturnTransition;
    }

    /**
     * Sets whether the the exit transition and enter transition overlap or not.
     * When true, the enter transition will start as soon as possible. When false, the
     * enter transition will wait until the exit transition completes before starting.
     *
     * @param allow true to start the enter transition when possible or false to
     *              wait until the exiting transition completes.
     * @attr ref android.R.styleable#Fragment_fragmentAllowEnterTransitionOverlap
     */
    public void setAllowEnterTransitionOverlap(boolean allow) {
        mAllowEnterTransitionOverlap = allow;
    }

    /**
     * Returns whether the the exit transition and enter transition overlap or not.
     * When true, the enter transition will start as soon as possible. When false, the
     * enter transition will wait until the exit transition completes before starting.
     *
     * @return true when the enter transition should start as soon as possible or false to
     * when it should wait until the exiting transition completes.
     * @attr ref android.R.styleable#Fragment_fragmentAllowEnterTransitionOverlap
     */
    public boolean getAllowEnterTransitionOverlap() {
        return (mAllowEnterTransitionOverlap == null) ? true : mAllowEnterTransitionOverlap;
    }

    /**
     * Sets whether the the return transition and reenter transition overlap or not.
     * When true, the reenter transition will start as soon as possible. When false, the
     * reenter transition will wait until the return transition completes before starting.
     *
     * @param allow true to start the reenter transition when possible or false to wait until the
     *              return transition completes.
     * @attr ref android.R.styleable#Fragment_fragmentAllowReturnTransitionOverlap
     */
    public void setAllowReturnTransitionOverlap(boolean allow) {
        mAllowReturnTransitionOverlap = allow;
    }

    /**
     * Returns whether the the return transition and reenter transition overlap or not.
     * When true, the reenter transition will start as soon as possible. When false, the
     * reenter transition will wait until the return transition completes before starting.
     *
     * @return true to start the reenter transition when possible or false to wait until the
     *         return transition completes.
     * @attr ref android.R.styleable#Fragment_fragmentAllowReturnTransitionOverlap
     */
    public boolean getAllowReturnTransitionOverlap() {
        return (mAllowReturnTransitionOverlap == null) ? true : mAllowReturnTransitionOverlap;
    }

    /**
     * Print the Fragments's state into the given stream.
     *
@@ -1929,4 +2249,23 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
                    + " did not call through to super.onDestroy()");
        }
    }

    private static Transition loadTransition(Context context, TypedArray typedArray,
            Transition currentValue, Transition defaultValue, int id) {
        if (currentValue != defaultValue) {
            return currentValue;
        }
        int transitionId = typedArray.getResourceId(id, 0);
        Transition transition = defaultValue;
        if (transitionId != 0 && transitionId != com.android.internal.R.transition.no_transition) {
            TransitionInflater inflater = TransitionInflater.from(context);
            transition = inflater.inflateTransition(transitionId);
            if (transition instanceof TransitionSet &&
                    ((TransitionSet)transition).getTransitionCount() == 0) {
                transition = null;
            }
        }
        return transition;
    }

}
+11 −2

File changed.

Preview size limit exceeded, changes collapsed.

+7 −10

File changed.

Preview size limit exceeded, changes collapsed.

Loading