Skip to content

Commit 98c370e

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Make invalidateOptionsMenu asynchronous" into jb-mr1-dev
2 parents 1e5aeec + 4b6d93f commit 98c370e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

core/java/android/view/Window.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ public abstract class Window {
8989
* If overlay is enabled, the action mode UI will be allowed to cover existing window content.
9090
*/
9191
public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
92+
93+
/**
94+
* Max value used as a feature ID
95+
* @hide
96+
*/
97+
public static final int FEATURE_MAX = FEATURE_ACTION_MODE_OVERLAY;
98+
9299
/** Flag for setting the progress bar's visibility to VISIBLE */
93100
public static final int PROGRESS_VISIBILITY_ON = -1;
94101
/** Flag for setting the progress bar's visibility to GONE */

policy/src/com/android/internal/policy/impl/PhoneWindow.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
192192

193193
private int mUiOptions = 0;
194194

195+
private boolean mInvalidatePanelMenuPosted;
196+
private int mInvalidatePanelMenuFeatures;
197+
private final Runnable mInvalidatePanelMenuRunnable = new Runnable() {
198+
@Override public void run() {
199+
for (int i = 0; i <= FEATURE_MAX; i++) {
200+
if ((mInvalidatePanelMenuFeatures & 1 << i) != 0) {
201+
doInvalidatePanelMenu(i);
202+
}
203+
}
204+
mInvalidatePanelMenuPosted = false;
205+
mInvalidatePanelMenuFeatures = 0;
206+
}
207+
};
208+
195209
static class WindowManagerHolder {
196210
static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface(
197211
ServiceManager.getService("window"));
@@ -722,6 +736,15 @@ public final void togglePanel(int featureId, KeyEvent event) {
722736

723737
@Override
724738
public void invalidatePanelMenu(int featureId) {
739+
mInvalidatePanelMenuFeatures |= 1 << featureId;
740+
741+
if (!mInvalidatePanelMenuPosted && mDecor != null) {
742+
mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
743+
mInvalidatePanelMenuPosted = true;
744+
}
745+
}
746+
747+
void doInvalidatePanelMenu(int featureId) {
725748
PanelFeatureState st = getPanelState(featureId, true);
726749
Bundle savedActionViewStates = null;
727750
if (st.menu != null) {
@@ -2842,6 +2865,9 @@ private void installDecor() {
28422865
mDecor.setIsRootNamespace(true);
28432866
mDecor.setLayoutDirection(
28442867
getContext().getResources().getConfiguration().getLayoutDirection());
2868+
if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) {
2869+
mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
2870+
}
28452871
}
28462872
if (mContentParent == null) {
28472873
mContentParent = generateLayout(mDecor);

0 commit comments

Comments
 (0)