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:org.mozilla.gecko.tests.AboutHomeTest.java

protected View getDisplayedBookmark(String url) {
    openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    mSolo.hideSoftKeyboard();//  w  w w .j  a  v a  2 s  .  co  m
    getInstrumentation().waitForIdleSync();
    ListView bookmarksTabList = findListViewWithTag(HomePager.LIST_TAG_BOOKMARKS);
    waitForNonEmptyListToLoad(bookmarksTabList);
    ListAdapter adapter = bookmarksTabList.getAdapter();
    if (adapter != null) {
        for (int i = 0; i < adapter.getCount(); i++) {
            // I am unable to click the view taken with getView for some reason so getting the child at i
            bookmarksTabList.smoothScrollToPosition(i);
            View bookmarkView = bookmarksTabList.getChildAt(i);
            if (bookmarkView instanceof android.widget.LinearLayout) {
                ViewGroup bookmarkItemView = (ViewGroup) bookmarkView;
                for (int j = 0; j < bookmarkItemView.getChildCount(); j++) {
                    View bookmarkContent = bookmarkItemView.getChildAt(j);
                    if (bookmarkContent instanceof android.widget.LinearLayout) {
                        ViewGroup bookmarkItemLayout = (ViewGroup) bookmarkContent;
                        for (int k = 0; k < bookmarkItemLayout.getChildCount(); k++) {
                            // Both the title and url are represented as text views so we can cast the view without any issues
                            TextView bookmarkTextContent = (TextView) bookmarkItemLayout.getChildAt(k);
                            if (url.equals(bookmarkTextContent.getText().toString())) {
                                return bookmarkView;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.learn.mobile.customview.henrytao.SmoothCollapsingToolbarLayout.java

protected Toolbar getToolbar() {
    if (vToolbar == null) {
        int i = 0;
        ViewGroup parent = (ViewGroup) getParent();
        View child;/*w  w  w  .  j a v  a  2s  .co m*/
        for (int z = parent.getChildCount(); i < z; i++) {
            child = parent.getChildAt(i);
            if (child instanceof Toolbar) {
                vToolbar = (Toolbar) child;
                break;
            }
        }
        if (vToolbar == null) {
            throw new IllegalStateException("Must have Toolbar");
        }
    }
    return vToolbar;
}

From source file:com.df.app.carsChecked.BasicInfoLayout.java

private View findView(ViewGroup viewGroup, String tag) {
    View view = null;//from  w w  w  . ja va  2  s.  c om

    for (int i = 0; i < viewGroup.getChildCount(); i++) {

        view = viewGroup.getChildAt(i);

        if (view instanceof ViewGroup) {
            view = findView((ViewGroup) view, tag);

            if (tag.equals(view.getTag())) {
                return view;
            }
        } else {
            if (tag.equals(view.getTag())) {
                return view;
            }
        }
    }

    return view;
}

From source file:info.tellmetime.DaydreamService.java

private void inflateMinutesIndicators() {
    FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators);
    minutesLayout.removeAllViews();//w w  w  .j a  va2 s. c  o  m
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final boolean isLandscape = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT);
    if (!isLandscape) {
        layoutParams.addRule(RelativeLayout.BELOW, R.id.clock);
        layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3,
                getResources().getDisplayMetrics());
    }
    minutesLayout.setLayoutParams(layoutParams);

    Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++) {
        TextView m = (TextView) minutesDots.getChildAt(i);

        m.setTypeface(mTypefaceBold);
        m.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize);
        m.setTextColor(mBacklightColor);
        m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
    }
}

From source file:com.bamalearn.bamalearnburmese.DrawerMainActivity.java

private void changeSearchViewTextColor(View view) {
    if (view != null) {
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(Color.WHITE);
            ((TextView) view).setHintTextColor(Color.WHITE);
            return;
        } else if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                changeSearchViewTextColor(viewGroup.getChildAt(i));
            }//  w  w  w .  jav a  2  s  .  co m
        }
    }
}

From source file:com.calciumion.widget.BasePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<View>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);//from   w  ww .  ja  v a  2 s .  co  m
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);
        convertView = getView(instantiatedItem, convertView, container);
        convertView.setTag(instantiatedItem);
        container.addView(convertView);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}

From source file:com.wagos.calendarcard.RecyclePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);//from w w  w. j  ava 2s .  com
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);

        if (convertView != null) {
            // Re-add existing view before rendering so that we can make change inside getView()
            container.addView(convertView);
            convertView = getView(instantiatedItem, convertView, container);
        } else {
            convertView = getView(instantiatedItem, null, container);
            container.addView(convertView);
        }

        // Set another tag id to not break ViewHolder pattern
        convertView.setTag(R.id.view_data, instantiatedItem);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}

From source file:io.selendroid.server.model.internal.AbstractNativeElementContext.java

private void addChildren(ViewGroup viewGroup, AndroidNativeElement parent) {
    if (viewGroup.getChildCount() == 0) {
        return;//from  ww  w .j  ava 2  s  .  com
    }
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        View childView = viewGroup.getChildAt(i);
        AndroidNativeElement child = newAndroidElement(childView);

        parent.addChild(child);
        child.setParent(parent);
        if (childView instanceof ViewGroup) {
            addChildren((ViewGroup) childView, child);
        }
    }
}

From source file:org.alfresco.mobile.android.application.fragments.preferences.PasscodePreferences.java

private void disableEnableControls(boolean enable, ViewGroup vg) {
    for (int i = 0; i < vg.getChildCount(); i++) {
        View child = vg.getChildAt(i);
        child.setEnabled(enable);//  w w w .ja  va2  s .c  om
        child.setFocusable(enable);
        if (child instanceof ViewGroup) {
            disableEnableControls(enable, (ViewGroup) child);
        }
    }
    vg.setEnabled(enable);
    vg.setFocusable(enable);
}

From source file:android.databinding.ViewDataBinding.java

private static void mapBindings(DataBindingComponent bindingComponent, View view, Object[] bindings,
        IncludedLayouts includes, SparseIntArray viewsWithIds, boolean isRoot) {
    final int indexInIncludes;
    final ViewDataBinding existingBinding = getBinding(view);
    if (existingBinding != null) {
        return;//from  ww  w  .  ja  v  a  2s .com
    }
    final String tag = (String) view.getTag();
    boolean isBound = false;
    if (isRoot && tag != null && tag.startsWith("layout")) {
        final int underscoreIndex = tag.lastIndexOf('_');
        if (underscoreIndex > 0 && isNumeric(tag, underscoreIndex + 1)) {
            final int index = parseTagInt(tag, underscoreIndex + 1);
            if (bindings[index] == null) {
                bindings[index] = view;
            }
            indexInIncludes = includes == null ? -1 : index;
            isBound = true;
        } else {
            indexInIncludes = -1;
        }
    } else if (tag != null && tag.startsWith(BINDING_TAG_PREFIX)) {
        int tagIndex = parseTagInt(tag, BINDING_NUMBER_START);
        if (bindings[tagIndex] == null) {
            bindings[tagIndex] = view;
        }
        isBound = true;
        indexInIncludes = includes == null ? -1 : tagIndex;
    } else {
        // Not a bound view
        indexInIncludes = -1;
    }
    if (!isBound) {
        final int id = view.getId();
        if (id > 0) {
            int index;
            if (viewsWithIds != null && (index = viewsWithIds.get(id, -1)) >= 0 && bindings[index] == null) {
                bindings[index] = view;
            }
        }
    }

    if (view instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) view;
        final int count = viewGroup.getChildCount();
        int minInclude = 0;
        for (int i = 0; i < count; i++) {
            final View child = viewGroup.getChildAt(i);
            boolean isInclude = false;
            if (indexInIncludes >= 0) {
                String childTag = (String) child.getTag();
                if (childTag != null && childTag.endsWith("_0") && childTag.startsWith("layout")
                        && childTag.indexOf('/') > 0) {
                    // This *could* be an include. Test against the expected includes.
                    int includeIndex = findIncludeIndex(childTag, minInclude, includes, indexInIncludes);
                    if (includeIndex >= 0) {
                        isInclude = true;
                        minInclude = includeIndex + 1;
                        final int index = includes.indexes[indexInIncludes][includeIndex];
                        final int layoutId = includes.layoutIds[indexInIncludes][includeIndex];
                        int lastMatchingIndex = findLastMatching(viewGroup, i);
                        if (lastMatchingIndex == i) {
                            bindings[index] = DataBindingUtil.bind(bindingComponent, child, layoutId);
                        } else {
                            final int includeCount = lastMatchingIndex - i + 1;
                            final View[] included = new View[includeCount];
                            for (int j = 0; j < includeCount; j++) {
                                included[j] = viewGroup.getChildAt(i + j);
                            }
                            bindings[index] = DataBindingUtil.bind(bindingComponent, included, layoutId);
                            i += includeCount - 1;
                        }
                    }
                }
            }
            if (!isInclude) {
                mapBindings(bindingComponent, child, bindings, includes, viewsWithIds, false);
            }
        }
    }
}