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.malin.rxjava.activity.MainActivity.java

/**
 * Remove an onclick listener//from  w  w  w.j ava  2 s  . co m
 *
 * @param view
 * @author malin.myemail@gmail.com
 * @website https://github.com/androidmalin
 * @data 2016/01/22
 */
private void unBingListener(View view) {
    if (view != null) {
        try {
            if (view.hasOnClickListeners()) {
                view.setOnClickListener(null);
            }
            if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
                ViewGroup viewGroup = (ViewGroup) view;
                int viewGroupChildCount = viewGroup.getChildCount();
                for (int i = 0; i < viewGroupChildCount; i++) {
                    unBingListener(viewGroup.getChildAt(i));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:com.malin.rxjava.activity.MainActivity.java

/**
 * ???Activity onDestoryviewrootview//from   w  ww  .j  a  v  a  2 s.c o  m
 * ?view?DrawingCache??
 * Activity???????
 *
 * @param view:the root view of the layout
 * @description Unbind the rootView
 * @author malin.myemail@gmail.com
 * @link http://stackoverflow.com/questions/9461364/exception-in-unbinddrawables
 * http://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=400656149&idx=1&sn=122b4f4965fafebf78ec0b4fce2ef62a&3rd=MzA3MDU4NTYzMw==&scene=6#rd
 * @since 2015.12.16
 */
private void unBindDrawables(View view) {
    if (view != null) {
        try {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable.setCallback(null);
            } else {
            }
            if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
                ViewGroup viewGroup = (ViewGroup) view;
                int viewGroupChildCount = viewGroup.getChildCount();
                for (int j = 0; j < viewGroupChildCount; j++) {
                    unBindDrawables(viewGroup.getChildAt(j));
                }
                viewGroup.removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:com.lansun.qmyo.view.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * //from  w  w  w .ja  va  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 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--) {
            // 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.inmobi.ultrapush.AnalyzeActivity.java

/**
 * Visit all subviews of this view group and run command
 *
 * @param group  The parent view group//from  www.  ja va 2s  . co m
 * @param cmd    The command to run for each view
 * @param select The tag value that must match. Null implies all views
 */

private void visit(ViewGroup group, Visit cmd, String select) {
    exec(group, cmd, select);
    for (int i = 0; i < group.getChildCount(); i++) {
        View c = group.getChildAt(i);
        if (c instanceof ViewGroup) {
            visit((ViewGroup) c, cmd, select);
        } else {
            exec(c, cmd, select);
        }
    }
}

From source file:org.appcelerator.titanium.view.TiUIView.java

public void release() {
    Log.d(TAG, "Releasing: " + this, Log.DEBUG_MODE);
    View nv = getNativeView();//from   www  .jav  a  2 s.  c  o m
    if (nv != null) {
        if (nv instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) nv;
            Log.d(TAG, "Group has: " + vg.getChildCount(), Log.DEBUG_MODE);
            if (!(vg instanceof AdapterView<?>)) {
                vg.removeAllViews();
            }
        }
        Drawable d = nv.getBackground();
        if (d != null) {
            nv.setBackgroundDrawable(null);
            d.setCallback(null);
            if (d instanceof TiBackgroundDrawable) {
                ((TiBackgroundDrawable) d).releaseDelegate();
            }
            d = null;
        }
        nativeView = null;
        borderView = null;
        if (proxy != null) {
            proxy.setModelListener(null);
        }
    }
}

From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java

@Override
public void onDestroyView() {
    super.onDestroyView();

    // Cancel any outstanding thumbnail requests
    final ViewGroup target = (mListView.getAdapter() != null) ? mListView : mGridView;
    final int count = target.getChildCount();
    for (int i = 0; i < count; i++) {
        final View view = target.getChildAt(i);
        mRecycleListener.onMovedToScrapHeap(view);
    }//from   w  ww.  j  a v  a2 s. c  om

    // Tear down any selection in progress
    mListView.setChoiceMode(AbsListView.CHOICE_MODE_NONE);
    mGridView.setChoiceMode(AbsListView.CHOICE_MODE_NONE);
}

From source file:com.cyanogenmod.filemanager.ui.widgets.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 av a2s  . 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--) {
            // 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 && (v.canScrollHorizontally(-dx) || v.canScrollVertically(-dy));
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;/*www .j  a v  a2 s  .  c o  m*/
    final ViewGroup speakersGroup = (ViewGroup) findViewById(
            com.saarang.samples.apps.iosched.R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
        speakersGroup.removeViewAt(i);
    }

    final LayoutInflater inflater = getLayoutInflater();

    boolean hasSpeakers = false;

    cursor.moveToPosition(-1); // move to just before first record
    while (cursor.moveToNext()) {
        final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME);
        if (TextUtils.isEmpty(speakerName)) {
            continue;
        }

        final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL);
        final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY);
        final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL);
        final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT);

        String speakerHeader = speakerName;
        if (!TextUtils.isEmpty(speakerCompany)) {
            speakerHeader += ", " + speakerCompany;
        }

        final View speakerView = inflater.inflate(com.saarang.samples.apps.iosched.R.layout.speaker_detail,
                speakersGroup, false);
        final TextView speakerHeaderView = (TextView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_header);
        final ImageView speakerImageView = (ImageView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_image);
        final TextView speakerAbstractView = (TextView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_abstract);

        if (!TextUtils.isEmpty(speakerImageUrl) && mSpeakersImageLoader != null) {
            mSpeakersImageLoader.loadImage(speakerImageUrl, speakerImageView);
        }

        speakerHeaderView.setText(speakerHeader);
        speakerImageView.setContentDescription(
                getString(com.saarang.samples.apps.iosched.R.string.speaker_googleplus_profile, speakerHeader));
        UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract);

        if (!TextUtils.isEmpty(speakerUrl)) {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String number = "tel:" + speakerUrl.trim();
                    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
                    startActivity(callIntent);
                    /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(SessionDetailActivity.this,
                        speakerProfileIntent,
                        UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);*/
                }
            });
        } else {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(SessionDetailActivity.this,
                            "Sorry, No number found for this person. Call the other coordinator",
                            Toast.LENGTH_SHORT).show();

                    /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(SessionDetailActivity.this,
                        speakerProfileIntent,
                        UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);*/
                }
            });

        }

        speakersGroup.addView(speakerView);
        hasSpeakers = true;
        mHasSummaryContent = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);
    updateEmptyView();
}

From source file:android.support.v7.internal.view.menu.BaseMenuPresenter.java

/**
 * Reuses item views when it can/*from  w  w  w  .  jav a2s . c  o  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);
                    ViewCompat.jumpDrawablesToCurrentState(itemView);
                }
                if (itemView != convertView) {
                    addItemView(itemView, childIndex);
                }
                childIndex++;
            }
        }
    }

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

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

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;
            }//  ww  w  .  ja  v  a 2 s .  c  om
        }
    }

    return checkV && ((allowedDirection() == HORIZONTAL && ViewCompat.canScrollHorizontally(v, -dx)
            || allowedDirection() == VERTICAL && ViewCompat.canScrollVertically(v, -dy)));
}