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:info.staticfree.android.units.Units.java

/**
 * @param vg Given a view group with view groups inside it, set all children to have the same onClickListeners.
 * @param onClickListener// w  w  w  . j av a2 s  .c  o m
 * @param onLongClickListener
 */
private void setGridChildrenListener(ViewGroup vg, OnClickListener onClickListener,
        OnLongClickListener onLongClickListener) {
    // Go through the children and add all the onClick listeners.
    // Make sure to update if the layout changes.
    final int rows = vg.getChildCount();
    for (int row = 0; row < rows; row++) {
        final ViewGroup v = (ViewGroup) vg.getChildAt(row);
        final int columns = v.getChildCount();
        for (int column = 0; column < columns; column++) {
            final View button = v.getChildAt(column);
            button.setOnClickListener(onClickListener);
            button.setOnLongClickListener(onLongClickListener);
        }
    }
}

From source file:android.support.transition.TransitionPort.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   www  .ja v a 2 s. com
 */
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.github.pennyfive.sqlitestudio.ui.PackagesFragment.java

@Override
public void onLoadFinished(Loader<Result> resultLoader, Result result) {
    TextView databaseCountHeader = (TextView) View.inflate(getActivity(), R.layout.header_text, null);
    databaseCountHeader.setText(getResources().getQuantityString(R.plurals.databases_header_num_databases,
            result.getTotalNumDatabases(), result.getTotalNumDatabases()));
    listView.addHeaderView(databaseCountHeader, null, false);

    listView.setAdapter(new BinderAdapter<ScannedPackage>(getActivity(), result.getScannedPackages()) {
        @Override/*from   ww  w  .j a  va2s  .  co m*/
        protected View newView(LayoutInflater inflater, ViewGroup parent) {
            return inflater.inflate(R.layout.item_package, parent, false);
        }

        @Override
        protected void bindView(View view, final ScannedPackage item, int position) {
            Drawable applicationIcon = getApplicationIcon(item.getPackageName());
            ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(applicationIcon);

            String applicationName = getApplicationName(item.getPackageName());
            ((TextView) view.findViewById(R.id.application_name)).setText(applicationName);

            ((TextView) view.findViewById(R.id.package_name)).setText(item.getPackageName());

            ((TextView) view.findViewById(R.id.num_databases)).setText(String.valueOf(item.getNumDatabases()));

            final ViewGroup databaseLayout = (ViewGroup) view.findViewById(R.id.database_layout);
            databaseLayout.removeAllViews();

            final LayoutInflater inflater = LayoutInflater.from(getActivity());

            final int databasesCount = item.getNumDatabases();
            int initialItemCount = databasesCount > NUM_DATABASES_WHEN_COLLAPSED + 1
                    ? NUM_DATABASES_WHEN_COLLAPSED
                    : databasesCount;
            for (int i = 0; i < initialItemCount; i++) {
                databaseLayout
                        .addView(inflateDatabaseItem(inflater, databaseLayout, item.getDatabasePaths().get(i)));
            }

            if (databasesCount > initialItemCount) {
                View showAllFooter = inflater.inflate(R.layout.item_package_show_all_extra, null);
                databaseLayout.addView(showAllFooter);
                showAllFooter.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        databaseLayout.removeView(v);
                        for (int i = databaseLayout.getChildCount(); i < databasesCount; i++) {
                            databaseLayout.addView(inflateDatabaseItem(inflater, databaseLayout,
                                    item.getDatabasePaths().get(i)));
                        }
                    }
                });
            }
        }

        private View inflateDatabaseItem(LayoutInflater inflater, ViewGroup parent, final String databasePath) {
            View databaseItem = inflater.inflate(R.layout.item_package_database_extra, parent, false);
            String databaseFileName = databasePath.substring(databasePath.lastIndexOf('/') + 1,
                    databasePath.length());
            ((TextView) databaseItem.findViewById(R.id.text)).setText(databaseFileName);
            databaseItem.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    onDatabaseSelected(databasePath);
                }
            });
            return databaseItem;
        }
    });
}

From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java

private void updateHeaderAmPm() {
    if (mIs24HourView) {
        mAmPmLayout.setVisibility(View.GONE);
    } else {//w  ww  .  j  a  v a  2s .  c om
        // Ensure that AM/PM layout is in the correct position.
        final String dateTimePattern = getBestTimePattern(mCurrentLocale, false);
        final boolean amPmAtStart = dateTimePattern.startsWith("a");
        final ViewGroup parent = (ViewGroup) mAmPmLayout.getParent();
        final int targetIndex = amPmAtStart ? 0 : parent.getChildCount() - 1;
        final int currentIndex = parent.indexOfChild(mAmPmLayout);
        if (targetIndex != currentIndex) {
            parent.removeView(mAmPmLayout);
            parent.addView(mAmPmLayout, targetIndex);
        }

        updateAmPmLabelStates(mInitialHourOfDay < 12 ? AM : PM);
    }
}

From source file:com.base.view.slidemenu.SlideMenu.java

protected final boolean canScrollVertically(View v, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();

        final int childCount = viewGroup.getChildCount();
        for (int index = 0; index < childCount; index++) {
            View child = viewGroup.getChildAt(index);
            final int left = child.getLeft();
            final int top = child.getTop();
            if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top
                    && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility()
                    && (ScrollDetectors.canScrollVertical(child, dy)
                            || canScrollVertically(child, dy, x + scrollX - left, y + scrollY - top))) {
                return true;
            }//from ww w. j  ava2 s  .c o  m
        }
    }

    return ViewCompat.canScrollVertically(v, -dy);
}

From source file:com.base.view.slidemenu.SlideMenu.java

/**
 * Detect whether the views inside content are slidable
 *//*ww  w  .ja  v  a2  s.  com*/
protected final boolean canScrollHorizontally(View v, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();

        final int childCount = viewGroup.getChildCount();
        for (int index = 0; index < childCount; index++) {
            View child = viewGroup.getChildAt(index);
            final int left = child.getLeft();
            final int top = child.getTop();
            if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top
                    && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility()
                    && (ScrollDetectors.canScrollHorizontal(child, dx)
                            || canScrollHorizontally(child, dx, x + scrollX - left, y + scrollY - top))) {
                return true;
            }
        }
    }

    return ViewCompat.canScrollHorizontally(v, -dx);
}

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

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from   w w  w  .  java2s  .  c o  m
    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(SessionDetailActivity.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.ncode.android.apps.schedo.ui.EventDetailActivity.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from w w  w.  j  a  v  a 2 s.  c om
    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(EventDetailActivity.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.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

/**
 * Sets the font on all TextViews in the ViewGroup. Searches recursively for
 * all inner ViewGroups as well. Just add a check for any other views you
 * want to set as well (EditText, etc.)/*from w w  w .  ja v a 2 s.com*/
 */
private void setFont(ViewGroup group, Typeface font) {
    int count = group.getChildCount();
    View v;
    for (int i = 0; i < count; i++) {
        v = group.getChildAt(i);
        if (v instanceof TextView || v instanceof EditText || v instanceof Button) {
            ((TextView) v).setTypeface(font);
        } else if (v instanceof ViewGroup)
            setFont((ViewGroup) v, font);
    }
}

From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java

private static void setLollipopMenuOverflowIconColor(final ViewGroup toolbar, final int color) {
    try {/*from w ww  .  j a  v a2 s.c o m*/
        //for API 23 (Android 6): at this point method Toolbar.setOverflowIcon(Drawable) has no effect
        toolbar.getClass().getMethod("getMenu").invoke(toolbar);
        AppearanceUtils.callWhenLoaded(toolbar, new Runnable() {
            @Override
            public void run() {
                try {
                    final ViewGroup actionMenuView = (ViewGroup) findViewByClassName(toolbar,
                            "android.widget.ActionMenuView");

                    Runnable setOverflowIcon = new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Class<?> toolbarClass = toolbar.getClass();
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                    Drawable overflowIcon = (Drawable) toolbarClass.getMethod("getOverflowIcon")
                                            .invoke(toolbar);
                                    setColorFilter(overflowIcon);
                                    toolbarClass.getMethod("setOverflowIcon", Drawable.class).invoke(toolbar,
                                            overflowIcon);
                                } else {
                                    ImageView overflowButton = (ImageView) findViewByClassName(actionMenuView,
                                            "android.widget.ActionMenuPresenter$OverflowMenuButton");
                                    if (overflowButton != null) {
                                        Drawable overflowIcon = overflowButton.getDrawable();
                                        setColorFilter(overflowIcon);
                                        overflowButton.setImageDrawable(overflowIcon);
                                    }
                                }
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }

                        private void setColorFilter(Drawable overflowIcon) {
                            overflowIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                        }
                    };

                    if (actionMenuView.getChildCount() == 0) {
                        AppearanceUtils.callWhenLoaded(actionMenuView == null ? toolbar : actionMenuView,
                                setOverflowIcon);
                    } else {
                        setOverflowIcon.run();
                    }
                } catch (Exception e) {
                    Logger.e(TAG, e);
                }
            }

            private View findViewByClassName(ViewGroup group, String className) {
                for (int i = 0, size = group.getChildCount(); i < size; ++i) {
                    View child = group.getChildAt(i);
                    if (child.getClass().getName().equals(className)) {
                        return child;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
}