Example usage for android.view ViewGroup getChildCount

List of usage examples for android.view ViewGroup getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:Main.java

public static <X extends View> X getChild(ViewGroup row, Class<X> klass) {
    assert klass != null;
    for (int i = 0; i < row.getChildCount(); i++) {
        View child = row.getChildAt(i);
        if (klass.isAssignableFrom(child.getClass())) {
            return klass.cast(child);
        }/*www. j a v a 2 s . c  o m*/

        if (child instanceof ViewGroup) {
            X kid = getChild((ViewGroup) child, klass);
            if (kid != null)
                return kid;
        }
    }
    // fail
    return null;
}

From source file:Main.java

private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (contentView.getChildCount() > 1) {
        contentView.removeViewAt(1);/*  w  w w .  j  av  a 2s  . co m*/
    }
    contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
}

From source file:Main.java

/**
 * Gets a list of all views of a given type, rooted at the given parent.
 * <p>/*from   www.j a va  2  s  . co m*/
 * This method will recurse down through all {@link ViewGroup} instances looking for
 * {@link View} instances of the supplied class type. Specifically it will use the
 * {@link Class#isAssignableFrom(Class)} method as the test for which views to add to the list,
 * so if you provide {@code View.class} as your type, you will get every view. The parent itself
 * will be included also, should it be of the right type.
 * <p>
 * This call manipulates the ui, and as such should only be called from the application's main
 * thread.
 */
private static <T extends View> List<T> getAllViews(final Class<T> clazz, final View parent) {
    List<T> results = new ArrayList<T>();
    if (parent.getClass().equals(clazz)) {
        results.add(clazz.cast(parent));
    }
    if (parent instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) parent;
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            results.addAll(getAllViews(clazz, viewGroup.getChildAt(i)));
        }
    }
    return results;
}

From source file:Main.java

private static View getFirstChildByClassName(ViewGroup parent, String name) {
    View retView = null;//from  ww w  . j a  v  a  2  s. c om
    int childCount = parent.getChildCount();

    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        View child = parent.getChildAt(childIndex);

        if (child.getClass().getName().equals(name)) {
            return child;
        }

        if (child instanceof ViewGroup) {
            View v = getFirstChildByClassName((ViewGroup) child, name);

            if (v != null) {
                return v;
            }
        }
    }

    return retView;
}

From source file:Main.java

private static <T extends View> T getFirstChildByInstance(ViewGroup parent, Class<T> instance) {
    View retView = null;/*from  ww  w .j a v a2 s.co  m*/
    int childCount = parent.getChildCount();

    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        View child = parent.getChildAt(childIndex);

        if (instance.isAssignableFrom(child.getClass())) {
            return instance.cast(child);
        }

        if (child instanceof ViewGroup) {
            View v = getFirstChildByInstance((ViewGroup) child, instance);

            if (v != null) {
                return instance.cast(v);
            }
        }
    }

    return instance.cast(retView);
}

From source file:Main.java

private static void applyParallaxEffectToImmediateChildren(View view, int offsetPixels,
        float startParallaxFactor, float parallaxInterval) {
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            translateViewForParallaxEffect(group.getChildAt(i), i, offsetPixels, startParallaxFactor,
                    parallaxInterval);//from w  w w  . j a  v a  2  s  . c  om
        }
    } else {
        translateViewForParallaxEffect(view, 0, offsetPixels, startParallaxFactor, parallaxInterval);
    }
}

From source file:Main.java

private static void cleanViewGroup(View view) {
    if (view != null) {
        if (view instanceof ViewGroup)
            try {
                ViewGroup viewGroup = (ViewGroup) view;
                int childCount = viewGroup.getChildCount();
                for (int index = 0; index < childCount; index++) {
                    View child = viewGroup.getChildAt(index);
                    cleanViewGroup(child);
                }/*from w w  w  .  j  a v  a  2  s .c  o  m*/
            } catch (Exception e) {
            }

        cleanView(view);
    }
}

From source file:Main.java

private static int applyParallaxEffectRecursively(View view, int offsetPixels, float startParallaxFactor,
        float parallaxInterval, int index) {
    int nextIndex = index;
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            nextIndex = applyParallaxEffectRecursively(group.getChildAt(i), offsetPixels, startParallaxFactor,
                    parallaxInterval, nextIndex);
        }//from  ww w  .  ja  v a  2 s .c  o m
    } else {
        translateViewForParallaxEffect(view, index, offsetPixels, startParallaxFactor, parallaxInterval);
        nextIndex++;
    }
    return nextIndex;
}

From source file:Main.java

public static void unBindDrawables(View view) {
    if (view != null) {
        try {/*  w ww .  j  av  a  2s .co  m*/
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
                ViewGroup viewGroup = (ViewGroup) view;
                int viewGroupChildCount = viewGroup.getChildCount();
                for (int j = 0; j < viewGroupChildCount; j++) {
                    unBindDrawables(viewGroup.getChildAt(j));
                }
                viewGroup.removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:Main.java

/**
 * Helps to find recursivly all visible childs in a view group.
 *
 * @param viewGroup     View group./*from  www.ja  v a  2 s  . c  om*/
 * @param ordoredChilds Childs list where visible childs will be added.
 */
static void findAllVisibleChilds(final ViewGroup viewGroup, final List<View> ordoredChilds) {
    for (int childViewIndex = 0; childViewIndex < viewGroup.getChildCount(); childViewIndex++) {
        final View childView = viewGroup.getChildAt(childViewIndex);
        if (childView instanceof ViewGroup) {
            findAllVisibleChilds((ViewGroup) childView, ordoredChilds);
            continue;
        }
        if (childView.getVisibility() == View.VISIBLE) {
            ordoredChilds.add(childView);
        }
    }
}