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

Commit b5e18555 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Fix bug 3200615 - "MenuPopupHelper cannot be used without an anchor"" into honeycomb

parents e15ac3b9 5e3f284b
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -66,11 +66,12 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        }

        public void run() {
            if (mPopup.tryShow()) {
                mOverflowPopup = mPopup;
            mPopup.show();
                mPostedOpenRunnable = null;
            }
        }
    }

    private OpenOverflowRunnable mPostedOpenRunnable;

+8 −1
Original line number Diff line number Diff line
@@ -69,6 +69,12 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
    }

    public void show() {
        if (!tryShow()) {
            throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
        }
    }

    public boolean tryShow() {
        mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
        mPopup.setOnItemClickListener(this);
        mPopup.setOnDismissListener(this);
@@ -92,13 +98,14 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
            mTreeObserver.addOnGlobalLayoutListener(this);
            mPopup.setAnchorView(anchor);
        } else {
            throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
            return false;
        }

        mPopup.setContentWidth(Math.min(measureContentWidth(adapter), mPopupMaxWidth));
        mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        mPopup.show();
        mPopup.getListView().setOnKeyListener(this);
        return true;
    }

    public void dismiss() {
+5 −4
Original line number Diff line number Diff line
@@ -3007,7 +3007,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

        @Override
        public void run() {
            show();
            if (tryShow()) {
                Callback cb = getCallback();
                if (cb != null) {
                    cb.onMenuOpened(FEATURE_ACTION_BAR, mSubMenu);
@@ -3015,3 +3015,4 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            }
        }
    }
}