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:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * ??/*from w w w  .j  a  va  2  s.co m*/
 *
 * @param activity       ?activity
 * @param color          ??
 * @param statusBarAlpha ???
 */

public static void setColor(Activity activity, 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:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * DrawerLayout ???/*from w  w  w .  j  a v a 2s . c o  m*/
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, 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:Main.java

public static void setupChangeAnimationOneTime(ViewGroup viewGroup) {
    LayoutTransition layoutTransition = viewGroup.getLayoutTransition();
    if (layoutTransition == null) {
        return;/*from w ww  . j  a v  a  2  s .  co m*/
    }
    try {
        Method method = LayoutTransition.class.getMethod("enableTransitionType", new Class[] { int.class });
        Field field = LayoutTransition.class.getField("CHANGING");
        method.invoke(layoutTransition, field.get(null));
    } catch (Exception e) {
        setupChangeAnimationOneTime((View) viewGroup);
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View childAt = viewGroup.getChildAt(i);
            setupChangeAnimationOneTime(childAt);
        }
    }
}

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

private static ViewGroup findToolbar(ViewGroup viewGroup) {
    ViewGroup toolbar = null;/*from  w ww.  j ava  2 s  . c o m*/
    for (int i = 0, len = viewGroup.getChildCount(); i < len; i++) {
        View view = viewGroup.getChildAt(i);
        if (view.getClass() == android.support.v7.widget.Toolbar.class
                || view.getClass().getName().equals("android.widget.Toolbar")) {
            toolbar = (ViewGroup) view;
        } else if (view instanceof ViewGroup) {
            toolbar = findToolbar((ViewGroup) view);
        }
        if (toolbar != null) {
            break;
        }
    }
    return toolbar;
}

From source file:dev.drsoran.moloko.util.UIUtils.java

public final static void inflateTags(Context context, ViewGroup container, Collection<String> tags,
        Bundle configuration) {//w w w. ja  va2s .co m
    if (configuration == null) {
        configuration = Bundle.EMPTY;
    }

    final int tagPos = getTaggedViewPos(container, "tag_name");

    if (tagPos != -1) {
        container.removeViews(tagPos, container.getChildCount() - tagPos);
    }

    // inflate the stub and add tags
    if (tags.size() > 0 && !configuration.containsKey(REMOVE_ALL_TAGS)) {
        try {
            final String[] tagsToRemove = configuration.getStringArray(REMOVE_TAGS_EQUALS);

            for (String tagText : tags) {
                boolean remove = false;

                if (tagsToRemove != null) {
                    for (int i = 0; i < tagsToRemove.length && !remove; i++) {
                        remove = tagsToRemove[i].equalsIgnoreCase(tagText);
                    }
                }

                if (!remove) {
                    final TextView tagView = (TextView) View.inflate(context, R.layout.tag_button, null);
                    tagView.setText(tagText);
                    container.addView(tagView);
                }
            }
        } catch (Throwable e) {
            throw new InflateException(e);
        }
    }

    if (container.getChildCount() > 0)
        container.setVisibility(View.VISIBLE);
    else
        container.setVisibility(View.GONE);
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void addWalkingBox(Context context, ViewGroup lineLayout) {
    addWalkingBox(context, lineLayout, lineLayout.getChildCount());
}

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

/**
 * ??(5.0??,?)/*from  ww w  . j av  a  2  s.co  m*/
 *
 * @param activity ? activity
 * @param color    ??
 */
@Deprecated
public static void setColorDiff(Activity activity, @ColorInt int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    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(color);
    } else {
        StatusBarView statusView = createStatusBarView(activity, color);
        decorView.addView(statusView);
    }
    setRootView(activity);
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void addLineBox(Context context, ViewGroup lineLayout, Line line) {
    addLineBox(context, lineLayout, line, lineLayout.getChildCount());
}

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

/**
 * DrawerLayout ???(5.0??,?)/*ww  w . j  av  a  2  s. c om*/
 *
 * @param activity     ?activity
 * @param drawerLayout DrawerLayout
 * @param color        ??
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout,
        @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // ????
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
            contentLayout.getChildAt(0)
                    .setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            //  statusBarView 
            StatusBarView statusBarView = createStatusBarView(activity, color);
            contentLayout.addView(statusBarView, 0);
        }
        // ? LinearLayout ,padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}

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

public static void setTranslucentImageHeader(Activity activity, int alpha, View needOffsetView) {
    setFullScreen(activity);//from   w w  w  . j a  v  a2s  . c  o  m
    //?windowphonedecorView
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int count = decorView.getChildCount();
    //??statusBarView
    if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
        decorView.getChildAt(count - 1).setBackgroundColor(Color.argb(alpha, 0, 0, 0));
    } else {
        //??view
        StatusBarView statusView = createTranslucentStatusBarView(activity, alpha);
        decorView.addView(statusView);
    }

    if (needOffsetView != null) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView
                .getLayoutParams();
        layoutParams.setMargins(0, getStatusBarHeight(activity), 0, 0);
    }

}