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

Commit 4b6d93fd authored by Adam Powell's avatar Adam Powell
Browse files

Make invalidateOptionsMenu asynchronous

Process any pending menu invalidations on the animation tick, before
traversals are performed. Collapse multiple menu invalidations
together.

Bug 7189372

Change-Id: I7a33ae9813980eb8fbcc958804de2c03328ecca8
parent 49a22f29
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -89,6 +89,13 @@ public abstract class Window {
     * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
     */
    public static final int FEATURE_ACTION_MODE_OVERLAY = 10;

    /**
     * Max value used as a feature ID
     * @hide
     */
    public static final int FEATURE_MAX = FEATURE_ACTION_MODE_OVERLAY;

    /** Flag for setting the progress bar's visibility to VISIBLE */
    public static final int PROGRESS_VISIBILITY_ON = -1;
    /** Flag for setting the progress bar's visibility to GONE */
+26 −0
Original line number Diff line number Diff line
@@ -192,6 +192,20 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    private int mUiOptions = 0;

    private boolean mInvalidatePanelMenuPosted;
    private int mInvalidatePanelMenuFeatures;
    private final Runnable mInvalidatePanelMenuRunnable = new Runnable() {
        @Override public void run() {
            for (int i = 0; i <= FEATURE_MAX; i++) {
                if ((mInvalidatePanelMenuFeatures & 1 << i) != 0) {
                    doInvalidatePanelMenu(i);
                }
            }
            mInvalidatePanelMenuPosted = false;
            mInvalidatePanelMenuFeatures = 0;
        }
    };

    static class WindowManagerHolder {
        static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface(
                ServiceManager.getService("window"));
@@ -722,6 +736,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    @Override
    public void invalidatePanelMenu(int featureId) {
        mInvalidatePanelMenuFeatures |= 1 << featureId;

        if (!mInvalidatePanelMenuPosted && mDecor != null) {
            mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
            mInvalidatePanelMenuPosted = true;
        }
    }

    void doInvalidatePanelMenu(int featureId) {
        PanelFeatureState st = getPanelState(featureId, true);
        Bundle savedActionViewStates = null;
        if (st.menu != null) {
@@ -2842,6 +2865,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            mDecor.setIsRootNamespace(true);
            mDecor.setLayoutDirection(
                    getContext().getResources().getConfiguration().getLayoutDirection());
            if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) {
                mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
            }
        }
        if (mContentParent == null) {
            mContentParent = generateLayout(mDecor);