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

/**
 * Determines if the supplied {@link View} and {@link AccessibilityNodeInfoCompat} has any
 * children which are not independently accessibility focusable and also have a spoken
 * description.//from  www  .  j a  va2s.co  m
 * <p>
 * NOTE: Accessibility services will include these children's descriptions in the closest
 * focusable ancestor.
 *
 * @param view The {@link View} to evaluate
 * @param node The {@link AccessibilityNodeInfoCompat} to evaluate
 * @return {@code true} if it has any non-actionable speaking descendants within its subtree
 */
public static boolean hasNonActionableSpeakingDescendants(@Nullable AccessibilityNodeInfoCompat node,
        @Nullable View view) {

    if (node == null || view == null || !(view instanceof ViewGroup)) {
        return false;
    }

    ViewGroup viewGroup = (ViewGroup) view;
    for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
        View childView = viewGroup.getChildAt(i);

        if (childView == null) {
            continue;
        }

        AccessibilityNodeInfoCompat childNode = AccessibilityNodeInfoCompat.obtain();
        try {
            ViewCompat.onInitializeAccessibilityNodeInfo(childView, childNode);

            if (isAccessibilityFocusable(childNode, childView)) {
                continue;
            }

            if (isSpeakingNode(childNode, childView)) {
                return true;
            }
        } finally {
            childNode.recycle();
        }
    }

    return false;
}

From source file:com.github.michalbednarski.intentslab.editor.ComponentPickerDialogFragment.java

private static void setTextViewsEnabled(View v, boolean enabled) {
    if (v instanceof TextView) {
        v.setEnabled(enabled);/*from  w w w  . java  2  s  .c o m*/
    }

    if (v instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) v;
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            setTextViewsEnabled(vg.getChildAt(i), enabled);
        }
    }
}

From source file:Main.java

public static void applyDialogStyle(ViewGroup viewGroup) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return;/*from w w w.jav  a2  s . c  o m*/
    }

    viewGroup.setBackgroundColor(Color.BLACK);

    // Theme.AppCompat.Light makes all text and background black
    final int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View childView = viewGroup.getChildAt(i);
        if (childView instanceof ListView) {
            childView.setBackgroundColor(Color.LTGRAY);
        } else if (childView instanceof ViewGroup) {
            applyDialogStyle((ViewGroup) childView);
        } else if (childView instanceof TextView) {
            ((TextView) childView).setTextColor(Color.WHITE);
        }
    }
}

From source file:com.normalexception.app.rx8club.fragment.FragmentUtils.java

/**
 * Convenient method to register an onclicklistener to all views within a 
 * viewgroup/*from www .j  av  a2s .c  o m*/
 * @param och   The handler to assign
 * @param vh   The view group to assign to
 */
public static void registerHandlerToViewObjects(OnClickListener och, ViewGroup vh) {
    View v = null;
    Log.v(TAG, String.format("Registering %d Listening Objects", vh.getChildCount()));
    for (int i = 0; i < vh.getChildCount(); i++) {
        v = vh.getChildAt(i);
        if (v instanceof Button)
            v.setOnClickListener(och);
        if (v instanceof ImageView)
            v.setOnClickListener(och);
    }
}

From source file:android.support.design.testutils.TestUtilsActions.java

/**
 * Replaces an existing {@link TabLayout} with a new one inflated from the specified
 * layout resource./* ww  w . j  a  va  2  s . c om*/
 */
public static ViewAction replaceTabLayout(final @LayoutRes int tabLayoutResId) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Replace TabLayout";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            final ViewGroup viewGroup = (ViewGroup) view;
            final int childCount = viewGroup.getChildCount();
            // Iterate over children and find TabLayout
            for (int i = 0; i < childCount; i++) {
                View child = viewGroup.getChildAt(i);
                if (child instanceof TabLayout) {
                    // Remove the existing TabLayout
                    viewGroup.removeView(child);
                    // Create a new one
                    final LayoutInflater layoutInflater = LayoutInflater.from(view.getContext());
                    final TabLayout newTabLayout = (TabLayout) layoutInflater.inflate(tabLayoutResId, viewGroup,
                            false);
                    // Make sure we're adding the new TabLayout at the same index
                    viewGroup.addView(newTabLayout, i);
                    break;
                }
            }

            uiController.loopMainThreadUntilIdle();
        }
    };
}

From source file:net.pmarks.chromadoze.NoiseService.java

private static TextView findTextView(View view, String title) {
    if (view instanceof TextView) {
        TextView text = (TextView) view;
        if (text.getText().equals(title)) {
            return text;
        }//ww  w. j  a  v  a 2s.c om
    } else if (view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            TextView found = findTextView(vg.getChildAt(i), title);
            if (found != null) {
                return found;
            }
        }
    }
    return null;
}

From source file:com.metinkale.prayerapp.vakit.WidgetService.java

private static boolean recurseGroup(ViewGroup gp) {
    int count = gp.getChildCount();
    for (int i = 0; i < count; ++i) {
        View v = gp.getChildAt(i);
        if (v instanceof TextView) {
            TextView text = (TextView) v;
            String szText = text.getText().toString();
            if (COLOR_SEARCH_1ST.equals(szText)) {
                COLOR_1ST = text.getCurrentTextColor();
            }/* www . j  av  a2  s  .  c  o  m*/
            if (COLOR_SEARCH_2ND.equals(szText)) {
                COLOR_2ND = text.getCurrentTextColor();
            }

            if ((COLOR_1ST != null) && (COLOR_2ND != null)) {
                return true;
            }
        } else if (gp.getChildAt(i) instanceof ViewGroup) {
            if (recurseGroup((ViewGroup) v)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.micabyte.android.app.BaseActivity.java

private static void unbindViewGroupReferences(ViewGroup viewGroup) {
    final int nrOfChildren = viewGroup.getChildCount();
    for (int i = 0; i < nrOfChildren; i++) {
        final View view = viewGroup.getChildAt(i);
        unbindViewReferences(view);//from  ww  w  . j a v a  2 s . c  o  m
        if (view instanceof ViewGroup)
            unbindViewGroupReferences((ViewGroup) view);
    }
    try {
        viewGroup.removeAllViews();
    } catch (Throwable mayHappen) {
        // AdapterViews, ListViews and potentially other ViewGroups don't
        // support the removeAllViews operation
    }
}

From source file:net.pmarks.chromadoze.ChromaDoze.java

private static ImageButton findImageButton(View view) {
    if (view instanceof ImageButton) {
        return (ImageButton) view;
    } else if (view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            ImageButton found = findImageButton(vg.getChildAt(i));
            if (found != null) {
                return found;
            }/*from w  w w.j a  va  2 s  .  co  m*/
        }
    }
    return null;
}

From source file:com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckUtils.java

/**
 * Retrieve text for a {@link View}, which may include text from the children of the {@code View}.
 * This text is an approximation of, but not identical to, what TalkBack would speak for the
 * {@link View}. One difference is that there are no separators between the speakable text from
 * different nodes./*from www  . ja va2  s . c o  m*/
 * <p>
 * TalkBack also will not speak {@link View}s that aren't visible. This method assumes that the
 * {@link View} passed in is visible. The visibility of the rest of child nodes is inferred from
 * {@code view.getVisibility}.
 *
 * @param view The {@link View} whose text should be returned.
 *
 * @return Speakable text derived from the {@link View} and its children. Returns an empty string
 *         if there is no such text, and {@code null} if {@code view == null}.
 */
static CharSequence getSpeakableTextForView(View view) {
    if (view == null) {
        return null;
    }

    View labelForThisView = ViewAccessibilityUtils.getLabelForView(view);
    if (labelForThisView != null) {
        return getSpeakableTextForView(labelForThisView);
    }

    SpannableStringBuilder returnStringBuilder = new SpannableStringBuilder("");

    // Accessibility importance is considered only on Jelly Bean and above
    if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            || ViewAccessibilityUtils.isImportantForAccessibility(view)) {
        if (!TextUtils.isEmpty(view.getContentDescription())) {
            // contentDescription always wins out over other properties
            return view.getContentDescription();
        }
        if (view instanceof TextView) {
            if (!TextUtils.isEmpty(((TextView) view).getText())) {
                returnStringBuilder.append(((TextView) view).getText());
            } else if (!TextUtils.isEmpty(((TextView) view).getHint())) {
                returnStringBuilder.append(((TextView) view).getHint());
            }
        }
    }

    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        // TODO(sjrush): Only evaluate child views if they're importantForAccessibility.
        for (int i = 0; i < group.getChildCount(); ++i) {
            View childView = group.getChildAt(i);
            if ((childView.getVisibility() == View.VISIBLE)
                    && !ViewAccessibilityUtils.isActionableForAccessibility(childView)) {
                returnStringBuilder.append(getSpeakableTextForView(childView));
            }
        }
    }

    if (view instanceof CompoundButton) {
        if (((CompoundButton) view).isChecked()) {
            StringBuilderUtils.appendWithSeparator(returnStringBuilder, "Checked");
        } else {
            StringBuilderUtils.appendWithSeparator(returnStringBuilder, "Not checked");
        }
    }
    return returnStringBuilder;
}