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:au.com.glassechidna.velocityviewpager.VelocityViewPager.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 .  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 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);
}

From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.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  .  jav 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 dx, int x, int y) {
    if (!canScroll)
        return true;

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

From source file:com.tjych.swip.vertical.DirectionalViewPager.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  .  j a  va  2s  .  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 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--) {
            // 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

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

From source file:com.minoon.stackviewpagersample.StackViewPager.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// ww  w . j ava2s. 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 dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        // [Changed]
        //            final int scrollX = v.getScrollX();
        final int scrollX = (int) v.getTranslationX();
        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);
}

From source file:com.telerik.examples.primitives.ExampleViewPagerBase.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 w ww .j  a  va  2s .  co 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 scroll = getScroll(v);
        final int invertedScroll = getInvertedScroll(v);
        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 + scroll >= getStart(child) && x + scroll < getEnd(child)
                    && y + invertedScroll >= getInvertedStart(child)
                    && y + invertedScroll < getInvertedEnd(child) && canScroll(child, true, dx,
                            x + scroll - getStart(child), y + invertedScroll - getInvertedStart(child))) {
                return true;
            }
        }
    }

    return checkV && getCanScroll(v, -dx);
}

From source file:com.cairoconfessions.MainActivity.java

public View addConfession(String confess, String desc) {
    final ViewGroup confession = (ViewGroup) LayoutInflater.from(this)
            .inflate(R.layout.confession_list_item_example, null);
    final TextView newConfess = (TextView) confession.findViewById(R.id.text_main);
    newConfess.setText(confess);// ww w.  java  2  s .c  o  m
    final float scale = getResources().getDisplayMetrics().density;
    if (!desc.equals("")) {
        confession.setContentDescription(desc);
        if (desc.equals("Love"))
            newConfess.setBackgroundResource(R.color.love);
        if (desc.equals("Pain"))
            newConfess.setBackgroundResource(R.color.pain);
        if (desc.equals("Guilt"))
            newConfess.setBackgroundResource(R.color.guilt);
        if (desc.equals("Fantasy"))
            newConfess.setBackgroundResource(R.color.fantasy);
        if (desc.equals("Dream"))
            newConfess.setBackgroundResource(R.color.dream);
    } else {
        switch ((new Random().nextInt(5)) % 5) {
        case 0:
            newConfess.setBackgroundResource(R.color.love);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Love");
            break;
        case 1:
            newConfess.setBackgroundResource(R.color.pain);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
            confession.setContentDescription("Pain");
            break;
        case 2:
            newConfess.setBackgroundResource(R.color.guilt);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Guilt");
            break;
        case 3:
            newConfess.setBackgroundResource(R.color.fantasy);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Fantasy");
            break;
        case 4:
            newConfess.setBackgroundResource(R.color.dream);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Dream");
            break;
        }
    }
    switch ((new Random().nextInt(3)) % 3) {
    case 0:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
        break;
    case 1:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
        break;
    case 2:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
        break;
    }
    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setDuration(1000);
    confession.setAnimation(fadeIn);
    confession.getChildAt(0).setPadding((int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f),
            (int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f));
    confession.getChildAt(0).setBackgroundResource(R.drawable.border);
    mPager.setCurrentItem(1);
    if (!desc.equals("")) {
        ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
    } else {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {

                ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
                ((LinearLayout) findViewById(R.id.confession_list)).post(new Runnable() {

                    public void run() {
                        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
                    }
                });
            }
        }, 1000);
    }
    return confession;

}

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.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 dx Delta scrolled in pixels/*from w  ww.j  a v  a  2  s . c om*/
 * @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:com.viewpagerindicator.MyDirectionalViewPager.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 dposition 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 va  2 s. c  o  m*/
protected boolean canScroll(View v, boolean checkV, int dposition, 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, dposition, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    if (mOrientation == HORIZONTAL) {
        return checkV && ViewCompat.canScrollHorizontally(v, -dposition);
    } else {
        return checkV && ViewCompat.canScrollVertically(v, -dposition);
    }
}

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  v a2s  .  c o m
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:com.guide.ViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * //w  ww  . j  a v a  2s.c  om
 * @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;
}