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:de.mrapp.android.bottomsheet.view.DraggableView.java

/**
 * Returns, whether a touch event at a specific position targets a view, which can be scrolled
 * up./*www.  j a v a2 s. c om*/
 *
 * @param x
 *         The horizontal position of the touch event in pixels as a {@link Float} value
 * @param y
 *         The vertical position of the touch event in pixels as a {@link Float} value
 * @param viewGroup
 *         The view group, which should be used to search for scrollable child views, as an
 *         instance of the class {@link ViewGroup}. The view group may not be null
 * @return True, if the touch event targets a view, which can be scrolled up, false otherwise
 */
private boolean isScrollUpEvent(final float x, final float y, @NonNull final ViewGroup viewGroup) {
    int location[] = new int[2];
    viewGroup.getLocationOnScreen(location);

    if (x >= location[0] && x <= location[0] + viewGroup.getWidth() && y >= location[1]
            && y <= location[1] + viewGroup.getHeight()) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View view = viewGroup.getChildAt(i);

            if (ViewCompat.canScrollVertically(view, -1)) {
                return true;
            } else if (view instanceof ViewGroup) {
                return isScrollUpEvent(x, y, (ViewGroup) view);
            }
        }
    }

    return false;
}

From source file:com.jun.fakeoschina.widget.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;/*  w  ww.  java  2  s. com*/
    ViewGroup tabsLayout = getTabsLayout();
    // tabsLayout.getMeasuredWidth() ? 528
    // getMeasuredWidth() pagerSlidingTabStrip xml720 android:layout_width="match_parent"
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<View>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

private void setExplorers(ViewGroup container, @Nullable List<User> explorers) {
    final Context context = container.getContext();
    // // TODO: 2016/10/8 performance improve
    //container.removeAllViews();
    //for (User explorer : explorers) {
    //    final ImageView avatar =
    //        (ImageView) LayoutInflater.from(context).inflate(R.layout.layout_item_explorer, container, false);
    //    ImageLoader.loadAvatar(context, avatar, explorer.getImage());
    //    container.addView(avatar);
    //}//w ww.  ja  v  a2 s . c  o m

    final int count = container.getChildCount();
    int targetCount = explorers == null ? 0 : explorers.size();
    targetCount = targetCount >= 5 ? 5 : targetCount;
    final LayoutInflater inflater = LayoutInflater.from(context);
    if (count > targetCount) {
        container.removeViews(targetCount, count - targetCount);
    }
    ImageView avatar;
    for (int i = 0; i < targetCount; i++) {
        if (i > count - 1) { // no cache
            avatar = (ImageView) inflater.inflate(R.layout.layout_item_explorer, container, false);
        } else {
            avatar = (ImageView) container.getChildAt(i);
        }
        ImageLoader.loadAvatar(context, avatar, explorers.get(i).getImage());
        if (avatar.getParent() == null) {
            container.addView(avatar);
        }
        avatar.setTag(R.id.avatar_tag_uid, explorers.get(i).getUid());
        avatar.setOnClickListener(mExplorerListener);
    }
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }/* www .j  a v  a2s . c  om*/
    if (view instanceof ViewPager) {
        ViewPager viewPager = (ViewPager) view;
        View currentViewPagerChild = ViewPagerUtils.getCurrentView(viewPager);
        View scrollingChild = findScrollingChild(currentViewPagerChild);
        if (scrollingChild != null) {
            return scrollingChild;
        }
    } else if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findScrollingChild(group.getChildAt(i));
            if (scrollingChild != null) {
                return scrollingChild;
            }
        }
    }
    return null;
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

private View findAllScrollableChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }//from w  ww  .  j a v a2 s .  c o  m
    if (view instanceof ViewPager) {
        ViewPager viewPager = ((ViewPager) view);
        for (int c = 0; c < viewPager.getChildCount(); c++) {
            View currentViewPagerChild = viewPager.getChildAt(c);
            if (currentViewPagerChild != null) {
                View scrollingChild = findAllScrollableChild(currentViewPagerChild);
                if (scrollingChild != null) {
                    scrollableViews.add(new WeakReference<View>(scrollingChild));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findAllScrollableChild(group.getChildAt(i));
            if (scrollingChild != null) {
                scrollableViews.add(new WeakReference<>(scrollingChild));
            }
        }
    }
    return null;
}

From source file:bottombar.BottomBar.java

private BottomBarTab findTabInLayout(ViewGroup child) {
    for (int i = 0; i < child.getChildCount(); i++) {
        View candidate = child.getChildAt(i);

        if (candidate instanceof BottomBarTab) {
            return (BottomBarTab) candidate;
        }//  www.  ja v  a  2 s.  c  o m
    }

    return null;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from ww w  . ja va 2 s. c om
    final ViewGroup speakersGroup = (ViewGroup) mRootView.findViewById(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 = getActivity().getLayoutInflater();

    boolean hasSpeakers = false;

    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(R.layout.speaker_detail, speakersGroup, false);
        final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header);
        final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image);
        final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract);

        if (!TextUtils.isEmpty(speakerImageUrl) && mImageLoader != null) {
            mImageLoader.get(UIUtils.getConferenceImageUrl(speakerImageUrl), speakerImageView);
        }

        speakerHeaderView.setText(speakerHeader);
        speakerImageView.setContentDescription(getString(R.string.speaker_googleplus_profile, speakerHeader));
        UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract);

        if (!TextUtils.isEmpty(speakerUrl)) {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    startActivity(speakerProfileIntent);
                }
            });
        } else {
            speakerImageView.setEnabled(false);
            speakerImageView.setOnClickListener(null);
        }

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

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

    // Show empty message when all data is loaded, and nothing to show
    if (mSessionCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }
}

From source file:com.gome.haoyuangong.views.SwipeRefreshLayout.java

private boolean canChildScroll(ViewGroup group, int direction, int startindex) {
    boolean canScroll = false;
    if (mCurrentTargetOffsetTop != 0) {
        return false;
    }//w  w  w  .j  a  v  a  2s.  com
    int count = group.getChildCount();
    for (int i = startindex; i < count; i++) {
        View child = group.getChildAt(i);
        if (child instanceof LinearLayout || child instanceof RelativeLayout) {
            canScroll = canChildScroll((ViewGroup) child, direction, 0);
        } else {
            canScroll = canScroll(child, direction);
            return canScroll;
        }
    }
    return canScroll;
}

From source file:com.lgh.tool.myview.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;//from w w w.jav  a  2 s . c om
        for (int w = 0, size = tabsLayout.getChildCount(); w < size; w++) {
            childView = tabsLayout.getChildAt(w);
            ViewGroup.LayoutParams params = childView.getLayoutParams();
            params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            childView.setLayoutParams(params);
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (!allowWidthFull) {
        return;
    }
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null) {
        return;
    }
    if (tabsLayout.getChildCount() <= 0) {
        return;
    }

    if (tabViews == null) {
        tabViews = new ArrayList<View>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.ststudy.client.android.ui.pagerslidingtabstrip.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;//from www  . java 2s. c  o  m
        for (int w = 0, size = tabsLayout.getChildCount(); w < size; w++) {
            childView = tabsLayout.getChildAt(w);
            ViewGroup.LayoutParams params = childView.getLayoutParams();
            params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            childView.setLayoutParams(params);
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (!allowWidthFull) {
        return;
    }
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null) {
        return;
    }
    if (tabsLayout.getChildCount() <= 0) {
        return;
    }

    if (tabViews == null) {
        tabViews = new ArrayList<>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}