Example usage for android.view ViewGroup getChildAt

List of usage examples for android.view ViewGroup getChildAt

Introduction

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

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:com.cooper.redditvideo.CustomSlidingPaneLayout.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 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.
 */// w w w. j a v a  2 s. c  o  m
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;
            }
        }
    }

    /* special case ViewPagers, which don't properly implement the scrolling interface */
    return checkV && (ViewCompat.canScrollHorizontally(v, -dx)
            || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)));
}

From source file:com.example.CustomSlidingPaneLayout.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 dx Delta scrolled in pixels/*from  w  w w .ja v a2 s .co  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 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;
            }
        }
    }
    return checkV && (ViewCompat.canScrollHorizontally(v, -dx)
            || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)));
}

From source file:com.android.calendar.event.EditEventView.java

private void addFieldsRecursive(StringBuilder b, View v) {
    if (v == null || v.getVisibility() != View.VISIBLE) {
        return;/* w  w  w.ja  va2s.  c  o  m*/
    }
    if (v instanceof TextView) {
        CharSequence tv = ((TextView) v).getText();
        if (!TextUtils.isEmpty(tv.toString().trim())) {
            b.append(tv + PERIOD_SPACE);
        }
    } else if (v instanceof RadioGroup) {
        RadioGroup rg = (RadioGroup) v;
        int id = rg.getCheckedRadioButtonId();
        if (id != View.NO_ID) {
            b.append(((RadioButton) (v.findViewById(id))).getText() + PERIOD_SPACE);
        }
    } else if (v instanceof Spinner) {
        Spinner s = (Spinner) v;
        if (s.getSelectedItem() instanceof String) {
            String str = ((String) (s.getSelectedItem())).trim();
            if (!TextUtils.isEmpty(str)) {
                b.append(str + PERIOD_SPACE);
            }
        }
    } else if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;
        int children = vg.getChildCount();
        for (int i = 0; i < children; i++) {
            addFieldsRecursive(b, vg.getChildAt(i));
        }
    }
}

From source file:com.android.launcher2.AsyncTaskCallback.java

private void setVisibilityOnChildren(ViewGroup layout, int visibility) {
    int childCount = layout.getChildCount();
    for (int i = 0; i < childCount; ++i) {
        layout.getChildAt(i).setVisibility(visibility);
    }/*from ww  w.j  a  v a 2  s .  c o m*/
}

From source file:com.cylee.dragcontentviewpager.ViewDragHelper.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).//from   w  w w. j a  v a2  s  .c  om
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @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 dy, int x, int y) {
    if (v instanceof ViewGroup) {
        if (v instanceof AbsListView && Math.abs(dy) > Math.abs(dx)) {
            if (Build.VERSION.SDK_INT >= 19) {
                return ((AbsListView) v).canScrollList(-dy);
            }
            return true;
        }
        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,
                            checkV, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.scurab.android.anuitorsample.widget.SlidingPaneLayout.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 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.
 *//*from  ww w.  j a v  a2  s.  c  om*/
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;
            }
        }
    }

    if (HACK_MOD) {
        return checkV && (ViewCompat.canScrollHorizontally(v, -dx)
                || (((v instanceof HorizontallySwipable))
                        && ((HorizontallySwipable) v).canScrollHorizontally(-dx))
                || (((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx))));

    } else {
        return checkV && ViewCompat.canScrollHorizontally(v, -dx);
    }
}

From source file:com.baidayi.swipback.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * //from  w  ww.  j a  v  a  2 s .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 along the X axis
 * @param dy
 *            Delta scrolled in pixels along the Y axis
 * @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 dy, 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--) {
            // 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy));
}

From source file:com.aretha.slidemenu.SlideMenu.java

/**
 * Resolve the attribute slideMode/*from  w  ww.  j a  va  2  s . c  o m*/
 */
protected void resolveSlideMode() {
    final ViewGroup decorView = (ViewGroup) getRootView();
    final ViewGroup contentContainer = (ViewGroup) decorView.findViewById(android.R.id.content);
    final View content = mContent;
    if (null == decorView || null == content || 0 == getChildCount()) {
        return;
    }

    TypedValue value = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.windowBackground, value, true);

    switch (mSlideMode) {
    case MODE_SLIDE_WINDOW: {
        // remove this view from parent
        removeViewFromParent(this);
        // copy the layoutparams of content
        LayoutParams contentLayoutParams = new LayoutParams(content.getLayoutParams());
        // remove content view from this view
        removeViewFromParent(content);
        // add content to layout root view
        contentContainer.addView(content);

        // get window with ActionBar
        View decorChild = decorView.getChildAt(0);
        decorChild.setBackgroundResource(0);
        removeViewFromParent(decorChild);
        addView(decorChild, contentLayoutParams);

        // add this view to root view
        decorView.addView(this);
        setBackgroundResource(value.resourceId);
    }
        break;
    case MODE_SLIDE_CONTENT: {
        // remove this view from decor view
        setBackgroundResource(0);
        removeViewFromParent(this);
        // get the origin content view from the content wrapper
        View originContent = contentContainer.getChildAt(0);
        // this is the decor child remove from decor view
        View decorChild = mContent;
        LayoutParams layoutParams = (LayoutParams) decorChild.getLayoutParams();
        // remove the origin content from content wrapper
        removeViewFromParent(originContent);
        // remove decor child from this view
        removeViewFromParent(decorChild);
        // restore the decor child to decor view
        decorChild.setBackgroundResource(value.resourceId);
        decorView.addView(decorChild);
        // add this view to content wrapper
        contentContainer.addView(this);
        // add the origin content to this view
        addView(originContent, layoutParams);
    }
        break;
    }
}

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   w  w w.  j av  a  2s . 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:cn.xm.xmvideoplayer.widget.swipebacklayout.ViewDragHelper.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 dx     Delta scrolled in pixels along the X axis
 * @param dy     Delta scrolled in pixels along the Y axis
 * @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.
 *//*  w w  w  .  j a  v a 2 s .c om*/
protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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--) {
            // 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy));
}