am 728827ff: Merge "Uphold common ordering expectations around action bar Home/Up dispatch" into jb-mr2-dev

* commit '728827ff472b72ed7a86971ed8e35a01ce5bc8bf':
  Uphold common ordering expectations around action bar Home/Up dispatch
This commit is contained in:
Adam Powell
2013-04-04 11:05:31 -07:00
committed by Android Git Automerger
2 changed files with 21 additions and 5 deletions

View File

@ -36,7 +36,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@ -125,6 +124,7 @@ public class ActionBarView extends AbsActionBarView {
private boolean mWasHomeEnabled; // Was it enabled before action view expansion? private boolean mWasHomeEnabled; // Was it enabled before action view expansion?
private MenuBuilder mOptionsMenu; private MenuBuilder mOptionsMenu;
private boolean mMenuPrepared;
private ActionBarContextView mContextView; private ActionBarContextView mContextView;
@ -164,8 +164,11 @@ public class ActionBarView extends AbsActionBarView {
private final OnClickListener mUpClickListener = new OnClickListener() { private final OnClickListener mUpClickListener = new OnClickListener() {
public void onClick(View v) { 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); mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem);
} }
}
}; };
public ActionBarView(Context context, AttributeSet attrs) { public ActionBarView(Context context, AttributeSet attrs) {
@ -402,6 +405,10 @@ public class ActionBarView extends AbsActionBarView {
mCallback = callback; mCallback = callback;
} }
public void setMenuPrepared() {
mMenuPrepared = true;
}
public void setMenu(Menu menu, MenuPresenter.Callback cb) { public void setMenu(Menu menu, MenuPresenter.Callback cb) {
if (menu == mOptionsMenu) return; if (menu == mOptionsMenu) return;

View File

@ -380,6 +380,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
st.createdPanelView = cb.onCreatePanelView(st.featureId); 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) { if (st.createdPanelView == null) {
// Init the panel state's menu--return false if init failed // Init the panel state's menu--return false if init failed
if (st.menu == null || st.refreshMenuContent) { 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) { if (mActionMenuPresenterCallback == null) {
mActionMenuPresenterCallback = new ActionMenuPresenterCallback(); mActionMenuPresenterCallback = new ActionMenuPresenterCallback();
} }
@ -405,7 +414,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// Ditch the menu created above // Ditch the menu created above
st.setMenu(null); st.setMenu(null);
if (mActionBar != null) { if (isActionBarMenu && mActionBar != null) {
// Don't show it in the action bar either // Don't show it in the action bar either
mActionBar.setMenu(null, mActionMenuPresenterCallback); 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 (!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. // The app didn't want to show the menu for now but it still exists.
// Clear it out of the action bar. // Clear it out of the action bar.
mActionBar.setMenu(null, mActionMenuPresenterCallback); mActionBar.setMenu(null, mActionMenuPresenterCallback);