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.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * ListView?/*www  .jav a2s. c om*/
 *
 * @param childCount
 */
protected void correctTooHighForListView(int childCount) {
    //????
    //???,??
    int lastPosition = mFirstPosition + childCount - 1;

    //??,?
    if (lastPosition == mItemCount - 1 && childCount > 0) {

        //???
        final View lastChild = getChildAt(childCount - 1);

        //???
        final int lastBottom = lastChild.getBottom();

        //?
        final int end = getBottom() - getTop();

        //??
        int bottomOffset = end - lastBottom;

        //??
        View firstChild = getChildAt(0);
        //??
        final int firstTop = firstChild.getTop();

        //1) ? ""
        //2) ??
        //?
        if (bottomOffset > 0 && (mFirstPosition > 0 || firstTop < getTop())) {

            if (mFirstPosition == 0) {
                //??
                bottomOffset = Math.min(bottomOffset, getTop() - firstTop);
            }

            // ??
            offsetChildrenTopAndBottom(bottomOffset);
            //                startScrollIfNeed(0, bottomOffset);
            if (mFirstPosition > 0) {
                //?
                fillUpView(mFirstPosition - 1, firstChild.getTop() - mDividerHeight);
                adjustViewsUpOrDown();
            }

        }
    }
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * WheelView?//  w ww. j  a  v  a  2 s.  c  om
 *
 * @param childCount
 */
protected void correctTooHighForWheelView(int childCount) {
    //????
    //???,??
    int lastPosition = mFirstPosition + childCount - 1;

    //??,?
    if (lastPosition == mItemCount - 1 && childCount > 0) {

        //???
        final View lastChild = getChildAt(childCount - 1);

        //???
        final int lastBottom = lastChild.getBottom();

        //?
        final int end = getBottom() - getYSel() + ((lastChild.getBottom() - lastChild.getTop()) / 2) - getTop();

        //??
        int bottomOffset = end - lastBottom;

        //??
        View firstChild = getChildAt(0);
        //??
        final int firstTop = firstChild.getTop();

        //1) ? ""
        //2) ??
        //?
        if (bottomOffset > 0 && (mFirstPosition > 0 || firstTop < getTop())) {

            if (mFirstPosition == 0) {
                //??
                bottomOffset = Math.min(bottomOffset, getTop() - firstTop);
            }

            // ??
            offsetChildrenTopAndBottom(bottomOffset);
            //                startScrollIfNeed(0, bottomOffset);
            if (mFirstPosition > 0) {
                //?
                fillUpView(mFirstPosition - 1, firstChild.getTop() - mDividerHeight);
                //
                adjustViewsUpOrDown();
            }

        }
    }
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

@Override
protected void detachViewsFromParent(int start, int count) {
    if (DEBUG) {/*w w w  .  j a  v a 2 s. co m*/
        Log.i(TAG,
                String.format(Locale.US, "Detach views from parent => " + "Start %d <==> %d ", start, count));
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            Log.i(TAG,
                    String.format(Locale.US,
                            "Detach views bounds top = [%d] left = [%d] bottom = [%d] right=[%d]",
                            child.getTop(), child.getLeft(), child.getBottom(), child.getRight()));
        }
    }
    super.detachViewsFromParent(start, count);
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

@Override
protected int computeVerticalScrollExtent() {
    final int count = getChildCount();
    if (count > 0) {
        if (mSmoothScrollbarEnabled) {
            int extent = count * 100;

            View view = getChildAt(0);
            final int top = view.getTop();
            int height = view.getHeight();
            if (height > 0) {
                extent += (top * 100) / height;
            }/*from w ww .j  a v a  2  s  .c o  m*/

            view = getChildAt(count - 1);
            final int bottom = view.getBottom();
            height = view.getHeight();
            if (height > 0) {
                extent -= ((bottom - getHeight()) * 100) / height;
            }
            return extent;
        } else {
            return 1;
        }
    }
    return 0;
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

@Override
protected void getEdgeVerticalPostion(int[] pos) {
    View child = getChildAt(getPageCount() - 1);
    pos[0] = child.getTop();/*from   www . jav  a 2s .c o  m*/
    pos[1] = child.getBottom();
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Important: this method will leave offscreen views attached if they
 * are required to maintain the invariant that child view with index i
 * is always the view corresponding to position mFirstPosition + i.
 *///from w w  w.  j a  v a  2  s  .co  m
private void recycleOffscreenViews() {
    if (getChildCount() == 0) {
        return;
    }

    final int height = getHeight();
    final int clearAbove = -mItemMargin;
    final int clearBelow = height + mItemMargin;
    for (int i = getChildCount() - 1; i >= 0; i--) {
        final View child = getChildAt(i);
        if (child.getTop() <= clearBelow) {
            // There may be other offscreen views, but we need to maintain
            // the invariant documented above.
            break;
        }

        child.clearFocus();
        if (mInLayout) {
            removeViewsInLayout(i, 1);
        } else {
            removeViewAt(i);
        }

        mRecycler.addScrap(child);
    }

    while (getChildCount() > 0) {
        final View child = getChildAt(0);
        if (child.getBottom() >= clearAbove) {
            // There may be other offscreen views, but we need to maintain
            // the invariant documented above.
            break;
        }

        child.clearFocus();
        if (mInLayout) {
            removeViewsInLayout(0, 1);
        } else {
            removeViewAt(0);
        }

        mRecycler.addScrap(child);
        mFirstPosition++;
    }

    final int childCount = getChildCount();
    if (childCount > 0) {
        // Repair the top and bottom column boundaries from the views we still have
        Arrays.fill(mItemTops, Integer.MAX_VALUE);
        Arrays.fill(mItemBottoms, Integer.MIN_VALUE);
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            final int top = child.getTop() - mItemMargin;
            final int bottom = child.getBottom();
            LayoutRecord rec = mLayoutRecords.get(mFirstPosition + i);

            // It's possible the layout record could be null for visible views because
            // they are cleared between adapter data set changes, but the views are left
            // attached for the purpose of animations. Hence, populate the layout record again.
            if (rec == null) {
                rec = recreateLayoutRecord(mFirstPosition + i, child, lp);
            }

            // In LTR layout, iterate across each column that this child is laid out in,
            // starting from the child's first column (lp.column).  For each column, update
            // mItemTops and mItemBottoms appropriately to take into account this child's
            // dimension.  In RTL layout, iterate in reverse, where the child's starting
            // column would start from the right-most.
            final int span = Math.min(mColCount, lp.span);
            for (int spanIndex = 0; spanIndex < span; spanIndex++) {
                final int col = mIsRtlLayout ? lp.column - spanIndex : lp.column + spanIndex;
                final int colTop = top - rec.getMarginAbove(spanIndex);
                final int colBottom = bottom + rec.getMarginBelow(spanIndex);
                if (colTop < mItemTops[col]) {
                    mItemTops[col] = colTop;
                }
                if (colBottom > mItemBottoms[col]) {
                    mItemBottoms[col] = colBottom;
                }
            }
        }

        for (int col = 0; col < mColCount; col++) {
            if (mItemTops[col] == Integer.MAX_VALUE) {
                // If one was untouched, both were.
                final int top = getPaddingTop();
                mItemTops[col] = top;
                mItemBottoms[col] = top;
            }
        }
    }

    mCurrentScrollState = getScrollState();
}

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

/**
 * Do an arrow scroll based on focus searching.  If a new view is
 * given focus, return the selection delta and amount to scroll via
 * an {@link ArrowScrollFocusResult}, otherwise, return null.
 *
 * @param direction either {@link android.view.View#FOCUS_UP} or
 *        {@link android.view.View#FOCUS_DOWN}.
 * @return The result if focus has changed, or <code>null</code>.
 *//*  w  w  w .jav  a2s . c  o m*/
private ArrowScrollFocusResult arrowScrollFocused(final int direction) {
    final View selectedView = getSelectedView();
    View newFocus;
    if (selectedView != null && selectedView.hasFocus()) {
        View oldFocus = selectedView.findFocus();
        newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction);
    } else {
        if (direction == View.FOCUS_DOWN) {
            final boolean topFadingEdgeShowing = (mFirstPosition > 0);
            final int listTop = mListPadding.top + (topFadingEdgeShowing ? getArrowScrollPreviewLength() : 0);
            final int ySearchPoint = (selectedView != null && selectedView.getTop() > listTop)
                    ? selectedView.getTop()
                    : listTop;
            mTempRect.set(0, ySearchPoint, 0, ySearchPoint);
        } else {
            final boolean bottomFadingEdgeShowing = (mFirstPosition + getChildCount() - 1) < mItemCount;
            final int listBottom = getHeight() - mListPadding.bottom
                    - (bottomFadingEdgeShowing ? getArrowScrollPreviewLength() : 0);
            final int ySearchPoint = (selectedView != null && selectedView.getBottom() < listBottom)
                    ? selectedView.getBottom()
                    : listBottom;
            mTempRect.set(0, ySearchPoint, 0, ySearchPoint);
        }
        newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction);
    }

    if (newFocus != null) {
        final int positionOfNewFocus = positionOfNewFocus(newFocus);

        // if the focus change is in a different new position, make sure
        // we aren't jumping over another selectable position
        if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) {
            final int selectablePosition = lookForSelectablePositionOnScreen(direction);
            if (selectablePosition != INVALID_POSITION
                    && ((direction == View.FOCUS_DOWN && selectablePosition < positionOfNewFocus)
                            || (direction == View.FOCUS_UP && selectablePosition > positionOfNewFocus))) {
                return null;
            }
        }

        int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus);

        final int maxScrollAmount = getMaxScrollAmount();
        if (focusScroll < maxScrollAmount) {
            // not moving too far, safe to give next view focus
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll);
            return mArrowScrollFocusResult;
        } else if (distanceToView(newFocus) < maxScrollAmount) {
            // Case to consider:
            // too far to get entire next focusable on screen, but by going
            // max scroll amount, we are getting it at least partially in view,
            // so give it focus and scroll the max ammount.
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount);
            return mArrowScrollFocusResult;
        }
    }
    return null;
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * WheelView?/*from www.j  a  v a 2  s  .  com*/
 *
 * @param childCount
 */
protected void correctTooLowForWheelView(int childCount) {
    //,????
    //???
    //??
    //???
    if (mFirstPosition == 0 && childCount > 0) {

        // ?
        final View firstChild = getChildAt(0);

        //?
        final int firstTop = firstChild.getTop();

        //?
        final int start = getTop();

        //?
        final int end = (getBottom() - getTop());

        //?
        int topOffset = firstTop - getYSel() + ((firstChild.getBottom() - firstChild.getTop()) / 2) - start;

        View lastChild = getChildAt(childCount - 1);

        final int lastBottom = lastChild.getBottom();

        int lastPosition = mFirstPosition + childCount - 1;

        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);
                }

                //??
                offsetChildrenTopAndBottom(-topOffset);
                //                    startScrollIfNeed(0, -topOffset);

                if (lastPosition < mItemCount - 1) {
                    // Fill the gap that was opened below the last position with more rows, if
                    // possible
                    fillDownView(lastPosition + 1, lastChild.getBottom() + mDividerHeight, 0);
                    // Close up the remaining gap
                    adjustViewsUpOrDown();
                }
            } else if (lastPosition == mItemCount - 1) {
                adjustViewsUpOrDown();
            }
        }
    }
}

From source file:com.zyk.drawerlayout.widget.DrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                continue;
            }/*from w ww.  j a v a2s . c  o  m*/

            if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                final int vright = v.getRight();
                if (vright > clipLeft)
                    clipLeft = vright;
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight)
                    clipRight = vleft;
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);
        canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
    } else if (mShadowLeftResolved != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
        final int shadowWidth = mShadowLeftResolved.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeftResolved.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeftResolved.setAlpha((int) (0xff * alpha));
        mShadowLeftResolved.draw(canvas);
    } else if (mShadowTopResolved != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
        final int shadowHeight = mShadowTopResolved.getIntrinsicHeight();
        final int childBottom = child.getBottom();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f));
        mShadowTopResolved.setBounds(child.getLeft(), childBottom, child.getRight(),
                childBottom + shadowHeight);
        mShadowTopResolved.setAlpha((int) (0xff * alpha));
        mShadowTopResolved.draw(canvas);
    } else if (mShadowRightResolved != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
        final int shadowWidth = mShadowRightResolved.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRightResolved.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRightResolved.setAlpha((int) (0xff * alpha));
        mShadowRightResolved.draw(canvas);
    } else if (mShadowBottomResolved != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        final int shadowHeight = mShadowBottomResolved.getIntrinsicHeight();
        final int childTop = child.getTop();
        final int showing = getWidth() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRightResolved.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowRightResolved.setAlpha((int) (0xff * alpha));
        mShadowRightResolved.draw(canvas);
    }
    return result;
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * ?//from   ww  w.  j av a2 s .c  o m
 *
 * @param yDelta
 */
protected boolean verticalScroll(int yDelta) {
    if (DEBUG)
        Log.i(TAG, "VerticalScroll " + yDelta);

    final int childCount = getChildCount();

    View firstChild = getChildAt(0);
    View lastChild = getChildAt(childCount - 1);

    int offScreenChildStart = 0;
    int offScreenChildCount = 0;

    if (yDelta > 0) {//
        for (int i = getChildCount() - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            if (child.getTop() + yDelta - mDividerHeight < (getBottom() - getTop())) {//
                break;
            } else {
                Log.i(TAG, "View OffScreen => " + i);
                offScreenChildStart = i;
                offScreenChildCount++;
                int position = mFirstPosition + i;
                mRecyclerBin.addRecyclerBin(position, child);
            }
        }
    } else if (yDelta < 0) {//?
        for (int i = 0; i < getChildCount(); i++) {
            final View child = getChildAt(i);
            if (child.getBottom() + yDelta + mDividerHeight > 0/*getTop()*/) {
                break;
            } else {
                Log.i(TAG, "View OffScreen => " + i);
                offScreenChildCount++;
                int position = mFirstPosition + i;
                mRecyclerBin.addRecyclerBin(position, child);
            }
        }
    } else {
        //Ignored
    }

    if (offScreenChildCount > 0) {
        //?
        detachViewsFromParent(offScreenChildStart, offScreenChildCount);
    }

    //?,
    //        if (yDelta < 0) {//
    //            //?,,??,
    //            if (mFirstPosition + getChildCount() == mItemCount) {
    //                int scrollMaxDistance = getChildAt(getChildCount() - 1).getBottom() - getBottom();
    //                yDelta = Math.max(-scrollMaxDistance, yDelta);
    //            }
    //        } else if (yDelta > 0) {//
    //            if (mFirstPosition == 0) {
    //                //,,??
    //                int scrollMaxDistance = getTop() - getChildAt(0).getTop();
    //                yDelta = Math.min(scrollMaxDistance, yDelta);
    //            }
    //        }

    if (!awakenScrollBars()) {
        invalidate();
    }

    offsetChildrenTopAndBottom(yDelta);

    if (yDelta < 0) {
        fillDownView(mFirstPosition + childCount, lastChild.getBottom() + mDividerHeight, offScreenChildCount);
        correctTooHigh(getChildCount());
    } else {
        fillUpView(mFirstPosition - 1, firstChild.getTop() - mDividerHeight);
        correctTooLow(getChildCount());
    }
    return yDelta != 0;
}