Example usage for android.view View getLeft

List of usage examples for android.view View getLeft

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getLeft() 

Source Link

Document

Left position of this view relative to its parent.

Usage

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

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }/*from w w  w . ja  va2 s  .c  o  m*/
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToTop = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToTop);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getLeft();
        invalidate();
    }
    return scroll;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectLeftWithinChild = rect.left;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectLeftWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }/*from  ww w.j  a va2 s.  c o  m*/
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.right < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToLeft = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToLeft);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getTop();
        invalidate();
    }
    return scroll;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Layout a child that has been measured, preserving its top position. TODO: unify with setUpChild.
 * /*ww w. java  2s  .  c o  m*/
 * @param child
 *           The child.
 */
private void relayoutMeasuredItem(View child) {
    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();

    final int childTop = mListPadding.top;
    final int childBottom = childTop + h;

    final int childLeft = child.getLeft();
    final int childRight = childLeft + w;

    child.layout(childLeft, childTop, childRight, childBottom);
}

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

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int height = getHeight();
    int listUnfadedTop = getScrollY();
    int listUnfadedBottom = listUnfadedTop + height;
    final int fadingEdge = getVerticalFadingEdgeLength();

    if (showingTopFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedTop += fadingEdge;
        }/*from   w w  w . jav a 2  s  .  c o m*/
    }

    int childCount = getChildCount();
    int bottomOfBottomChild = getChildAt(childCount - 1).getBottom();

    if (showingBottomFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (bottomOfBottomChild - fadingEdge))) {
            listUnfadedBottom -= fadingEdge;
        }
    }

    int scrollYDelta = 0;

    if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.height() > height) {
            // just enough to get screen size chunk on
            scrollYDelta += (rect.top - listUnfadedTop);
        } else {
            // get entire rect at bottom of screen
            scrollYDelta += (rect.bottom - listUnfadedBottom);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToBottom = bottomOfBottomChild - listUnfadedBottom;
        scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
    } else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.height() > height) {
            // screen size chunk
            scrollYDelta -= (listUnfadedBottom - rect.bottom);
        } else {
            // entire rect at top
            scrollYDelta -= (listUnfadedTop - rect.top);
        }

        // make sure we aren't scrolling any further than the top our children
        int top = getChildAt(0).getTop();
        int deltaToTop = top - listUnfadedTop;
        scrollYDelta = Math.max(scrollYDelta, deltaToTop);
    }

    final boolean scroll = scrollYDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollYDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedTop = child.getTop();
        invalidate();
    }
    return scroll;
}

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

/**
 * Make sure views are touching the top or bottom edge, as appropriate for
 * our gravity//from   w w  w  .ja  v  a 2  s . c o  m
 */
private void adjustViewsLeftOrRight() {
    final int childCount = getChildCount();
    int delta;

    if (childCount > 0) {
        View child;

        if (!mStackFromRight) {
            // Uh-oh -- we came up short. Slide all views up to make them
            // align with the top
            child = getChildAt(0);
            delta = child.getLeft() - mListPadding.left;
            if (mFirstPosition != 0) {
                // It's OK to have some space above the first item if it is
                // part of the vertical spacing
                delta -= mDividerWidth;
            }
            if (delta < 0) {
                // We only are looking to see if we are too low, not too high
                delta = 0;
            }
        } else {
            // we are too high, slide all views down to align with bottom
            child = getChildAt(childCount - 1);
            delta = child.getRight() - (getWidth() - mListPadding.right);

            if (mFirstPosition + childCount < mItemCount) {
                // It's OK to have some space below the last item if it is
                // part of the vertical spacing
                delta += mDividerWidth;
            }

            if (delta > 0) {
                delta = 0;
            }
        }

        if (delta != 0) {
            offsetChildrenLeftAndRightUnhide(-delta);
        }
    }
}

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

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.mBehavior != null) {
        final float scrimAlpha = lp.mBehavior.getScrimOpacity(this, child);
        if (scrimAlpha > 0f) {
            if (mScrimPaint == null) {
                mScrimPaint = new Paint();
            }// w  ww .  j a  v  a2s.  co m
            mScrimPaint.setColor(lp.mBehavior.getScrimColor(this, child));
            mScrimPaint.setAlpha(MathUtils.constrain(Math.round(255 * scrimAlpha), 0, 255));

            final int saved = canvas.save();
            if (child.isOpaque()) {
                // If the child is opaque, there is no need to draw behind it so we'll inverse
                // clip the canvas
                canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(),
                        Region.Op.DIFFERENCE);
            }
            // Now draw the rectangle for the scrim
            canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                    getHeight() - getPaddingBottom(), mScrimPaint);
            canvas.restoreToCount(saved);
        }
    }
    return super.drawChild(canvas, child, drawingTime);
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Make sure views are touching the top or bottom edge, as appropriate for our gravity
 *///from w  w w. j  ava2s. co m
private void adjustViewsLeftOrRight() {
    final int childCount = getChildCount();
    int delta;

    if (childCount > 0) {
        View child;

        if (!mStackFromRight) {
            // Uh-oh -- we came up short. Slide all views up to make them
            // align with the top
            child = getChildAt(0);
            delta = child.getLeft() - mListPadding.left;
            if (mFirstPosition != 0) {
                // It's OK to have some space above the first item if it is
                // part of the vertical spacing
                delta -= mDividerWidth;
            }
            if (delta < 0) {
                // We only are looking to see if we are too low, not too high
                delta = 0;
            }
        } else {
            // we are too high, slide all views down to align with bottom
            child = getChildAt(childCount - 1);
            delta = child.getRight() - (getWidth() - mListPadding.right);

            if (mFirstPosition + childCount < mItemCount) {
                // It's OK to have some space below the last item if it is
                // part of the vertical spacing
                delta += mDividerWidth;
            }

            if (delta > 0) {
                delta = 0;
            }
        }

        if (delta != 0) {
            offsetChildrenLeftAndRight(-delta);
        }
    }
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Log.i(TAG, "drawChild()");
    final int width = getWidth();
    final boolean drawingContent = isContentView(child);
    int clipTop = 0;
    int clipBottom = getHeight();

    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.getWidth() < width) {
                Log.i(TAG, "drawChild() -- 0");
                continue;
            }/* www . j  ava2 s  . c  o  m*/
            if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                final int vbottom = v.getBottom();
                if (vbottom > clipTop)
                    clipTop = vbottom;
            } else {
                final int vtop = v.getTop();
                if (vtop < clipBottom) {
                    clipBottom = vtop;
                }
            }
        }
        canvas.clipRect(0, clipTop, getWidth(), clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        Log.i(TAG, "drawChild() -- 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(0, clipTop, getWidth(), clipBottom, mScrimPaint);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        Log.i(TAG, "drawChild() -- Gravity.BOTTOM");
        final int shadowHeight = mShadowBottom.getIntrinsicWidth();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowBottom.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowBottom.setAlpha((int) (0xff * alpha));
        mShadowBottom.draw(canvas);
    }
    return result;
}

From source file:com.android.internal.widget.ViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns.// w  w  w.j  a  va 2  s  .  c  o  m
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getPaddedWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

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

@Override
int findMotionCol(int x) {
    int childCount = getChildCount();
    if (childCount > 0) {
        if (!mStackFromRight) {
            for (int i = 0; i < childCount; i++) {
                View v = getChildAt(i);
                if (x <= v.getRight()) {
                    return mFirstPosition + i;
                }/*from   w w w  .java2s  .c  o m*/
            }
        } else {
            for (int i = childCount - 1; i >= 0; i--) {
                View v = getChildAt(i);
                if (x >= v.getLeft()) {
                    return mFirstPosition + i;
                }
            }
        }
    }
    return INVALID_POSITION;
}