Code example for View

Methods: getHeight, getLocationInWindow, getLocationOnScreen, getRootView, getScrollX, getScrollY, getViewTreeObserver, getWindowVisibleDisplayFrame, requestRectangleOnScreen

0
    } 
 
    private boolean findDropDownPosition(View anchor, WindowManager.LayoutParams p,
                                         int xoff, int yoff) {
        final int anchorHeight = anchor.getHeight();
        anchor.getLocationInWindow(mDrawingLocation);
        p.x = mDrawingLocation[0] + xoff;
        p.y = mDrawingLocation[1] + anchorHeight + yoff;
        boolean onTop = false;
        p.gravity = Gravity.LEFT | Gravity.TOP;
        anchor.getLocationOnScreen(mScreenLocation);
        final Rect displayFrame = new Rect();
        anchor.getWindowVisibleDisplayFrame(displayFrame);
        int screenY = mScreenLocation[1] + anchorHeight + yoff;
        final View root = anchor.getRootView();
        if (screenY + mPopupHeight > displayFrame.bottom ||
                p.x + mPopupWidth - root.getWidth() > 0) {
            if (mAllowScrollingAnchorParent) {
                int scrollX = anchor.getScrollX();
                int scrollY = anchor.getScrollY();
                Rect r = new Rect(scrollX, scrollY, scrollX + mPopupWidth + xoff,
                        scrollY + mPopupHeight + anchor.getHeight() + yoff);
                anchor.requestRectangleOnScreen(r, true);
            } 
            anchor.getLocationInWindow(mDrawingLocation);
            p.x = mDrawingLocation[0] + xoff;
            p.y = mDrawingLocation[1] + anchor.getHeight() + yoff;
            anchor.getLocationOnScreen(mScreenLocation);
            onTop = displayFrame.bottom - mScreenLocation[1] - anchor.getHeight() - yoff <
                    mScreenLocation[1] - yoff - displayFrame.top;
            if (onTop) {
                p.gravity = Gravity.LEFT | Gravity.BOTTOM;
                p.y = root.getHeight() - mDrawingLocation[1] + yoff;
            } else { 
                p.y = mDrawingLocation[1] + anchor.getHeight() + yoff;
            } 
        } 
        if (mClipToScreen) {
            final int displayFrameWidth = displayFrame.right - displayFrame.left;
            int right = p.x + p.width;
            if (right > displayFrameWidth) {
                p.x -= right - displayFrameWidth;
            } 
            if (p.x < displayFrame.left) {
                p.x = displayFrame.left;
                p.width = Math.min(p.width, displayFrameWidth);
            } 
            if (onTop) {
                int popupTop = mScreenLocation[1] + yoff - mPopupHeight;
                if (popupTop < 0) {
                    p.y += popupTop;
                } 
            } else { 
                p.y = Math.max(p.y, displayFrame.top);
            } 
        } 
        p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;
        return onTop;
    } 
 
    public int getAnimationStyle() { 
        return mAnimationStyle;
    } 
 
    public Drawable getBackground() {
        return mBackground;
    } 
 
    public View getContentView() {
        return mContentView;
    } 
 
    public int getHeight() { 
        return mHeight;
    } 
 
    public int getInputMethodMode() { 
        return mInputMethodMode;
 
    } 
 
    public int getMaxAvailableHeight(View anchor) {
        return getMaxAvailableHeight(anchor, 0);
    } 
 
    public int getMaxAvailableHeight(View anchor, int yOffset) {
        return getMaxAvailableHeight(anchor, yOffset, false);
    } 
 
    public int getMaxAvailableHeight(View anchor, int yOffset, boolean ignoreBottomDecorations) {
        final Rect displayFrame = new Rect();
        anchor.getWindowVisibleDisplayFrame(displayFrame);
        final int[] anchorPos = mDrawingLocation;
        anchor.getLocationOnScreen(anchorPos);
        int bottomEdge = displayFrame.bottom;
        if (ignoreBottomDecorations) {
            Resources res = anchor.getContext().getResources();
            bottomEdge = res.getDisplayMetrics().heightPixels;
        } 
        final int distanceToBottom = bottomEdge - (anchorPos[1] + anchor.getHeight()) - yOffset;
        final int distanceToTop = anchorPos[1] - displayFrame.top + yOffset;
        int returnedHeight = Math.max(distanceToBottom, distanceToTop);
        if (mBackground != null) {
            mBackground.getPadding(mTempRect);
            returnedHeight -= mTempRect.top + mTempRect.bottom;
        } 
        return returnedHeight;
    } 
 
    public int getSoftInputMode() { 
        return mSoftInputMode;
    } 
 
    public int getWidth() { 
        return mWidth;
    } 
 
    public int getWindowLayoutType() { 
        return mWindowLayoutType;
    } 
 
    private void invokePopup(WindowManager.LayoutParams p) {
        if (mContext != null) {
            p.packageName = mContext.getPackageName();
        } 
        if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
            mPopupView.setFitsSystemWindows(mLayoutInsetDecor);
        } 
        mWindowManager.addView(mPopupView, p);
    } 
 
    public boolean isAboveAnchor() { 
        return mAboveAnchor;
    } 
 
    public boolean isClippingEnabled() { 
        return mClippingEnabled;
    } 
 
    public boolean isFocusable() { 
        return mFocusable;
    } 
 
    public boolean isLayoutInScreenEnabled() { 
        return mLayoutInScreen;
    } 
 
    public boolean isOutsideTouchable() { 
        return mOutsideTouchable;
    } 
 
    public boolean isShowing() { 
        return mIsShowing;
    } 
 
    public boolean isSplitTouchEnabled() { 
        if (mSplitTouchEnabled < 0 && mContext != null) {
            return mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB;
        } 
        return mSplitTouchEnabled == 1;
    } 
 
    public boolean isTouchable() { 
        return mTouchable;
    } 
 
    @SuppressWarnings("deprecation") 
    private void preparePopup(WindowManager.LayoutParams p) {
        if (mContentView == null || mContext == null || mWindowManager == null) {
            throw new IllegalStateException("You must specify a valid content view by "
                    + "calling setContentView() before attempting to show the popup."); 
        } 
        if (mBackground != null) {
            final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
            int height = ViewGroup.LayoutParams.MATCH_PARENT;
            if (layoutParams != null &&
                    layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
                height = ViewGroup.LayoutParams.WRAP_CONTENT;
            } 
            PopupViewContainer popupViewContainer = new PopupViewContainer(mContext);
            PopupViewContainer.LayoutParams listParams = new PopupViewContainer.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, height
            ); 
            popupViewContainer.setBackgroundDrawable(mBackground);
            popupViewContainer.addView(mContentView, listParams);
            mPopupView = popupViewContainer;
        } else { 
            mPopupView = mContentView;
        } 
        mPopupWidth = p.width;
        mPopupHeight = p.height;
    } 
 
    private void registerForScrollChanged(View anchor, int xoff, int yoff) {
        unregisterForScrollChanged(); 
        mAnchor = new WeakReference<View>(anchor);
        ViewTreeObserver vto = anchor.getViewTreeObserver();
        if (vto != null) {
            vto.addOnScrollChangedListener(mOnScrollChangedListener);
        } 
        mAnchorXoff = xoff;
        mAnchorYoff = yoff;
    }