Example usage for android.view View getScrollX

List of usage examples for android.view View getScrollX

Introduction

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

Prototype

public final int getScrollX() 

Source Link

Document

Return the scrolled left position of this view.

Usage

From source file:com.guide.ViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*from  w w  w .j a  va 2s .  c  o  m*/
 * @param v
 *            View to test for horizontal scrollability
 * @param checkV
 *            Whether the view v passed should itself be checked for
 *            scrollability (true), or just its children (false).
 * @param dx
 *            Delta scrolled in pixels
 * @param x
 *            X coordinate of the active touch point
 * @param y
 *            Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance
        // first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    boolean canScroll = false;
    if (isOrientationHorizontal()) {
        canScroll = ViewCompat.canScrollHorizontally(v, -dx);
    } else {
        canScroll = ViewCompat.canScrollVertically(v, -dx);
    }
    return checkV && canScroll;
}

From source file:android.improving.utils.views.cardsview.OrientedViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param delta  Delta scrolled in pixels
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 *///from   w w w  .j  a  va2 s. com
protected boolean canScroll(View v, boolean checkV, int delta, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (mOrientation == Orientation.VERTICAL) {
                if (y + scrollY >= child.getTop() && y + scrollY < child.getBottom()
                        && x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && canScroll(child,
                                true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                    return true;
                }
            } else {
                if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                        && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                                true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                    return true;
                }
            }
        }
    }

    return checkV && ViewCompat.canScrollVertically(v, -delta);
}

From source file:dev.dworks.libs.widget.ViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param d Delta scrolled in pixels/*from   www.j  a v a  2 s.c o m*/
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int d, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom()
                    && canScroll(child, true, d, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    boolean canScroll;
    if (mOrientation == HORIZONTAL) {
        canScroll = checkV && ViewCompat.canScrollHorizontally(v, -d);
    } else {
        canScroll = checkV && ViewCompat.canScrollVertically(v, -d);
    }
    return canScroll;
}

From source file:org.bangbang.support.v4.widget.HListView.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.  j  a  v  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(child);
            mSelectedTop = child.getTop();
            invalidate();
        }
        return scroll;
    }

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;
        }/* w w w.  j  av  a 2  s  . co 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  w w  w .  ja v a  2 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.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 ww .  j  av a 2  s  . com*/
    }

    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:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * NOTE This method is borrowed from {@link ScrollView}.
 *///from  www  .  ja v a2 s  .c o m
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
    // offset into coordinate space of this scroll view
    rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());

    return scrollToChildRect(rectangle, immediate);
}

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

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw//w w  w  .  j a  v  a2  s  .c  o  m
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = getTextViewIcon((TextView) v);
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

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

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw/*  w  w w.  jav a2 s .  c om*/
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}