List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:Main.java
private static void unwrapView(ViewGroup wrapper) { final int childCount = wrapper.getChildCount(); View[] childViews = new View[childCount]; ViewGroup parent = (ViewGroup) wrapper.getParent(); if (parent != null) { parent.removeView(wrapper);//from w w w . j av a 2s . c o m } for (int i = 0; i < childCount; i++) { childViews[i] = wrapper.getChildAt(i); } // If there was just one wrapper reuse the wrapper layout // params to ensure correct type for parent if (childCount == 1) { ViewGroup.LayoutParams wrapperParams = wrapper.getLayoutParams(); if (wrapperParams != null) { childViews[0].setLayoutParams(wrapperParams); } } for (int i = 0; i < childCount; i++) { final View childView = childViews[i]; wrapper.removeView(childView); if (parent != null) { parent.addView(childView); } } }
From source file:com.normalexception.app.rx8club.fragment.FragmentUtils.java
/** * Convenient method to register an onclicklistener to all views within a * viewgroup/*from w w w. ja va2 s. co 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:Main.java
public static void applyDialogStyle(ViewGroup viewGroup) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { return;//from w ww . j ava 2 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.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 ww w . j av a2s. co 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; }
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(); }//from ww w . ja v a2 s . com 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 w w w . j ava2s. com 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:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java
@Nullable public static CharSequence getDescription(AccessibilityNodeInfoCompat node, View view) { CharSequence contentDescription = node.getContentDescription(); CharSequence nodeText = node.getText(); boolean hasNodeText = !TextUtils.isEmpty(nodeText); boolean isEditText = view instanceof EditText; // EditText's prioritize their own text content over a contentDescription if (!TextUtils.isEmpty(contentDescription) && (!isEditText || !hasNodeText)) { return contentDescription; }/*from w w w.j a v a 2 s . c om*/ if (hasNodeText) { return nodeText; } // If there are child views and no contentDescription the text of all non-focusable children, // comma separated, becomes the description. if (view instanceof ViewGroup) { final StringBuilder concatChildDescription = new StringBuilder(); final String separator = ", "; ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { final View child = viewGroup.getChildAt(i); AccessibilityNodeInfoCompat childNodeInfo = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(child, childNodeInfo); CharSequence childNodeDescription = null; if (AccessibilityUtil.isSpeakingNode(childNodeInfo, child) && !AccessibilityUtil.isAccessibilityFocusable(childNodeInfo, child)) { childNodeDescription = getDescription(childNodeInfo, child); } if (!TextUtils.isEmpty(childNodeDescription)) { if (concatChildDescription.length() > 0) { concatChildDescription.append(separator); } concatChildDescription.append(childNodeDescription); } childNodeInfo.recycle(); } return concatChildDescription.length() > 0 ? concatChildDescription.toString() : null; } return null; }
From source file:com.hellofyc.base.util.ViewUtils.java
@TargetApi(11) public static void setActionBarTranslation(Context context, float y) { int actionBarHeight = getActionBarHeight(context); ViewGroup content = ((ViewGroup) ((Activity) context).findViewById(android.R.id.content).getParent()); int children = content.getChildCount(); for (int i = 0; i < children; i++) { View child = content.getChildAt(i); if (child.getId() != android.R.id.content) { if (y <= -actionBarHeight) { child.setVisibility(View.GONE); } else { child.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { child.setTranslationY(y); }//from ww w . j a v a 2 s .c om } } } }
From source file:android.support.design.testutils.TestUtilsActions.java
/** * Replaces an existing {@link TabLayout} with a new one inflated from the specified * layout resource./*from w w w.j a v a 2 s . c o m*/ */ 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:io.github.prefanatic.cleantap.util.AnimUtils.java
public static void hideChildren(ViewGroup group) { FastOutLinearInInterpolator interpolator = new FastOutLinearInInterpolator(); for (int i = 0; i < group.getChildCount(); i++) { View view = group.getChildAt(i); view.animate().alpha(0f).translationY(view.getHeight() / 3).setStartDelay(0L).setDuration(100L) .setInterpolator(interpolator).start(); }/*from w w w. j a va 2 s .c om*/ }