Code example for PopupWindow

Methods: dismissisShowingshowAtLocationupdate

1
 
        mWindowAbovePos.y = mAnchorRect.top - getMeasuredHeight();
        mWindowBelowPos.y = mAnchorRect.bottom + mVerticalSpaceShownBelow;
        mWindowMiddlePos.y = (parentRect.bottom - parentRect.top) / 2;
 
        if (mWindow.isShowing()) {
            switchAboveBelow(true); 
            mWindow.update(mWindowAbovePos.x, mWindowAbovePos.y, -1, -1);
 
            if (!isPositionVisible(mWindowAbovePos, parentRect)) {
                hide(); 
 
                switchAboveBelow(false); 
                if (isPositionVisible(mWindowBelowPos, parentRect)) {
                    mWindow.showAtLocation(mParent, 0, mWindowBelowPos.x, mWindowBelowPos.y);
                    mIsShowing = true;
                } else { 
                    switchAboveBelow(true); 
                    if (isPositionVisible(mWindowMiddlePos, parentRect)) {
	                    mWindow.showAtLocation(mParent, 0, mWindowMiddlePos.x, mWindowMiddlePos.y);
	                    mIsShowing = true;
                    } 
                } 
            } 
        } 
    } 
 
    /** 
     * @return true if the selection menu is active. 
     */ 
    public boolean isShowing() { 
        return mIsShowing;
    } 
 
    /** 
     * Shows the selection menu if it's currently anchored to a visible area. 
     */ 
    public void show() { 
        if (!mIsShowing) {
            Rect parentRect = getParentRect();
            if (!isSelectionVisible(parentRect)) return;
            switchAboveBelow(true); 
            if (isPositionVisible(mWindowAbovePos, parentRect)) {
                mWindow.showAtLocation(mParent, 0, mWindowAbovePos.x, mWindowAbovePos.y);
                mIsShowing = true;
            } else { 
                switchAboveBelow(false); 
                if (isPositionVisible(mWindowBelowPos, parentRect)) {
                    mWindow.showAtLocation(mParent, 0, mWindowBelowPos.x, mWindowBelowPos.y);
                    mIsShowing = true;
                } else { 
                    switchAboveBelow(true); 
                    if (isPositionVisible(mWindowMiddlePos, parentRect)) {
	                    mWindow.showAtLocation(mParent, 0, mWindowMiddlePos.x, mWindowMiddlePos.y);
	                    mIsShowing = true;
                    } 
                } 
            } 
        } 
    } 
 
    /** 
     * Hides the selection menu. 
     */ 
    public void hide() { 
        if (mIsShowing) {
            mWindow.dismiss();
            mIsShowing = false;
        } 
    } 
 
    /** 
Experience pair programming with AI  Get Codota for Java