Java Code Examples for android.view.ViewGroup#getChildCount()

The following examples show how to use android.view.ViewGroup#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Monitor.java    From BehaviorCollect with GNU General Public License v3.0 6 votes vote down vote up
private static String getButtonName(View view ){
	String viewName = "";
	//获取文本值
	if (view instanceof TextView){
		viewName = ((TextView) view).getText().toString();
	}else if (view instanceof ViewGroup){
		ViewGroup viewGroup = (ViewGroup)view;
		int count = viewGroup.getChildCount();
		for (int i = 0; i < count; i++) {
			View itemView = viewGroup.getChildAt(i);
			String id = ViewUtils.getSimpleResourceName(itemView.getContext(), itemView.getId());
			if (itemView instanceof TextView){
				viewName = ((TextView) itemView).getText().toString();
				break;
			}else if (itemView instanceof ViewGroup){
				String name =getButtonName(itemView);
				if (null != name){
					return name;
				}
			}
		}
	}
	return viewName;
}
 
Example 2
Source File: FragmentActivity.java    From guideshow with MIT License 6 votes vote down vote up
private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) {
    writer.print(prefix);
    if (view == null) {
        writer.println("null");
        return;
    }
    writer.println(viewToString(view));
    if (!(view instanceof ViewGroup)) {
        return;
    }
    ViewGroup grp = (ViewGroup)view;
    final int N = grp.getChildCount();
    if (N <= 0) {
        return;
    }
    prefix = prefix + "  ";
    for (int i=0; i<N; i++) {
        dumpViewHierarchy(prefix, writer, grp.getChildAt(i));
    }
}
 
Example 3
Source File: TipsUtils.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void hideTipsInternal(View targetView, View tipsView) {
    ViewGroup tipsContainerView = (ViewGroup) targetView.getParent();
    if (!(tipsContainerView instanceof TipsContainer)) {
        return;
    }
    tipsContainerView.removeView(tipsView);
    boolean hideTarget = false;
    for (int i = 0; i < tipsContainerView.getChildCount(); ++i) {
        Tips tips = (Tips) tipsContainerView.getChildAt(i).getTag();
        if (tips == null) {
            continue;
        }
        hideTarget = tips.mHideTarget;
        if (hideTarget) {
            break;
        }
    }
    targetView.setVisibility(hideTarget ? View.INVISIBLE : View.VISIBLE);
    if (tipsContainerView.getChildCount() == 1) {
        removeContainerView(tipsContainerView, targetView);
    }
}
 
Example 4
Source File: ViewDragHelper.java    From TLint with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for
 *               scrollability (true), or just its children (false).
 * @param dx     Delta scrolled in pixels along the X axis
 * @param dy     Delta scrolled in pixels along the Y axis
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance
        // first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child
                    .getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy,
                    x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v,
            -dy));
}
 
Example 5
Source File: AlertController.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
static boolean canTextInput(View v) {
    if (v.onCheckIsTextEditor()) {
        return true;
    }

    if (!(v instanceof ViewGroup)) {
        return false;
    }

    ViewGroup vg = (ViewGroup)v;
    int i = vg.getChildCount();
    while (i > 0) {
        i--;
        v = vg.getChildAt(i);
        if (canTextInput(v)) {
            return true;
        }
    }

    return false;
}
 
Example 6
Source File: FontUtils.java    From FontTextView with MIT License 6 votes vote down vote up
/**
 * <p>Replace the font of specified view and it's children with specified typeface</p>
 */
private void replaceFont(@NonNull View root, @NonNull Typeface typeface) {
    if (root == null || typeface == null) {
        return;
    }

    if (root instanceof TextView) { // If view is TextView or it's subclass, replace it's font
        TextView textView = (TextView)root;
        // Extract previous style of TextView
        int style = Typeface.NORMAL;
        if (textView.getTypeface() != null) {
            style = textView.getTypeface().getStyle();
        }
        textView.setTypeface(typeface, style);
    } else if (root instanceof ViewGroup) { // If view is ViewGroup, apply this method on it's child views
        ViewGroup viewGroup = (ViewGroup) root;
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            replaceFont(viewGroup.getChildAt(i), typeface);
        }
    } // else return
}
 
Example 7
Source File: ViewPagerEx.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 8
Source File: SwipeMenuHelper.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
private View getSwipeMenuView(ViewGroup itemView) {
    if (itemView instanceof SwipeHorizontalMenuLayout) {
        return itemView;
    }

    List<View> unvisited = new ArrayList<>();
    unvisited.add(itemView);

    while (!unvisited.isEmpty()) {
        View child = unvisited.remove(0);

        if (!(child instanceof ViewGroup)) continue;

        if (child instanceof SwipeHorizontalMenuLayout) return child;

        ViewGroup group = (ViewGroup) child;
        int childCount = group.getChildCount();

        for (int i = 0; i < childCount; i++) {
            unvisited.add(group.getChildAt(i));
        }
    }

    return itemView;
}
 
Example 9
Source File: TranslucentUtils.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @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);
    }
}
 
Example 10
Source File: CropperSample.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public void setFont(ViewGroup group, Typeface font) {
    int count = group.getChildCount();
    View v;
    for (int i = 0; i < count; i++) {
        v = group.getChildAt(i);
        if (v instanceof TextView || v instanceof EditText || v instanceof Button) {
            ((TextView) v).setTypeface(font);
        } else if (v instanceof ViewGroup)
            setFont((ViewGroup) v, font);
    }
}
 
Example 11
Source File: SettingsFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void setZeroPaddingToLayoutChildren(View view) {
    if (!(view instanceof ViewGroup))
        return;
    ViewGroup viewGroup = (ViewGroup) view;
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        setZeroPaddingToLayoutChildren(viewGroup.getChildAt(i));
        viewGroup.setPaddingRelative(0, viewGroup.getPaddingTop(), viewGroup.getPaddingEnd(), viewGroup.getPaddingBottom());
    }
}
 
Example 12
Source File: Clicker.java    From AndroidRipper with GNU Affero General Public License v3.0 5 votes vote down vote up
private void failIfIndexHigherThenChildCount(ViewGroup viewGroup, int index, long endTime){
	while(index > viewGroup.getChildCount()){
		final boolean timedOut = SystemClock.uptimeMillis() > endTime;
		if (timedOut){
			int numberOfIndexes = viewGroup.getChildCount();
			Assert.fail("Can not click on index " + index + " as there are only " + numberOfIndexes + " indexes available");
		}
		sleeper.sleep();
	}
}
 
Example 13
Source File: BaseActivity.java    From screenstandby with GNU General Public License v2.0 5 votes vote down vote up
protected static void SetMetroFont(ViewGroup layout)
{
	for (int i = 0; i < layout.getChildCount(); i++)
	{
		TextView text = (layout.getChildAt(i) instanceof TextView ? (TextView)layout.getChildAt(i) : null);
		if (text != null)
			text.setTypeface(typeface);
	}
}
 
Example 14
Source File: CollectViewsLayout.java    From UETool with MIT License 5 votes vote down vote up
private void traverse(View view, List<Element> elements) {
    if (UETool.getInstance().getFilterClasses().contains(view.getClass().getName())) return;
    if (view.getAlpha() == 0 || view.getVisibility() != View.VISIBLE) return;
    if (getResources().getString(R.string.uet_disable).equals(view.getTag())) return;
    elements.add(new Element(view));
    if (view instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) view;
        for (int i = 0; i < parent.getChildCount(); i++) {
            traverse(parent.getChildAt(i), elements);
        }
    }
}
 
Example 15
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void recycleViewGroupAndChildViews(ViewGroup viewGroup, boolean recycleBitmap) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {

        View child = viewGroup.getChildAt(i);

        if (child instanceof WebView) {
            WebView webView = (WebView) child;
            webView.loadUrl("about:blank");
            webView.stopLoading();
            continue;
        }

        if (child instanceof ViewGroup) {
            recycleViewGroupAndChildViews((ViewGroup) child, true);
            continue;
        }

        if (child instanceof ImageView) {
            ImageView iv = (ImageView) child;
            Drawable drawable = iv.getDrawable();
            if (drawable instanceof BitmapDrawable) {
                BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                Bitmap bitmap = bitmapDrawable.getBitmap();
                if (recycleBitmap && bitmap != null) {
                    bitmap.recycle();
                }
            }
            iv.setImageBitmap(null);
            iv.setBackground(null);
            continue;
        }

        child.setBackground(null);

    }

    viewGroup.setBackground(null);
}
 
Example 16
Source File: LinkActivity.java    From AirFree-Client with GNU General Public License v3.0 5 votes vote down vote up
private void reset(View root) {
    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            reset(parent.getChildAt(i));
        }
    } else {
        root.setScaleX(1);
        root.setScaleY(1);
        root.setAlpha(1);
    }
}
 
Example 17
Source File: InterceptLayout.java    From QNotified with GNU General Public License v3.0 5 votes vote down vote up
public static InterceptLayout setupRudely(View v) {
    ViewGroup parent = (ViewGroup) v.getParent();
    int index = 0;
    ViewGroup.LayoutParams currlp = v.getLayoutParams();
    for (int i = 0; i < parent.getChildCount(); i++) {
        if (parent.getChildAt(i) == v) {
            index = i;
            break;
        }
    }
    parent.removeView(v);
    InterceptLayout layout = new InterceptLayout(v.getContext());
    ViewGroup.LayoutParams lpOuter;
    LinearLayout.LayoutParams lpInner;
    if (currlp == null) {
        lpOuter = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        lpInner = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    } else if (currlp instanceof ViewGroup.MarginLayoutParams) {
        lpOuter = currlp;
        lpInner = new LayoutParams(currlp.width, currlp.height);
        lpInner.bottomMargin = ((MarginLayoutParams) currlp).bottomMargin;
        lpInner.topMargin = ((MarginLayoutParams) currlp).topMargin;
        lpInner.leftMargin = ((MarginLayoutParams) currlp).leftMargin;
        lpInner.rightMargin = ((MarginLayoutParams) currlp).rightMargin;
        ((MarginLayoutParams) currlp).bottomMargin = ((MarginLayoutParams) currlp).topMargin
                = ((MarginLayoutParams) currlp).leftMargin = ((MarginLayoutParams) currlp).rightMargin = 0;
        lpOuter.height = lpOuter.width = WRAP_CONTENT;
    } else {
        lpOuter = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        lpInner = new LinearLayout.LayoutParams(currlp.width, currlp.height);
    }
    layout.addView(v, lpInner);
    parent.addView(layout, index, lpOuter);
    return layout;
}
 
Example 18
Source File: ComponentHeightComputer.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
static int computeComponentContentHeight(@NonNull WXComponent component) {
    View view = component.getHostView();
    if(view == null) {
        return 0;
    }
    if(component instanceof WXListComponent) {
        WXListComponent listComponent = (WXListComponent) component;
        BounceRecyclerView bounceRecyclerView = listComponent.getHostView();
        if(bounceRecyclerView == null) {
            return 0;
        }
        WXRecyclerView innerView = bounceRecyclerView.getInnerView();
        if(innerView == null) {
            return bounceRecyclerView.getMeasuredHeight();
        } else {
            return innerView.computeVerticalScrollRange();
        }
    } else if(component instanceof WXScroller) {
        WXScroller scroller = (WXScroller) component;
        if(!ViewUtils.isVerticalScroller(scroller)) {
            return view.getMeasuredHeight();
        }
        ViewGroup group = scroller.getInnerView();
        if(group == null) {
            return view.getMeasuredHeight();
        }
        if(group.getChildCount() != 1) {
            return view.getMeasuredHeight();
        } else {
            return group.getChildAt(0).getMeasuredHeight();
        }
    } else {
        return view.getMeasuredHeight();
    }
}
 
Example 19
Source File: FlowLayout.java    From Carbon with Apache License 2.0 5 votes vote down vote up
public Component findComponentOfType(Class type) {
    List<ViewGroup> groups = new ArrayList<>();
    groups.add(this);
    while (!groups.isEmpty()) {
        ViewGroup group = groups.remove(0);
        for (int i = 0; i < group.getChildCount(); i++) {
            View child = group.getChildAt(i);
            if (child instanceof ComponentView && ((ComponentView) child).getComponent().getClass().equals(type))
                return ((ComponentView) child).getComponent();
            if (child instanceof ViewGroup)
                groups.add((ViewGroup) child);
        }
    }
    return null;
}
 
Example 20
Source File: MyScrollView.java    From wallpaper with GNU General Public License v2.0 5 votes vote down vote up
public void receiveChildInfo() {
	
	firstChild = (ViewGroup) getChildAt(0);
	if(firstChild != null){
		subChildCount = firstChild.getChildCount();
		for(int i = 0;i < subChildCount;i++){
			if(((View)firstChild.getChildAt(i)).getWidth() > 0){
				pointList.add(((View)firstChild.getChildAt(i)).getLeft());
			}
		}
	}

}