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

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

Optimize Fragment operations so that minimal work is done.

Bug 29631389

When multiple operations are executed at once, they sometimes
cancel each other. For example, if the following transactions
are queued:

Transaction 1: add A
Transaction 2: replace with B

This can be trimmed down to add B.

This CL optimizes fragments in both add and pop directions.

Developers can choose not to allow optimization by
using FragmentTransaction#setAllowOptimization

Test: If6637e9f1c2a414bebaff6404efc45dd828378ad

Change-Id: Iab75be3e0aa388fc79b794e647ac6893165bebd7
parent 6b6fc563
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4668,6 +4668,7 @@ package android.app {
    method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
    method public abstract android.app.FragmentTransaction setAllowOptimization(boolean);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
    method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
+1 −0
Original line number Diff line number Diff line
@@ -4813,6 +4813,7 @@ package android.app {
    method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
    method public abstract android.app.FragmentTransaction setAllowOptimization(boolean);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
    method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
+1 −0
Original line number Diff line number Diff line
@@ -4671,6 +4671,7 @@ package android.app {
    method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
    method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
    method public abstract android.app.FragmentTransaction setAllowOptimization(boolean);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
    method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
    method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
+130 −142

File changed.

Preview size limit exceeded, changes collapsed.

+9 −0
Original line number Diff line number Diff line
@@ -481,6 +481,12 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
    // If app has requested a specific animation, this is the one to use.
    int mNextAnim;

    // If app has requested a specific transition, this is the one to use.
    int mNextTransition;

    // If app has requested a specific transition style, this is the one to use.
    int mNextTransitionStyle;

    // The parent container of the fragment after dynamically added to UI.
    ViewGroup mContainer;

@@ -510,6 +516,9 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
    SharedElementCallback mEnterTransitionCallback = SharedElementCallback.NULL_CALLBACK;
    SharedElementCallback mExitTransitionCallback = SharedElementCallback.NULL_CALLBACK;

    // True if mHidden has been changed and the animation should be scheduled.
    boolean mHiddenChanged;

    /**
     * State information that has been retrieved from a fragment instance
     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
Loading