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:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.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 ww  w .  j  a v a  2  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--) {
            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:android.car.ui.provider.CarDrawerLayout.java

private void updateDrawerAlpha() {
    float alpha;/*from  w w w.  j av a  2 s .  co m*/
    if (mStartedOpen) {
        alpha = mDrawerFadeInterpolator.getReverseInterpolation(onScreen());
    } else {
        alpha = mDrawerFadeInterpolator.getForwardInterpolation(onScreen());
    }
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    int drawerChildCount = drawerView.getChildCount();
    for (int i = 0; i < drawerChildCount; i++) {
        drawerView.getChildAt(i).setAlpha(alpha);
    }
}

From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from w  w  w.  jav  a2s  . com
    final ViewGroup speakersGroup = (ViewGroup) 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 = 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(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) && mSpeakersImageLoader != null) {
            mSpeakersImageLoader.loadImage(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 View.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);
                    UIUtils.preferPackageForIntent(CurrentSessionActivity.this, speakerProfileIntent,
                            UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);
                }
            });
        } else {
            speakerImageView.setEnabled(false);
            speakerImageView.setOnClickListener(null);
        }

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

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

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

/**
 * if the ViewGroup children want to handle this event.
 * @param v the v//ww w . j  a va 2s . c o  m
 * @param event the event
 * @return v
 */
private View childNeedHandleTouchEvent(ViewGroup v, MotionEvent event) {
    if (v == null)
        return null;
    if (v.onTouchEvent(event))
        return v;

    int childCount = v.getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
        View child = v.getChildAt(i);
        if (child instanceof ViewGroup) {
            View grandChild = childNeedHandleTouchEvent((ViewGroup) child, event);
            if (grandChild != null)
                return grandChild;
        } else {
            if (childNeedHandleTouchEvent(v.getChildAt(i), event))
                return v.getChildAt(i);
        }
    }
    return null;
}

From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;/*from  w w  w .jav a 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) && mSpeakersImageLoader != null) {
            mSpeakersImageLoader.loadImage(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);
                    UIUtils.preferPackageForIntent(getActivity(), speakerProfileIntent,
                            UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    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:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java

private void setEnabledRecursive(View v, boolean enabled) {
    if (v == null)
        return;/*  ww  w.  j a v  a2s  .  c  om*/
    if (v.isEnabled() == enabled)
        return;
    v.setEnabled(enabled);

    if (v instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) v;
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            setEnabledRecursive(vg.getChildAt(i), enabled);
        }
    }
}

From source file:org.de.jmg.learn.SettingsActivity.java

private void initHelp() {
    ViewGroup Settings = (ViewGroup) findViewById(R.id.layoutSettings);
    int ChildCount = Settings.getChildCount();
    for (int i = 0; i < ChildCount; i++) {
        if (i > 100)
            break;
        libLearn.gStatus = "getting view " + i;
        View V = Settings.getChildAt(i);
        CharSequence cs = V.getContentDescription();
        if (cs != null && cs.length() > 0) {
            V.setOnLongClickListener(ViewOnLongClickCD);
        }/*from w w  w  .j a v  a2s.com*/
    }

}

From source file:com.chauthai.swipereveallayout.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  a va 2  s .c om
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:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v//  w  w  w.ja v a2 s .c o  m
 *            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--) {
            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.yangc.swipebacklayout.helper.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 ww  .  j av  a  2 s.c om*/
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));
}