Example usage for android.view ViewGroup getTop

List of usage examples for android.view ViewGroup getTop

Introduction

In this page you can find the example usage for android.view ViewGroup getTop.

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

private static Rect getChildViewRect(final View parentView, final View childView) {
    Rect childRect = new Rect(childView.getLeft(), childView.getTop(), childView.getRight(),
            childView.getBottom());//w w w.j a  v a2  s .  com
    if (!parentView.equals(childView)) {
        View workingChildView = childView;
        ViewGroup parent;
        while (!(parent = (ViewGroup) workingChildView.getParent()).equals(parentView)) {
            childRect.offset(parent.getLeft(), parent.getTop());
            workingChildView = parent;
        }
    }
    return childRect;
}

From source file:com.haarman.listviewanimations.itemmanipulation.SwipeDismissListViewTouchListener.java

private Rect getChildViewRect(View parentView, View childView) {
    final Rect childRect = new Rect(childView.getLeft(), childView.getTop(), childView.getRight(),
            childView.getBottom());/*from  ww  w .  j a  va 2s .  co  m*/
    if (parentView == childView) {
        return childRect;

    }

    ViewGroup parent;
    while ((parent = (ViewGroup) childView.getParent()) != parentView) {
        childRect.offset(parent.getLeft(), parent.getTop());
        childView = parent;
    }

    return childRect;
}

From source file:org.chromium.chrome.browser.widget.animation.FocusAnimator.java

/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null)
        return;/* ww  w  . j  a v a  2  s .c  om*/

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null)
        parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax)
        parent.setScrollY(scrollMax);
}

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

/**
 * close surface/*from   www.ja  v  a2s .c om*/
 * @param smooth smoothly or not.
 * @param notify if notify all the listeners.
 */
public void close(boolean smooth, boolean notify) {
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if (smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if (notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        } else {
            safeBottomView();
        }
    }
    invalidate();
}

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

public void open(boolean smooth, boolean notify) {
    ViewGroup surface = getSurfaceView(), bottom = getBottomView();
    int dx, dy;//from w  ww  .ja v a  2s .c o m
    Rect rect = computeSurfaceLayoutArea(true);
    if (smooth) {
        mDragHelper.smoothSlideViewTo(getSurfaceView(), rect.left, rect.top);
    } else {
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if (getShowMode() == ShowMode.PullOut) {
            Rect bRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
            bottom.layout(bRect.left, bRect.top, bRect.right, bRect.bottom);
        }
        if (notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        } else {
            safeBottomView();
        }
    }
    invalidate();
}

From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java

private boolean anyChildWantMotionEvent(MotionEvent ev, ViewGroup group) {
    MotionEvent event = MotionEvent.obtain(ev);
    event.offsetLocation(-group.getLeft(), -group.getTop());
    //view//from   ww w .j  av a  2  s.c  o m
    int childCount = group.getChildCount();
    final float x = event.getX();
    final float y = event.getY();

    for (int i = 0; i < childCount; i++) {
        View child = group.getChildAt(i);
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) {
            if (child instanceof ViewGroup) {
                MotionEvent chileEvent = MotionEvent.obtain(event);
                chileEvent.offsetLocation(-child.getLeft(), -child.getTop());
                if (anyChildWantMotionEvent(chileEvent, (ViewGroup) child)) {
                    chileEvent.recycle();
                    return true;
                }
            } else if (child.onTouchEvent(event)) {
                return true;
            }
        }
    }
    event.recycle();
    return false;
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Open the drawer view by animating it into view.
 *///w ww  .j a  va 2s .  c  om
public void openDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    mStartedOpen = false;

    if (hasWindowFocus()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart();
        } else {
            left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerOpening(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        dispatchOnDrawerOpened(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    View focusable = drawerView.getChildAt(0);
    if (focusable != null) {
        focusable.requestFocus();
    }
    invalidate();
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Close the specified drawer view by animating it into view.
 *///from ww  w  . j  av a  2  s . c o  m
public void closeDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }
    mStartedOpen = true;

    // Don't trigger the close drawer animation if drawer is not open.
    if (hasWindowFocus() && isDrawerOpen()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart() - drawerView.getWidth();
        } else {
            left = drawerLp.getMarginStart() + getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerClosing(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 0.f;
        dispatchOnDrawerClosed(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    if (!isInTouchMode()) {
        List<View> focusables = contentView.getFocusables(FOCUS_DOWN);
        if (focusables.size() > 0) {
            View candidate = focusables.get(0);
            candidate.requestFocus();
        }
    }
    invalidate();
}

From source file:com.android.argb.edhlc.Utils.java

public static void makeViewVisible(View view) {
    int viewTop = view.getTop();
    int viewBottom = view.getBottom();

    for (;;) {/*from w  ww.j  av a2 s  .  com*/
        ViewParent viewParent = view.getParent();
        if (viewParent == null || !(viewParent instanceof ViewGroup))
            break;

        ViewGroup viewGroupParent = (ViewGroup) viewParent;
        if (viewGroupParent instanceof NestedScrollView) {

            NestedScrollView nestedScrollView = (NestedScrollView) viewGroupParent;
            int height = nestedScrollView.getHeight();
            int screenTop = nestedScrollView.getScrollY();
            int screenBottom = screenTop + height;
            int fadingEdge = nestedScrollView.getVerticalFadingEdgeLength();

            // leave room for top fading edge as long as rect isn't at very top
            if (viewTop > 0)
                screenTop += fadingEdge;

            // leave room for bottom fading edge as long as rect isn't at very bottom
            if (viewBottom < nestedScrollView.getChildAt(0).getHeight())
                screenBottom -= fadingEdge;

            int scrollYDelta = 0;

            if (viewBottom > screenBottom && viewTop > screenTop) {
                // 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 (viewBottom - viewTop > height) // just enough to get screen size chunk on
                    scrollYDelta += (viewTop - screenTop);
                else // get entire rect at bottom of screen
                    scrollYDelta += (viewBottom - screenBottom);

                // make sure we aren't scrolling beyond the end of our content
                int bottom = nestedScrollView.getChildAt(0).getBottom();
                int distanceToBottom = bottom - screenBottom;
                scrollYDelta = Math.min(scrollYDelta, distanceToBottom);

            } else if (viewTop < screenTop && viewBottom < screenBottom) {
                // 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 (viewBottom - viewTop > height) // screen size chunk
                    scrollYDelta -= (screenBottom - viewBottom);
                else // entire rect at top
                    scrollYDelta -= (screenTop - viewTop);

                // make sure we aren't scrolling any further than the top our content
                scrollYDelta = Math.max(scrollYDelta, -nestedScrollView.getScrollY());
            }
            nestedScrollView.smoothScrollBy(0, scrollYDelta);
            break;
        }
        // Transform coordinates to parent:
        int dy = viewGroupParent.getTop() - viewGroupParent.getScrollY();
        viewTop += dy;
        viewBottom += dy;

        view = viewGroupParent;
    }
}

From source file:com.isapp.android.circularviewpager.CircularViewPager.java

private Rect getChildRectInPagerCoordinates(Rect outRect, View child) {
    if (outRect == null) {
        outRect = new Rect();
    }//from   ww w. j  ava  2 s. c  o m
    if (child == null) {
        outRect.set(0, 0, 0, 0);
        return outRect;
    }
    outRect.left = child.getLeft();
    outRect.right = child.getRight();
    outRect.top = child.getTop();
    outRect.bottom = child.getBottom();
    ViewParent parent = child.getParent();
    while (parent instanceof ViewGroup && parent != this) {
        final ViewGroup group = (ViewGroup) parent;
        outRect.left += group.getLeft();
        outRect.right += group.getRight();
        outRect.top += group.getTop();
        outRect.bottom += group.getBottom();
        parent = group.getParent();
    }
    return outRect;
}