From 4b6d93fd0485b46a3a15a71516d39b4f72d9b3db Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Tue, 18 Sep 2012 18:34:08 -0700 Subject: [PATCH] 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 --- core/java/android/view/Window.java | 7 +++++ .../internal/policy/impl/PhoneWindow.java | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index a24289523560e..06974d31e86e1 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -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 */ diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index e761847b788c8..bba2c7fd8b6b0 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -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);