Search in sources :

Example 1 with View_HasStateListenerSupport

use of com.smartandroid.sa.sherlock.internal.view.View_HasStateListenerSupport in project SmartAndroidSource by jaychou2012.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new IcsListPopupWindow(mContext, null, android.R.attr.popupMenuStyle);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mAdapter = new MenuAdapter(mMenu);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        // avoid VTO-related leaks.
        if (anchor.getWindowToken() != null) {
            ViewTreeObserver vto = anchor.getViewTreeObserver();
            if (vto != mTreeObserver) {
                if (mTreeObserver != null && mTreeObserver.isAlive()) {
                    mTreeObserver.removeGlobalOnLayoutListener(this);
                }
                if ((mTreeObserver = vto) != null) {
                    vto.addOnGlobalLayoutListener(this);
                }
            }
        } else if (anchor instanceof View_HasStateListenerSupport) {
            ((View_HasStateListenerSupport) anchor).addOnAttachStateChangeListener(this);
        }
        mPopup.setAnchorView(anchor);
    } else {
        return false;
    }
    mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : View_HasStateListenerSupport(com.smartandroid.sa.sherlock.internal.view.View_HasStateListenerSupport) View(android.view.View) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver) IcsListPopupWindow(com.smartandroid.sa.sherlock.internal.widget.IcsListPopupWindow)

Aggregations

View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 AdapterView (android.widget.AdapterView)1 View_HasStateListenerSupport (com.smartandroid.sa.sherlock.internal.view.View_HasStateListenerSupport)1 IcsListPopupWindow (com.smartandroid.sa.sherlock.internal.widget.IcsListPopupWindow)1