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:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

private static ImageView findOverflowMenuButton(Activity activity, ViewGroup viewGroup) {
    if (viewGroup == null) {
        return null;
    }/*from  ww  w.jav  a 2s. com*/
    ImageView overflow = null;
    for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
        View v = viewGroup.getChildAt(i);
        if (v instanceof ImageView && (v.getClass().getSimpleName().equals("OverflowMenuButton")
                || v instanceof ActionMenuView.ActionMenuChildView)) {
            overflow = (ImageView) v;
        } else if (v instanceof ViewGroup) {
            overflow = findOverflowMenuButton(activity, (ViewGroup) v);
        }
        if (overflow != null) {
            break;
        }
    }
    return overflow;
}

From source file:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 * ??//from w w  w. j a v a 2 s.com
 *
 * @param activity       ?activity
 * @param color          ??
 * @param statusBarAlpha ???
 */

public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        int count = decorView.getChildCount();
        if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
            decorView.getChildAt(count - 1).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            StatusBarView statusView = createStatusBarView(activity, color, statusBarAlpha);
            decorView.addView(statusView);
        }
        setRootView(activity);
    }
}

From source file:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 * DrawerLayout ???//w  w w.  j a v  a  2s.com
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
        int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // ????
    //  statusBarView 
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
        contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        StatusBarView statusBarView = createStatusBarView(activity, color);
        contentLayout.addView(statusBarView, 0);
    }
    // ? LinearLayout ,padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(),
                getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(),
                contentLayout.getPaddingBottom());
    }
    // 
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);

    addTranslucentView(activity, statusBarAlpha);
}

From source file:biz.bokhorst.xprivacy.Util.java

public static List<View> getViewsByTag(ViewGroup root, String tag) {
    List<View> views = new ArrayList<View>();
    for (int i = 0; i < root.getChildCount(); i++) {
        View child = root.getChildAt(i);

        if (child instanceof ViewGroup)
            views.addAll(getViewsByTag((ViewGroup) child, tag));

        if (tag.equals(child.getTag()))
            views.add(child);/*from   w  w w.  j a  v  a  2s. c o  m*/
    }
    return views;
}

From source file:es.usc.citius.servando.calendula.fragments.MedicineCreateOrEditFragment.java

private static ArrayList<View> getViewsByTag(ViewGroup root, String tag) {
    ArrayList<View> views = new ArrayList<View>();
    final int childCount = root.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = root.getChildAt(i);
        if (child instanceof ViewGroup) {
            views.addAll(getViewsByTag((ViewGroup) child, tag));
        }//from   w w w  .ja va2 s  . c  o m

        final Object tagObj = child.getTag();
        if (tagObj != null && tagObj.equals(tag)) {
            views.add(child);
        }

    }
    return views;
}

From source file:me.anon.lib.Views.java

/**
 * Gets all views of a parent that match an class (recursive)
 * @param parent The parent view/* www . j  a  va2 s.c  om*/
 * @param instance The class to check
 * @return An array of views
 */
public static <T extends View> List<T> findAllChildrenByClass(ViewGroup parent, Class<T> instance) {
    List<View> views = new ArrayList<View>();
    int childCount = parent.getChildCount();

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

        if (child != null && child.getClass() == instance) {
            views.add(child);
        }

        if (child instanceof ViewGroup) {
            views.addAll(findAllChildrenByClass((ViewGroup) child, instance));
        }
    }

    return (List<T>) views;
}

From source file:me.anon.lib.Views.java

/**
 * Gets all views of a parent that match an class (recursive)
 * @param parent The parent view/*from  ww w . jav  a2  s.  c  o m*/
 * @param instance The class to check by instance
 * @return An array of views
 */
public static <T extends View> List<T> findAllChildrenByInstance(ViewGroup parent, Class<T> instance) {
    List<View> views = new ArrayList<View>();
    int childCount = parent.getChildCount();

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

        if (child != null && instance.isAssignableFrom(child.getClass())) {
            views.add(child);
        }

        if (child instanceof ViewGroup) {
            views.addAll(findAllChildrenByInstance((ViewGroup) child, instance));
        }
    }

    return (List<T>) views;
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static void setChildrenAlpha(ViewGroup root, final float alpha) {
    final int childCount = root.getChildCount();
    for (int i = 0; i < childCount; ++i) {
        root.getChildAt(i).setAlpha(alpha);
    }/* www. j  a v  a 2 s . c  om*/
}

From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java

static private void addLineBox(Context context, ViewGroup lineLayout, Line line, int index,
        boolean check_duplicates) {
    if (check_duplicates) {
        // loop through all line boxes in the linearLayout
        for (int i = 0; i < lineLayout.getChildCount(); ++i) {
            // check if current line box is the same as the one we are about to add
            if (line.label != null && line.label.equals(((LineView) lineLayout.getChildAt(i)).getLabel())) {
                // lines are equal, so bail out from here and don't add new line box
                return;
            }//  w ww.j  a  v  a  2s  .  c  o m
        }
    }

    LineView lineView = new LineView(context);
    lineView.setLine(line);

    // set margin, because setting in in xml does not work
    FlowLayout.LayoutParams llp = new FlowLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(0, 5, 15, 5);
    lineView.setLayoutParams(llp);

    lineLayout.addView(lineView, index);
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

private static View findChildUnder(ViewGroup parent, float x, float y) {
    final int childCount = parent.getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
        final View child = parent.getChildAt(i);
        if (isChildUnder(child, x, y)) {
            return child;
        }//w  w w . j  ava2  s . com
    }
    return null;
}