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

Commit 8c16aa9f authored by Adam Powell's avatar Adam Powell
Browse files

Uphold common ordering expectations around action bar Home/Up dispatch

Some apps aren't particularly happy if a stray key event is dispatched
to a newly created window before its menu is prepared, causing the
action bar's Home/Up event to be dispatched. Ignore these clicks on
the Home/Up button before the menu goes through its initial prepare
step.

Note that it is still possible (and valid!) for Home/Up to be
dispatched even if the app chose to return false from
onCreateOptionsMenu or similar.

Bug 7085070

Change-Id: If4b7d5f8c5a08ce8a094f1919347604d78ddedfb
parent bbcf0852
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -125,6 +124,7 @@ public class ActionBarView extends AbsActionBarView {
    private boolean mWasHomeEnabled; // Was it enabled before action view expansion?

    private MenuBuilder mOptionsMenu;
    private boolean mMenuPrepared;
    
    private ActionBarContextView mContextView;

@@ -164,8 +164,11 @@ public class ActionBarView extends AbsActionBarView {

    private final OnClickListener mUpClickListener = new OnClickListener() {
        public void onClick(View v) {
            if (mMenuPrepared) {
                // Only invoke the window callback if the options menu has been initialized.
                mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
            }
        }
    };

    public ActionBarView(Context context, AttributeSet attrs) {
@@ -402,6 +405,10 @@ public class ActionBarView extends AbsActionBarView {
        mCallback = callback;
    }

    public void setMenuPrepared() {
        mMenuPrepared = true;
    }

    public void setMenu(Menu menu, MenuPresenter.Callback cb) {
        if (menu == mOptionsMenu) return;

+12 −3
Original line number Diff line number Diff line
@@ -380,6 +380,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            st.createdPanelView = cb.onCreatePanelView(st.featureId);
        }

        final boolean isActionBarMenu =
                (st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR);

        if (isActionBarMenu && mActionBar != null) {
            // Enforce ordering guarantees around events so that the action bar never
            // dispatches menu-related events before the panel is prepared.
            mActionBar.setMenuPrepared();
        }

        if (st.createdPanelView == null) {
            // Init the panel state's menu--return false if init failed
            if (st.menu == null || st.refreshMenuContent) {
@@ -389,7 +398,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                    }
                }

                if (mActionBar != null) {
                if (isActionBarMenu && mActionBar != null) {
                    if (mActionMenuPresenterCallback == null) {
                        mActionMenuPresenterCallback = new ActionMenuPresenterCallback();
                    }
@@ -405,7 +414,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                    // Ditch the menu created above
                    st.setMenu(null);

                    if (mActionBar != null) {
                    if (isActionBarMenu && mActionBar != null) {
                        // Don't show it in the action bar either
                        mActionBar.setMenu(null, mActionMenuPresenterCallback);
                    }
@@ -430,7 +439,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            }

            if (!cb.onPreparePanel(st.featureId, st.createdPanelView, st.menu)) {
                if (mActionBar != null) {
                if (isActionBarMenu && mActionBar != null) {
                    // The app didn't want to show the menu for now but it still exists.
                    // Clear it out of the action bar.
                    mActionBar.setMenu(null, mActionMenuPresenterCallback);