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:Main.java

private static void setDialogFontSize(View view, int size) {
    if (view instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) view;
        int count = parent.getChildCount();
        for (int i = 0; i < count; i++) {
            setDialogFontSize(parent.getChildAt(i), size);
        }/*from   ww w.j a v a2s .c om*/
    } else if (view instanceof TextView) {
        TextView textview = (TextView) view;
        textview.setTextSize(size);
    }
}

From source file:Main.java

/**
 * Invalidates a view and all of its descendants.
 *///from   www . ja  v a 2s  . c  o m
private static void recursiveInvalidate(View view) {
    view.invalidate();
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        int childCount = group.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = group.getChildAt(i);
            if (child.getVisibility() == View.VISIBLE) {
                recursiveInvalidate(child);
            }
        }
    }
}

From source file:Main.java

public static void clearAllEdits(ViewGroup group) {
    if (group != null) {
        int count = group.getChildCount();
        for (int i = 0; i < count; ++i) {
            View view = group.getChildAt(i);
            if (view instanceof EditText) {
                ((EditText) view).setText("");
            } else if (view instanceof LinearLayout) {
                clearAllEdits((ViewGroup) view);
            }//from   w w w  . j a  va2  s.co m
        }
    }
}

From source file:Main.java

public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = viewGroup.getChildAt(i);
        if (view.isFocusable())
            view.setEnabled(enabled);/*  w  w  w . j a  va  2s  .c om*/
        if (view instanceof ViewGroup) {
            enableDisableViewGroup((ViewGroup) view, enabled);
        } else if (view instanceof ListView) {
            if (view.isFocusable())
                view.setEnabled(enabled);
            ListView listView = (ListView) view;
            int listChildCount = listView.getChildCount();
            for (int j = 0; j < listChildCount; j++) {
                if (view.isFocusable())
                    listView.getChildAt(j).setEnabled(false);
            }
        }
    }
}

From source file:Main.java

/**
 * Gets a list of all views of a given type, rooted at the given parent.
 * <p>/*  ww w.ja  va 2s .  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 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. ja va  2s .  c om
        }
    } else {
        translateViewForParallaxEffect(view, 0, offsetPixels, startParallaxFactor, parallaxInterval);
    }
}

From source file:com.mobicage.rogerthat.util.TextUtils.java

public static void overrideFonts(final Context context, final View v) {
    try {//w w w .  j a va  2s . com
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                overrideFonts(context, child);
            }
        } else if (v instanceof EditText) {
            ((EditText) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_light.ttf"));
            ((EditText) v).setTextColor(ContextCompat.getColor(context, R.color.mc_words_color));
        } else if (v instanceof Button) {
            ((Button) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_bold.ttf"));
            ((Button) v).setTextColor(ContextCompat.getColor(context, android.R.color.white));
        } else if (v instanceof TextView) {
            ((TextView) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/lato_light.ttf"));
            ((TextView) v).setTextColor(ContextCompat.getColor(context, R.color.mc_words_color));
        }
    } 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   w  w w  .ja v  a2  s  . com*/
 * @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);
        }
    }
}

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  w w  w .j a v a2 s .c om
    } else {
        translateViewForParallaxEffect(view, index, offsetPixels, startParallaxFactor, parallaxInterval);
        nextIndex++;
    }
    return nextIndex;
}

From source file:Main.java

public static void recycleViewGroup(ViewGroup layout) {
    if (layout == null)
        return;/*from  w  w  w  .  j  a  v a 2  s  .  c o m*/
    synchronized (layout) {
        for (int i = 0; i < layout.getChildCount(); i++) {
            View subView = layout.getChildAt(i);
            if (subView instanceof ViewGroup) {
                recycleViewGroup((ViewGroup) subView);
            } else {
                if (subView instanceof ImageView) {
                    recycleImageView((ImageView) subView);
                }
            }
        }
    }
}