Example usage for android.view View getBottom

List of usage examples for android.view View getBottom

Introduction

In this page you can find the example usage for android.view View getBottom.

Prototype

@ViewDebug.CapturedViewProperty
public final int getBottom() 

Source Link

Document

Bottom position of this view relative to its parent.

Usage

From source file:com.appunite.list.ListView.java

@Override
public boolean isOpaque() {
    boolean retValue = (mCachingActive && mIsCacheColorOpaque && mDividerIsOpaque
            && hasOpaqueScrollbarsUnhide()) || super.isOpaque();
    if (retValue) {
        // only return true if the list items cover the entire area of the view
        final int listTop = mListPadding != null ? mListPadding.top : getPaddingTop();
        View first = getChildAt(0);
        if (first == null || first.getTop() > listTop) {
            return false;
        }/*w  ww  .  j  a  va2 s  .  c  om*/
        final int listBottom = getHeight() - (mListPadding != null ? mListPadding.bottom : getPaddingBottom());
        View last = getChildAt(getChildCount() - 1);
        if (last == null || last.getBottom() < listBottom) {
            return false;
        }
    }
    return retValue;
}

From source file:com.appunite.list.ListView.java

/**
 * Fills the list from pos down to the end of the list view.
 *
 * @param pos The first position to put in the list
 *
 * @param nextTop The location where the top of the item associated with pos
 *        should be drawn//from   www.  ja v a2  s  .c  om
 *
 * @return The view that is currently selected, if it happens to be in the
 *         range that we draw.
 */
private View fillDown(int pos, int nextTop) {
    View selectedView = null;

    int end = (getBottom() - getTop());
    if (mClipToPadding) {
        end -= mListPadding.bottom;
    }

    while (nextTop < end && pos < mItemCount) {
        // is this the selected item?
        boolean selected = pos == mSelectedPosition;
        View child = makeAndAddView(pos, nextTop, true, mListPadding.left, selected);

        nextTop = child.getBottom() + mDividerHeight;
        if (selected) {
            selectedView = child;
        }
        pos++;
    }

    // FIXME removed bacause we do not need RemoteViews (j.m.)
    //        setVisibleRangeHint(mFirstPosition, mFirstPosition + getChildCount() - 1);
    return selectedView;
}

From source file:com.appunite.list.ListView.java

/**
 * Check if we have dragged the bottom of the list too low (we have pushed the
 * bottom element off the bottom of the screen when we did not need to). Correct by sliding
 * everything back up./*from   w  w w  . j  a  va  2  s .  c  om*/
 *
 * @param childCount Number of children
 */
private void correctTooLow(int childCount) {
    // First see if the first item is visible. If it is not, it is OK for the
    // bottom of the list to be pushed down.
    if (mFirstPosition == 0 && childCount > 0) {

        // Get the first child ...
        final View firstChild = getChildAt(0);

        // ... and its top edge
        final int firstTop = firstChild.getTop();

        // This is top of our drawable area
        final int start = mListPadding.top;

        // This is bottom of our drawable area
        final int end = (getBottom() - getTop()) - mListPadding.bottom;

        // This is how far the top edge of the first view is from the top of the
        // drawable area
        int topOffset = firstTop - start;
        View lastChild = getChildAt(childCount - 1);
        final int lastBottom = lastChild.getBottom();
        int lastPosition = mFirstPosition + childCount - 1;

        // Make sure we are 1) Too low, and 2) Either there are more rows below the
        // last row or the last row is scrolled off the bottom of the drawable area
        if (topOffset > 0) {
            if (lastPosition < mItemCount - 1 || lastBottom > end) {
                if (lastPosition == mItemCount - 1) {
                    // Don't pull the bottom too far up
                    topOffset = Math.min(topOffset, lastBottom - end);
                }
                // Move everything up
                offsetChildrenTopAndBottomUnhide(-topOffset);
                if (lastPosition < mItemCount - 1) {
                    // Fill the gap that was opened below the last position with more rows, if
                    // possible
                    fillDown(lastPosition + 1, lastChild.getBottom() + mDividerHeight);
                    // Close up the remaining gap
                    adjustViewsUpOrDown();
                }
            } else if (lastPosition == mItemCount - 1) {
                adjustViewsUpOrDown();
            }
        }
    }
}

From source file:com.appunite.list.ListView.java

/**
 * Scroll the children by amount, adding a view at the end and removing
 * views that fall off as necessary.//from   w w w .j a  va2s. c o m
 *
 * @param amount The amount (positive or negative) to scroll.
 */
private void scrollListItemsBy(int amount) {
    offsetChildrenTopAndBottomUnhide(amount);

    final int listBottom = getHeight() - mListPadding.bottom;
    final int listTop = mListPadding.top;
    final AbsListView.RecycleBin recycleBin = mRecycler;

    if (amount < 0) {
        // shifted items up

        // may need to pan views into the bottom space
        int numChildren = getChildCount();
        View last = getChildAt(numChildren - 1);
        while (last.getBottom() < listBottom) {
            final int lastVisiblePosition = mFirstPosition + numChildren - 1;
            if (lastVisiblePosition < mItemCount - 1) {
                last = addViewBelow(last, lastVisiblePosition);
                numChildren++;
            } else {
                break;
            }
        }

        // may have brought in the last child of the list that is skinnier
        // than the fading edge, thereby leaving space at the end.  need
        // to shift back
        if (last.getBottom() < listBottom) {
            offsetChildrenTopAndBottomUnhide(listBottom - last.getBottom());
        }

        // top views may be panned off screen
        View first = getChildAt(0);
        while (first.getBottom() < listTop) {
            AbsListView.LayoutParams layoutParams = (LayoutParams) first.getLayoutParams();
            if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) {
                recycleBin.addScrapView(first, mFirstPosition);
            }
            detachViewFromParent(first);
            first = getChildAt(0);
            mFirstPosition++;
        }
    } else {
        // shifted items down
        View first = getChildAt(0);

        // may need to pan views into top
        while ((first.getTop() > listTop) && (mFirstPosition > 0)) {
            first = addViewAbove(first, mFirstPosition);
            mFirstPosition--;
        }

        // may have brought the very first child of the list in too far and
        // need to shift it back
        if (first.getTop() > listTop) {
            offsetChildrenTopAndBottomUnhide(listTop - first.getTop());
        }

        int lastIndex = getChildCount() - 1;
        View last = getChildAt(lastIndex);

        // bottom view may be panned off screen
        while (last.getTop() > listBottom) {
            AbsListView.LayoutParams layoutParams = (LayoutParams) last.getLayoutParams();
            if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) {
                recycleBin.addScrapView(last, mFirstPosition + lastIndex);
            }
            detachViewFromParent(last);
            last = getChildAt(--lastIndex);
        }
    }
}

From source file:com.huyn.demogroup.bahavior.widget.CoordinatorLayout.java

private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) {
    if (!ViewCompat.isLaidOut(child)) {
        // The view has not been laid out yet,
        // so we can't obtain its bounds.
        return;/* w w w . j  a  v a 2  s  .co m*/
    }

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection);

    final Behavior behavior = lp.getBehavior();
    final Rect rect = mTempRect3;
    if (behavior != null && behavior.getInsetDodgeRect(this, child, rect)) {
        // Make sure that it intersects the views bounds
        if (!rect.intersect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom())) {
            throw new IllegalArgumentException("Rect should intersect with child's bounds.");
        }
    } else {
        rect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
    }

    if (rect.isEmpty()) {
        // Rect is empty so there is nothing to dodge against, skip...
        return;
    }

    boolean offsetY = false;
    if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) {
        int distance = rect.top - lp.topMargin - lp.mInsetOffsetY;
        if (distance < inset.top) {
            setInsetOffsetY(child, inset.top - distance);
            offsetY = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) {
        int distance = getHeight() - rect.bottom - lp.bottomMargin + lp.mInsetOffsetY;
        if (distance < inset.bottom) {
            setInsetOffsetY(child, distance - inset.bottom);
            offsetY = true;
        }
    }
    if (!offsetY) {
        SysoutUtil.sysout("CoordinatorLayout", "offsetChildByInset");
        setInsetOffsetY(child, 0);
    }

    boolean offsetX = false;
    if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) {
        int distance = rect.left - lp.leftMargin - lp.mInsetOffsetX;
        if (distance < inset.left) {
            setInsetOffsetX(child, inset.left - distance);
            offsetX = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) {
        int distance = getWidth() - rect.right - lp.rightMargin + lp.mInsetOffsetX;
        if (distance < inset.right) {
            setInsetOffsetX(child, distance - inset.right);
            offsetX = true;
        }
    }
    if (!offsetX) {
        setInsetOffsetX(child, 0);
    }
}

From source file:com.appunite.list.GridView.java

/**
 * Fills the grid based on positioning the new selection relative to the old
 * selection. The new selection will be placed at, above, or below the
 * location of the new selection depending on how the selection is moving.
 * The selection will then be pinned to the visible part of the screen,
 * excluding the edges that are faded. The grid is then filled upwards and
 * downwards from there./* w  w  w .j  ava2  s .  c  o  m*/
 *
 * @param delta Which way we are moving
 * @param childrenTop Where to start drawing children
 * @param childrenBottom Last pixel where children can be drawn
 * @return The view that currently has selection
 */
private View moveSelection(int delta, int childrenTop, int childrenBottom) {
    final int fadingEdgeLength = getVerticalFadingEdgeLength();
    final int selectedPosition = mSelectedPosition;
    final int numColumns = mNumColumns;
    final int verticalSpacing = mVerticalSpacing;

    int oldRowStart;
    int rowStart;
    int rowEnd = -1;

    if (!mStackFromBottom) {
        oldRowStart = (selectedPosition - delta) - ((selectedPosition - delta) % numColumns);

        rowStart = selectedPosition - (selectedPosition % numColumns);
    } else {
        int invertedSelection = mItemCount - 1 - selectedPosition;

        rowEnd = mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns));
        rowStart = Math.max(0, rowEnd - numColumns + 1);

        invertedSelection = mItemCount - 1 - (selectedPosition - delta);
        oldRowStart = mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns));
        oldRowStart = Math.max(0, oldRowStart - numColumns + 1);
    }

    final int rowDelta = rowStart - oldRowStart;

    final int topSelectionPixel = getTopSelectionPixel(childrenTop, fadingEdgeLength, rowStart);
    final int bottomSelectionPixel = getBottomSelectionPixel(childrenBottom, fadingEdgeLength, numColumns,
            rowStart);

    // Possibly changed again in fillUp if we add rows above this one.
    mFirstPosition = rowStart;

    View sel;
    View referenceView;

    if (rowDelta > 0) {
        /*
         * Case 1: Scrolling down.
         */

        final int oldBottom = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getBottom();

        sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldBottom + verticalSpacing, true);
        referenceView = mReferenceView;

        adjustForBottomFadingEdge(referenceView, topSelectionPixel, bottomSelectionPixel);
    } else if (rowDelta < 0) {
        /*
         * Case 2: Scrolling up.
         */
        final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop();

        sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldTop - verticalSpacing, false);
        referenceView = mReferenceView;

        adjustForTopFadingEdge(referenceView, topSelectionPixel, bottomSelectionPixel);
    } else {
        /*
         * Keep selection where it was
         */
        final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop();

        sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldTop, true);
        referenceView = mReferenceView;
    }

    if (!mStackFromBottom) {
        fillUp(rowStart - numColumns, referenceView.getTop() - verticalSpacing);
        adjustViewsUpOrDown();
        fillDown(rowStart + numColumns, referenceView.getBottom() + verticalSpacing);
    } else {
        fillDown(rowEnd + numColumns, referenceView.getBottom() + verticalSpacing);
        adjustViewsUpOrDown();
        fillUp(rowStart - 1, referenceView.getTop() - verticalSpacing);
    }

    return sel;
}

From source file:com.appunite.list.ListView.java

private View addViewBelow(View theView, int position) {
    int belowPosition = position + 1;
    View view = obtainView(belowPosition, mIsScrap);
    int edgeOfNewChild = theView.getBottom() + mDividerHeight;
    setupChild(view, belowPosition, edgeOfNewChild, true, mListPadding.left, false, mIsScrap[0]);
    return view;//from w  w w  .  j a va 2  s. c  om
}

From source file:com.appunite.list.ListView.java

/**
 * Check if we have dragged the bottom of the list too high (we have pushed the
 * top element off the top of the screen when we did not need to). Correct by sliding
 * everything back down.//ww w . j a  v a2s.c  o m
 *
 * @param childCount Number of children
 */
private void correctTooHigh(int childCount) {
    // First see if the last item is visible. If it is not, it is OK for the
    // top of the list to be pushed up.
    int lastPosition = mFirstPosition + childCount - 1;
    if (lastPosition == mItemCount - 1 && childCount > 0) {

        // Get the last child ...
        final View lastChild = getChildAt(childCount - 1);

        // ... and its bottom edge
        final int lastBottom = lastChild.getBottom();

        // This is bottom of our drawable area
        final int end = (getBottom() - getTop()) - mListPadding.bottom;

        // This is how far the bottom edge of the last view is from the bottom of the
        // drawable area
        int bottomOffset = end - lastBottom;
        View firstChild = getChildAt(0);
        final int firstTop = firstChild.getTop();

        // Make sure we are 1) Too high, and 2) Either there are more rows above the
        // first row or the first row is scrolled off the top of the drawable area
        if (bottomOffset > 0 && (mFirstPosition > 0 || firstTop < mListPadding.top)) {
            if (mFirstPosition == 0) {
                // Don't pull the top too far down
                bottomOffset = Math.min(bottomOffset, mListPadding.top - firstTop);
            }
            // Move everything down
            offsetChildrenTopAndBottomUnhide(bottomOffset);
            if (mFirstPosition > 0) {
                // Fill the gap that was opened above mFirstPosition with more rows, if
                // possible
                fillUp(mFirstPosition - 1, firstChild.getTop() - mDividerHeight);
                // Close up the remaining gap
                adjustViewsUpOrDown();
            }

        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) {
    if (!ViewCompat.isLaidOut(child)) {
        // The view has not been laid out yet, so we can't obtain its bounds.
        return;/* ww w . ja  va2 s.  co  m*/
    }

    if (child.getWidth() <= 0 || child.getHeight() <= 0) {
        // Bounds are empty so there is nothing to dodge against, skip...
        return;
    }

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final Behavior behavior = lp.getBehavior();
    final Rect dodgeRect = acquireTempRect();
    final Rect bounds = acquireTempRect();
    bounds.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());

    if (behavior != null && behavior.getInsetDodgeRect(this, child, dodgeRect)) {
        // Make sure that the rect is within the view's bounds
        if (!bounds.contains(dodgeRect)) {
            throw new IllegalArgumentException("Rect should be within the child's bounds." + " Rect:"
                    + dodgeRect.toShortString() + " | Bounds:" + bounds.toShortString());
        }
    } else {
        dodgeRect.set(bounds);
    }

    // We can release the bounds rect now
    releaseTempRect(bounds);

    if (dodgeRect.isEmpty()) {
        // Rect is empty so there is nothing to dodge against, skip...
        releaseTempRect(dodgeRect);
        return;
    }

    final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection);

    boolean offsetY = false;
    if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) {
        int distance = dodgeRect.top - lp.topMargin - lp.mInsetOffsetY;
        if (distance < inset.top) {
            setInsetOffsetY(child, inset.top - distance);
            offsetY = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) {
        int distance = getHeight() - dodgeRect.bottom - lp.bottomMargin + lp.mInsetOffsetY;
        if (distance < inset.bottom) {
            setInsetOffsetY(child, distance - inset.bottom);
            offsetY = true;
        }
    }
    if (!offsetY) {
        setInsetOffsetY(child, 0);
    }

    boolean offsetX = false;
    if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) {
        int distance = dodgeRect.left - lp.leftMargin - lp.mInsetOffsetX;
        if (distance < inset.left) {
            setInsetOffsetX(child, inset.left - distance);
            offsetX = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) {
        int distance = getWidth() - dodgeRect.right - lp.rightMargin + lp.mInsetOffsetX;
        if (distance < inset.right) {
            setInsetOffsetX(child, distance - inset.right);
            offsetX = true;
        }
    }
    if (!offsetX) {
        setInsetOffsetX(child, 0);
    }

    releaseTempRect(dodgeRect);
}

From source file:com.appunite.list.ListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (mCachingStarted) {
        mCachingActive = true;/*from www. j  a  v  a 2s. co  m*/
    }

    // Draw the dividers
    final int dividerHeight = mDividerHeight;
    final Drawable overscrollHeader = mOverScrollHeader;
    final Drawable overscrollFooter = mOverScrollFooter;
    final boolean drawOverscrollHeader = overscrollHeader != null;
    final boolean drawOverscrollFooter = overscrollFooter != null;
    final boolean drawDividers = dividerHeight > 0 && mDivider != null;

    if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) {
        // Only modify the top and bottom in the loop, we set the left and right here
        final Rect bounds = mTempRect;
        bounds.left = getPaddingLeft();
        bounds.right = getRight() - getLeft() - getPaddingRight();

        final int count = getChildCount();
        final int headerCount = mHeaderViewInfos.size();
        final int itemCount = mItemCount;
        final int footerLimit = itemCount - mFooterViewInfos.size() - 1;
        final boolean headerDividers = mHeaderDividersEnabled;
        final boolean footerDividers = mFooterDividersEnabled;
        final int first = mFirstPosition;
        final boolean areAllItemsSelectable = mAreAllItemsSelectable;
        final ListAdapter adapter = mAdapter;
        // If the list is opaque *and* the background is not, we want to
        // fill a rect where the dividers would be for non-selectable items
        // If the list is opaque and the background is also opaque, we don't
        // need to draw anything since the background will do it for us
        final boolean fillForMissingDividers = isOpaque() && !super.isOpaque();

        if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) {
            mDividerPaint = new Paint();
            mDividerPaint.setColor(getCacheColorHint());
        }
        final Paint paint = mDividerPaint;

        int effectivePaddingTop = 0;
        int effectivePaddingBottom = 0;
        if (mClipToPadding) {
            effectivePaddingTop = mListPadding.top;
            effectivePaddingBottom = mListPadding.bottom;
        }

        final int viewBottom = getBottom();
        final int viewTop = getTop();
        final int scrollY = getScrollY();

        final int listBottom = viewBottom - viewTop - effectivePaddingBottom + scrollY;
        if (!mStackFromBottom) {
            int bottom = 0;

            // Draw top divider or header for overscroll
            if (count > 0 && scrollY < 0) {
                if (drawOverscrollHeader) {
                    bounds.bottom = 0;
                    bounds.top = scrollY;
                    drawOverscrollHeader(canvas, overscrollHeader, bounds);
                } else if (drawDividers) {
                    bounds.bottom = 0;
                    bounds.top = -dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }

            for (int i = 0; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    bottom = child.getBottom();
                    // Don't draw dividers next to items that are not enabled

                    if (drawDividers && (bottom < listBottom && !(drawOverscrollFooter && i == count - 1))) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            drawDivider(canvas, bounds, i);
                        } else if (fillForMissingDividers) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            final int overFooterBottom = viewBottom + scrollY;
            if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) {
                bounds.top = bottom;
                bounds.bottom = overFooterBottom;
                drawOverscrollFooter(canvas, overscrollFooter, bounds);
            }
        } else {
            int top;

            if (count > 0 && drawOverscrollHeader) {
                bounds.top = scrollY;
                bounds.bottom = getChildAt(0).getTop();
                drawOverscrollHeader(canvas, overscrollHeader, bounds);
            }

            final int start = drawOverscrollHeader ? 1 : 0;
            for (int i = start; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    top = child.getTop();
                    // Don't draw dividers next to items that are not enabled
                    if (top > effectivePaddingTop) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            // Give the method the child ABOVE the divider, so we
                            // subtract one from our child
                            // position. Give -1 when there is no child above the
                            // divider.
                            drawDivider(canvas, bounds, i - 1);
                        } else if (fillForMissingDividers) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            if (count > 0 && scrollY > 0) {
                if (drawOverscrollFooter) {
                    final int absListBottom = viewBottom;
                    bounds.top = absListBottom;
                    bounds.bottom = absListBottom + scrollY;
                    drawOverscrollFooter(canvas, overscrollFooter, bounds);
                } else if (drawDividers) {
                    bounds.top = listBottom;
                    bounds.bottom = listBottom + dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }
        }
    }

    // Draw the indicators (these should be drawn above the dividers) and children
    super.dispatchDraw(canvas);
}