diff options
| author | Adam Powell <adamp@google.com> | 2010-11-11 22:15:07 -0800 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2010-11-11 22:55:36 -0800 |
| commit | 0458796f1401732b38660794148f4c5e5602f432 (patch) | |
| tree | 1be055e761a5265467e539f86d6e3135ed789778 | |
| parent | 1aab83501cb2ddc264ec9913d1062b1c87344e3a (diff) | |
| download | frameworks_base-0458796f1401732b38660794148f4c5e5602f432.zip frameworks_base-0458796f1401732b38660794148f4c5e5602f432.tar.gz frameworks_base-0458796f1401732b38660794148f4c5e5602f432.tar.bz2 | |
Fix bug 3146938 - Menus spawned by ActionBar should hide when action
bar is hidden
Any popup spawned by the private class MenuPopupHelper will be hidden
if its anchor becomes hidden. ("hidden" == !View#isShown())
Fix a bug where ActionBar subtitle views were not going away when
subtitle text was set to null.
Fix a bug when switching out of ActionBar tabbed nav mode with no
active tabs.
Change-Id: I1f30c067156221f96905ac69ab876418ad2e94f8
3 files changed, 32 insertions, 7 deletions
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 7cf369f..cd1cae6 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -616,7 +616,7 @@ public class ActionBarImpl extends ActionBar { public int getSelectedNavigationIndex() { switch (mActionView.getNavigationMode()) { case NAVIGATION_MODE_TABS: - return mSelectedTab.getPosition(); + return mSelectedTab != null ? mSelectedTab.getPosition() : -1; case NAVIGATION_MODE_LIST: return mActionView.getDropdownSelectedPosition(); default: diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java index c947824..1d103ed 100644 --- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java +++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java @@ -24,6 +24,7 @@ import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; import android.view.View.MeasureSpec; +import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.ListPopupWindow; import android.widget.PopupWindow; @@ -33,7 +34,8 @@ import java.lang.ref.WeakReference; /** * @hide */ -public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.OnKeyListener { +public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.OnKeyListener, + ViewTreeObserver.OnGlobalLayoutListener { private static final String TAG = "MenuPopupHelper"; private Context mContext; @@ -42,6 +44,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On private int mPopupMaxWidth; private WeakReference<View> mAnchorView; private boolean mOverflowOnly; + private ViewTreeObserver mTreeObserver; private PopupWindow.OnDismissListener mDismissListener = new PopupWindow.OnDismissListener() { public void onDismiss() { @@ -82,12 +85,18 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On mPopup.setAdapter(adapter); mPopup.setModal(true); - if (mAnchorView != null) { - mPopup.setAnchorView(mAnchorView.get()); - } else if (mMenu instanceof SubMenuBuilder) { + View anchor = mAnchorView != null ? mAnchorView.get() : null; + if (anchor == null && mMenu instanceof SubMenuBuilder) { SubMenuBuilder subMenu = (SubMenuBuilder) mMenu; final MenuItemImpl itemImpl = (MenuItemImpl) subMenu.getItem(); - mPopup.setAnchorView(itemImpl.getItemView(MenuBuilder.TYPE_ACTION_BUTTON, null)); + anchor = itemImpl.getItemView(MenuBuilder.TYPE_ACTION_BUTTON, null); + mAnchorView = new WeakReference<View>(anchor); + } + + if (anchor != null) { + mTreeObserver = anchor.getViewTreeObserver(); + mTreeObserver.addOnGlobalLayoutListener(this); + mPopup.setAnchorView(anchor); } else { throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor"); } @@ -101,6 +110,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On if (isShowing()) { mPopup.dismiss(); } + mTreeObserver.removeGlobalOnLayoutListener(this); + mTreeObserver = null; } public boolean isShowing() { @@ -115,7 +126,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On item = mMenu.getItem(position); } mMenu.performItemAction(item, 0); - mPopup.dismiss(); + dismiss(); } public boolean onKey(View v, int keyCode, KeyEvent event) { @@ -142,4 +153,17 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On } return width; } + + @Override + public void onGlobalLayout() { + if (!isShowing()) { + mTreeObserver.removeGlobalOnLayoutListener(this); + mTreeObserver = null; + } else { + final View anchor = mAnchorView != null ? mAnchorView.get() : null; + if (anchor != null && !anchor.isShown()) { + dismiss(); + } + } + } } diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index be6a57a..7a64da0 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -330,6 +330,7 @@ public class ActionBarView extends ViewGroup { mSubtitle = subtitle; if (mSubtitleView != null) { mSubtitleView.setText(subtitle); + mSubtitleView.setVisibility(subtitle != null ? VISIBLE : GONE); } } |
