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

Commit 0458796f authored by Adam Powell's avatar Adam Powell
Browse files

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
parent 1aab8350
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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:
+30 −6
Original line number Diff line number Diff line
@@ -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();
            }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ public class ActionBarView extends ViewGroup {
        mSubtitle = subtitle;
        if (mSubtitleView != null) {
            mSubtitleView.setText(subtitle);
            mSubtitleView.setVisibility(subtitle != null ? VISIBLE : GONE);
        }
    }