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:name.teze.layout.lib.SlidingPaneLayout.java

/** 
 * @param v  /*from w w w .  j  a v a2s .c o  m*/
 * @author: by Fooyou 201434  ?3:01:23
 */
private void findIgnoredView(View v) {
    /*if(BuildConfig.DEBUG)Log.d(TAG, "findIgnoredView");*/
    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;
        for (int i = 0; i < vg.getChildCount(); i++) {
            final View child = vg.getChildAt(i);
            if (child instanceof ViewPager || child instanceof ScrollView || child instanceof Gallery
                    || child instanceof HorizontalScrollView) {
                mIgnoredViews.add(child);
            } else {
                findIgnoredView(child);
            }
        }
    } else {
        if (v instanceof ViewPager || v instanceof ScrollView || v instanceof Gallery
                || v instanceof HorizontalScrollView) {
            mIgnoredViews.add(v);
        }
    }
}

From source file:ayushi.view.customview.ViewDragHelper.java

/**
 * 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.
 *///w w  w .j a v a  2  s.co  m
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));
}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

private void rebuildNotifications() {
    final long now = SystemClock.elapsedRealtime();

    ViewGroup container = mIconsContainer;

    final int childCount = container.getChildCount();

    // Count the number of non-notification fragments
    // such as unlock or music controls fragments.
    int start = 0;
    for (int i = 0; i < childCount; i++) {
        View child = container.getChildAt(i);
        Widget fragment = findWidgetByIcon(child);
        if (fragment instanceof NotifyWidget) {
            // Those fragments are placed at the begin of layout
            // so no reason to continue searching.
            break;
        } else {//from  w  w  w. j  a v a  2s . co m
            start++;
        }
    }

    final ArrayList<OpenNotification> list = NotificationPresenter.getInstance().getList();
    final int notifyCount = list.size();

    final boolean[] notifyUsed = new boolean[notifyCount];
    final boolean[] childUsed = new boolean[childCount];

    for (int i = start; i < childCount; i++) {
        View child = container.getChildAt(i);
        NotifyWidget widget = (NotifyWidget) findWidgetByIcon(child);
        OpenNotification target = widget.getNotification();

        for (int j = 0; j < notifyCount; j++) {
            OpenNotification n = list.get(j);
            if (NotificationUtils.hasIdenticalIds(target, n)) {

                notifyUsed[j] = true;
                childUsed[i] = true;

                if (target != n) {
                    widget.setNotification(n);
                }
                break;
            }
        }
    }

    // Re-use free views and remove redundant views.
    boolean removeAllAfter = false;
    for (int a = start, j = 0, offset = 0; a < childCount; a++) {
        if (childUsed[a])
            continue;
        final int i = a + offset;

        View child = container.getChildAt(i);
        removing_all_next_views: {
            if (!removeAllAfter) {
                for (; j < notifyCount; j++) {
                    if (notifyUsed[j])
                        continue;

                    assert child != null;
                    notifyUsed[j] = true;

                    NotifyWidget nw = (NotifyWidget) findWidgetByIcon(child);
                    nw.setNotification(list.get(j));
                    break removing_all_next_views;
                }
            }
            removeAllAfter = true;
            internalReleaseWidget(child);

            // Remove widget's icon.
            container.removeViewAt(i);
            offset--;
        }
    }

    assert getActivity() != null;
    LayoutInflater inflater = getActivity().getLayoutInflater();

    final int iconSize = getConfig().getIconSizePx();
    for (int i = 0; i < notifyCount; i++) {
        if (notifyUsed[i])
            continue;

        NotifyWidget nw = new NotifyWidget(this, this);
        if (isResumed())
            nw.start();

        View iconView = nw.createIconView(inflater, container);
        ViewUtils.setSize(iconView, iconSize);
        container.addView(iconView);

        nw.setNotification(list.get(i));
        mWidgetsMap.put(iconView, nw);
    }

    // /////////////////////
    // ~~ UPDATE HASH MAP ~~
    // /////////////////////

    HashMap<String, SceneCompat> map = (HashMap<String, SceneCompat>) mScenesMap.clone();

    mScenesMap.clear();
    for (Widget fragment : mWidgetsMap.values()) {
        String type = fragment.getClass().getName();
        SceneCompat scene = map.get(type);
        if (scene != null) {
            fragment.createView(null, null, scene.getView());
        } else {
            ViewGroup sceneView = fragment.createView(inflater, mSceneContainer, null);
            if (sceneView != null) {
                scene = new SceneCompat(mSceneContainer, sceneView);
                map.put(type, scene);
            }
        }
        if (scene != null) {
            mScenesMap.put(type, scene);
        }
    }

    if (DEBUG) {
        long delta = SystemClock.elapsedRealtime() - now;
        Log.d(TAG, "Fragment list updated in " + delta + "ms.");
    }

    // Do not animate divider's visibility change on
    // pause/resume, cause it _somehow_ confuses people.
    boolean animate = !mResuming;
    updateDividerVisibility(animate);
}

From source file:com.cooper.redditvideo.CustomSlidingPaneLayout.java

/**
 * 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.
 *///from   w w w .j a  va2 s  .  co m
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;
            }
        }
    }

    /* special case ViewPagers, which don't properly implement the scrolling interface */
    return checkV && (ViewCompat.canScrollHorizontally(v, -dx)
            || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)));
}

From source file:com.example.CustomSlidingPaneLayout.java

/**
 * 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/* www .ja  v a2 s  .c  om*/
 * @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)
            || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)));
}

From source file:com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.java

/**
 * Reuses item views when it can/* ww w .j  a  va2  s  .  co  m*/
 */
public void updateMenuView(boolean cleared) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null)
        return;

    int childIndex = 0;
    if (mMenu != null) {
        mMenu.flagActionItems();
        ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
        final int itemCount = visibleItems.size();
        for (int i = 0; i < itemCount; i++) {
            MenuItemImpl item = visibleItems.get(i);
            if (shouldIncludeItem(childIndex, item)) {
                final View convertView = parent.getChildAt(childIndex);
                final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView
                        ? ((MenuView.ItemView) convertView).getItemData()
                        : null;
                final View itemView = getItemView(item, convertView, parent);
                if (item != oldItem) {
                    // Don't let old states linger with new data.
                    itemView.setPressed(false);
                    if (IS_HONEYCOMB)
                        itemView.jumpDrawablesToCurrentState();
                }
                if (itemView != convertView) {
                    addItemView(itemView, childIndex);
                }
                childIndex++;
            }
        }
    }

    // Remove leftover views.
    while (childIndex < parent.getChildCount()) {
        if (!filterLeftoverView(parent, childIndex)) {
            childIndex++;
        }
    }
}

From source file:com.cylee.dragcontentviewpager.ViewDragHelper.java

/**
 * 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)./*from w  w w.j ava2 s  .  c om*/
 * @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) {
        if (v instanceof AbsListView && Math.abs(dy) > Math.abs(dx)) {
            if (Build.VERSION.SDK_INT >= 19) {
                return ((AbsListView) v).canScrollList(-dy);
            }
            return true;
        }
        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,
                            checkV, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return false;
}

From source file:activities.PaintActivity.java

public void enableChildsOnTouch(ViewGroup viewGroup, boolean enabled) {
    int cnt = viewGroup.getChildCount();
    for (int i = 0; i < cnt; i++) {
        View v = viewGroup.getChildAt(i);
        if (v instanceof ViewGroup) {
            enableChildsOnTouch((ViewGroup) v, enabled);
        } else {//  w  w w .jav  a 2s.  c  o m
            v.setEnabled(enabled);

        }
    }
}

From source file:com.scurab.android.anuitorsample.widget.SlidingPaneLayout.java

/**
 * 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.
 */// w  ww  . j a  v  a2  s  . c om
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;
            }
        }
    }

    if (HACK_MOD) {
        return checkV && (ViewCompat.canScrollHorizontally(v, -dx)
                || (((v instanceof HorizontallySwipable))
                        && ((HorizontallySwipable) v).canScrollHorizontally(-dx))
                || (((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx))));

    } else {
        return checkV && ViewCompat.canScrollHorizontally(v, -dx);
    }
}

From source file:cn.xm.xmvideoplayer.widget.swipebacklayout.ViewDragHelper.java

/**
 * 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.
 *///from   w w w  . j ava 2 s. com
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--) {
            // 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));
}