Code example for PopupWindow

Methods: dismissisShowingsetContentViewshowAtLocation

0
    void show() { 
        if (!isPositionVisible()) { 
            hide(); 
            return; 
        } 
        mContainer.setContentView(this);
        final int[] coords = mTempCoords;
        mParent.getLocationInWindow(coords);
        mContainerPositionX = coords[0] + mPositionX;
        mContainerPositionY = coords[1] + mPositionY;
        mContainer.showAtLocation(mParent, 0, mContainerPositionX, mContainerPositionY);
 
        // Hide paste view when handle is moved on screen. 
        if (mPastePopupWindow != null) {
            mPastePopupWindow.hide();
        } 
    } 
 
    void hide() { 
        mIsDragging = false;
        mContainer.dismiss();
        if (mPastePopupWindow != null) {
            mPastePopupWindow.hide();
        } 
    } 
 
    boolean isShowing() { 
        return mContainer.isShowing();
    } 
 
    private boolean isPositionVisible() { 
        // Always show a dragging handle. 
        if (mIsDragging) {
            return true; 
        } 
 
        final Rect clip = mTempRect;
        clip.left = 0;
        clip.top = 0;
        clip.right = mParent.getWidth();
        clip.bottom = mParent.getHeight();
 
        final ViewParent parent = mParent.getParent();
        if (parent == null || !parent.getChildVisibleRect(mParent, clip, null)) {
            return false; 
        } 
 
        final int[] coords = mTempCoords;
        mParent.getLocationInWindow(coords);
        final int posX = coords[0] + mPositionX + (int) mHotspotX;
        final int posY = coords[1] + mPositionY + (int) mHotspotY;
 
        return posX >= clip.left && posX <= clip.right &&
                posY >= clip.top && posY <= clip.bottom;
    } 
 
    // x and y are in physical pixels. 
    void moveTo(int x, int y) {
        mPositionX = x;
        mPositionY = y;
        if (isPositionVisible()) { 
            int[] coords = null;
            if (mContainer.isShowing()) {
                coords = mTempCoords;
                mParent.getLocationInWindow(coords);
                final int containerPositionX = coords[0] + mPositionX;
                final int containerPositionY = coords[1] + mPositionY;