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:com.givewaygames.transition.Transition.java

/**
 * Recursive method which captures values for an entire view hierarchy,
 * starting at some root view. Transitions without targetIDs will use this
 * method to capture values for all possible views.
 *
 * @param view The view for which to capture values. Children of this View
 * will also be captured, recursively down to the leaf nodes.
 * @param start true if values are being captured in the start scene, false
 * otherwise.//from ww w  . j a  v a2s. co  m
 */
private void captureHierarchy(View view, boolean start) {
    if (view == null) {
        return;
    }
    boolean isListViewItem = false;
    if (view.getParent() instanceof ListView) {
        isListViewItem = true;
    }
    if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) {
        // ignore listview children unless we can track them with stable IDs
        return;
    }
    int id = View.NO_ID;
    long itemId = View.NO_ID;
    if (!isListViewItem) {
        id = view.getId();
    } else {
        ListView listview = (ListView) view.getParent();
        int position = listview.getPositionForView(view);
        itemId = listview.getItemIdAtPosition(position);
        view.setHasTransientState(true);
    }
    if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) {
        return;
    }
    if (mTargetExcludes != null && mTargetExcludes.contains(view)) {
        return;
    }
    if (mTargetTypeExcludes != null && view != null) {
        int numTypes = mTargetTypeExcludes.size();
        for (int i = 0; i < numTypes; ++i) {
            if (mTargetTypeExcludes.get(i).isInstance(view)) {
                return;
            }
        }
    }
    TransitionValues values = new TransitionValues();
    values.view = view;
    if (start) {
        captureStartValues(values);
    } else {
        captureEndValues(values);
    }
    if (start) {
        if (!isListViewItem) {
            mStartValues.viewValues.put(view, values);
            if (id >= 0) {
                mStartValues.idValues.put((int) id, values);
            }
        } else {
            mStartValues.itemIdValues.put(itemId, values);
        }
    } else {
        if (!isListViewItem) {
            mEndValues.viewValues.put(view, values);
            if (id >= 0) {
                mEndValues.idValues.put((int) id, values);
            }
        } else {
            mEndValues.itemIdValues.put(itemId, values);
        }
    }
    if (view instanceof ViewGroup) {
        // Don't traverse child hierarchy if there are any child-excludes on this view
        if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) {
            return;
        }
        if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) {
            return;
        }
        if (mTargetTypeChildExcludes != null && view != null) {
            int numTypes = mTargetTypeChildExcludes.size();
            for (int i = 0; i < numTypes; ++i) {
                if (mTargetTypeChildExcludes.get(i).isInstance(view)) {
                    return;
                }
            }
        }
        ViewGroup parent = (ViewGroup) view;
        for (int i = 0; i < parent.getChildCount(); ++i) {
            captureHierarchy(parent.getChildAt(i), start);
        }
    }
}

From source file:com.yangpeiyong.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/*from  www .j  a  v  a 2s  .  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)));

    // return checkV && ViewCompat.canScrollHorizontally(v, (isLayoutRtlSupport() ? dx : -dx));
}

From source file:me.hoen.slidingmenu.ResideMenuLayout.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  ww  w.  ja  va  2 s.com
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, (isLayoutRtlSupport() ? dx : -dx))
            || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx));
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

/** Creates a new view for use in the list view */
@Override/*from w ww . j  a  v  a  2s  . c  o m*/
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.task_adapter_row_simple, parent, false);

    // create view holder
    ViewHolder viewHolder = new ViewHolder();
    viewHolder.task = new Task();
    viewHolder.rowBody = (ViewGroup) view.findViewById(R.id.rowBody);
    viewHolder.nameView = (TextView) view.findViewById(R.id.title);
    viewHolder.completeBox = (CheckableImageView) view.findViewById(R.id.completeBox);
    viewHolder.dueDate = (TextView) view.findViewById(R.id.due_date);
    viewHolder.tagBlock = (TextView) view.findViewById(R.id.tag_block);
    viewHolder.taskActionContainer = view.findViewById(R.id.taskActionContainer);
    viewHolder.taskActionIcon = (ImageView) view.findViewById(R.id.taskActionIcon);

    boolean showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false);
    if (showFullTaskTitle) {
        viewHolder.nameView.setMaxLines(Integer.MAX_VALUE);
        viewHolder.nameView.setSingleLine(false);
        viewHolder.nameView.setEllipsize(null);
    }

    view.setTag(viewHolder);
    for (int i = 0; i < view.getChildCount(); i++) {
        view.getChildAt(i).setTag(viewHolder);
    }

    // add UI component listeners
    addListeners(view);

    return view;
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*w w  w . j  a  v a 2 s  .  c o m*/
 * @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, (isLayoutRtlSupport() ? dx : -dx));
}

From source file:com.jzh.stuapp.view.MyViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*from ww w.  j av  a 2 s .  c  o  m*/
 * @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();
        for (int i = count - 1; i >= 0; i--) {
            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);
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

/**
 * Initialize the ViewPager and setup the rest of the layout
 *//*from  ww  w. java 2  s.  c  o m*/
private void setupLayout() {
    if (this.currentList == null) {
        setCurrentList(SpecialList.firstSpecialSafe());
    }
    // clear tabletfragments
    final ViewGroup all = (ViewGroup) this.findViewById(R.id.multi_pane_box);
    if ((all != null) && MirakelCommonPreferences.isTablet()) {
        for (int i = 0; i < all.getChildCount(); i++) {
            final ViewGroup group = (ViewGroup) all.getChildAt(i);
            group.removeAllViews();
            Log.d(TAG, "Clear view " + i);
        }
    }
    // Initialize ViewPager
    /*
     * TODO We need the try catch because it throws sometimes a
     * runtimeexception when adding fragments.
     */
    try {
        initViewPager();
    } catch (final Exception e) {
        Log.wtf(TAG, "initViewPager throwed an exception", e);
    }
    initNavDrawer();
    this.startIntent = getIntent();
    handleIntent(this.startIntent);
}

From source file:com.icenler.lib.view.LazyViewPager.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/*from  w ww.j a va2 s  .  co m*/
 * @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--) {
            // 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);
}

From source file:com.android.calendar.event.EditEventView.java

private void addFieldsRecursive(StringBuilder b, View v) {
    if (v == null || v.getVisibility() != View.VISIBLE) {
        return;/*from  w  w  w.  j  ava  2 s  .  c om*/
    }
    if (v instanceof TextView) {
        CharSequence tv = ((TextView) v).getText();
        if (!TextUtils.isEmpty(tv.toString().trim())) {
            b.append(tv + PERIOD_SPACE);
        }
    } else if (v instanceof RadioGroup) {
        RadioGroup rg = (RadioGroup) v;
        int id = rg.getCheckedRadioButtonId();
        if (id != View.NO_ID) {
            b.append(((RadioButton) (v.findViewById(id))).getText() + PERIOD_SPACE);
        }
    } else if (v instanceof Spinner) {
        Spinner s = (Spinner) v;
        if (s.getSelectedItem() instanceof String) {
            String str = ((String) (s.getSelectedItem())).trim();
            if (!TextUtils.isEmpty(str)) {
                b.append(str + PERIOD_SPACE);
            }
        }
    } else if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;
        int children = vg.getChildCount();
        for (int i = 0; i < children; i++) {
            addFieldsRecursive(b, vg.getChildAt(i));
        }
    }
}

From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java

private boolean anyChildWantMotionEvent(MotionEvent ev, ViewGroup group) {
    MotionEvent event = MotionEvent.obtain(ev);
    event.offsetLocation(-group.getLeft(), -group.getTop());
    //view//  w w  w  .ja  v  a 2  s. c  o m
    int childCount = group.getChildCount();
    final float x = event.getX();
    final float y = event.getY();

    for (int i = 0; i < childCount; i++) {
        View child = group.getChildAt(i);
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) {
            if (child instanceof ViewGroup) {
                MotionEvent chileEvent = MotionEvent.obtain(event);
                chileEvent.offsetLocation(-child.getLeft(), -child.getTop());
                if (anyChildWantMotionEvent(chileEvent, (ViewGroup) child)) {
                    chileEvent.recycle();
                    return true;
                }
            } else if (child.onTouchEvent(event)) {
                return true;
            }
        }
    }
    event.recycle();
    return false;
}