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

Commit 812a806c authored by Chris Banes's avatar Chris Banes Committed by Android (Google) Code Review
Browse files

Merge "Fix ToolbarActionBar invalidating destroyed Activities"

parents bedb566a 21b25771
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,10 @@ public abstract class ActionBar {
        return false;
    }

    /** @hide */
    public void onDestroy() {
    }

    /**
     * Common implementation for requestFocus that takes in the Toolbar and moves focus
     * to the contents. This makes the ViewGroups containing the toolbar allow focus while it stays
+14 −2
Original line number Diff line number Diff line
@@ -1703,6 +1703,10 @@ public class Activity extends ContextThemeWrapper
            mSearchManager.stopSearch();
        }

        if (mActionBar != null) {
            mActionBar.onDestroy();
        }

        getApplication().dispatchActivityDestroyed(this);
    }

@@ -2208,14 +2212,22 @@ public class Activity extends ContextThemeWrapper
     * @param toolbar Toolbar to set as the Activity's action bar
     */
    public void setActionBar(@Nullable Toolbar toolbar) {
        if (getActionBar() instanceof WindowDecorActionBar) {
        final ActionBar ab = getActionBar();
        if (ab instanceof WindowDecorActionBar) {
            throw new IllegalStateException("This Activity already has an action bar supplied " +
                    "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " +
                    "android:windowActionBar to false in your theme to use a Toolbar instead.");
        }
        // Clear out the MenuInflater to make sure that it is valid for the new Action Bar

        // If we reach here then we're setting a new action bar
        // First clear out the MenuInflater to make sure that it is valid for the new Action Bar
        mMenuInflater = null;

        // If we have an action bar currently, destroy it
        if (ab != null) {
            ab.onDestroy();
        }

        ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this);
        mActionBar = tbab;
        mWindow.setCallback(tbab.getWrappedWindowCallback());
+6 −0
Original line number Diff line number Diff line
@@ -483,6 +483,12 @@ public class ToolbarActionBar extends ActionBar {
        return true;
    }

    @Override
    public void onDestroy() {
        // Remove any invalidation callbacks
        mDecorToolbar.getViewGroup().removeCallbacks(mMenuInvalidator);
    }

    public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
        mMenuVisibilityListeners.add(listener);
    }