Example usage for android.view ViewGroup getChildAt

List of usage examples for android.view ViewGroup getChildAt

Introduction

In this page you can find the example usage for android.view ViewGroup getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:android.support.v7.widget.ActionMenuPresenter.java

@Override
public boolean filterLeftoverView(ViewGroup parent, int childIndex) {
    if (parent.getChildAt(childIndex) == mOverflowButton)
        return false;
    return super.filterLeftoverView(parent, childIndex);
}

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId,
        Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description,
        final TextView breadcrumb) {
    // Pull out the root layout of the dialog and set the background drawable, to be
    // faded in during the transition.
    final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0);
    twoPane.setVisibility(View.INVISIBLE);

    // If the appropriate data is embedded in the intent and there is an icon specified
    // in the content fragment, we animate the icon from its initial position to the final
    // position. Otherwise, we perform a simpler transition in which the ActionFragment
    // slides in and the ContentFragment text fields slide in.
    mIntroAnimationInProgress = true;/*from   w w w  .  ja v a2  s. c  om*/
    List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent());
    TransitionImageAnimation ltransitionAnimation = null;
    final Uri iconUri;
    final int color;
    if (images != null && images.size() > 0) {
        if (iconResourceId != 0) {
            iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId));
        } else if (iconResourceUri != null) {
            iconUri = iconResourceUri;
        } else {
            iconUri = null;
        }
        TransitionImage src = images.get(0);
        color = src.getBackground();
        if (iconUri != null) {
            ltransitionAnimation = new TransitionImageAnimation(contentView);
            ltransitionAnimation.addTransitionSource(src);
            ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0)
                    .interpolator(new DecelerateInterpolator(1f));
        }
    } else {
        iconUri = null;
        color = 0;
    }
    final TransitionImageAnimation transitionAnimation = ltransitionAnimation;

    // Fade out the old activity, and hard cut the new activity.
    activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out);

    int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background);
    mBgDrawable.setColor(bgColor);
    mBgDrawable.setAlpha(0);
    twoPane.setBackground(mBgDrawable);

    // If we're animating the icon, we create a new ImageView in which to place the embedded
    // bitmap. We place it in the root layout to match its location in the previous activity.
    mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout);
    if (transitionAnimation != null) {
        transitionAnimation.listener(new TransitionImageAnimation.Listener() {
            @Override
            public void onRemovedView(TransitionImage src, TransitionImage dst) {
                if (icon != null) {
                    //want to make sure that users still see at least the source image
                    // if the dst image is too large to finish downloading before the
                    // animation is done. Check if the icon is not visible. This mean
                    // BaseContentFragement have not finish downloading the image yet.
                    if (icon.getVisibility() != View.VISIBLE) {
                        icon.setImageDrawable(src.getBitmap());
                        int intrinsicWidth = icon.getDrawable().getIntrinsicWidth();
                        LayoutParams lp = icon.getLayoutParams();
                        lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth;
                        icon.setVisibility(View.VISIBLE);
                    }
                    icon.setAlpha(1f);
                }
                if (mShadowLayer != null) {
                    mShadowLayer.setShadowsAlpha(1f);
                }
                onIntroAnimationFinished();
            }
        });
        icon.setAlpha(0f);
        if (mShadowLayer != null) {
            mShadowLayer.setShadowsAlpha(0f);
        }
    }

    // We need to defer the remainder of the animation preparation until the first
    // layout has occurred, as we don't yet know the final location of the icon.
    twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time,  the texture is actually not created
            // delay a little so we can make sure all hardware layer is created before
            // animation, in that way we can avoid the jittering of start animation
            twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!mFragment.isAdded()) {
                    // We have been detached before this could run, so just bail
                    return;
                }

                twoPane.setVisibility(View.VISIBLE);
                final int secondaryDelay = SLIDE_IN_DISTANCE;

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255);
                oa.setDuration(ANIMATE_IN_DURATION);
                oa.setStartDelay(secondaryDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                View actionFragmentView = activity.findViewById(mActionAreaId);
                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
                int endDist = isRtl ? -actionFragmentView.getMeasuredWidth()
                        : actionFragmentView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                if (icon != null && transitionAnimation != null) {
                    // now we get the icon view in place,  update the transition target
                    TransitionImage target = new TransitionImage();
                    target.setUri(iconUri);
                    target.createFromImageView(icon);
                    if (icon.getBackground() instanceof ColorDrawable) {
                        ColorDrawable d = (ColorDrawable) icon.getBackground();
                        target.setBackground(d.getColor());
                    }
                    transitionAnimation.addTransitionTarget(target);
                    transitionAnimation.startTransition();
                } else if (icon != null) {
                    prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                            new DecelerateInterpolator(1.0f), true /* is the icon */);
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(0f);
                    }
                }
            }
        };
    });
}

From source file:com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.java

/**
 * Reuses item views when it can/*from   w w  w .ja  va2s  .  com*/
 */
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);
                    if (IS_HONEYCOMB)
                        itemView.jumpDrawablesToCurrentState();
                }
                if (itemView != convertView) {
                    addItemView(itemView, childIndex);
                }
                childIndex++;
            }
        }
    }

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

From source file:com.liushengfan.test.customerviewgroup.view.PagerSlidingTabStrip.java

private void changeTextColor(int position) {
    for (int i = 0; i < tabCount; i++) {
        View view = tabsContainer.getChildAt(i);
        if (view instanceof TextView) {
            TextView tab = (TextView) view;
            if (position == i) {
                tab.setTextColor(getResources().getColor(R.color.sgk_red_common_bg));
            } else {
                tab.setTextColor(getResources().getColor(R.color.sgk_black_text_color));
            }//from   w w w .  j  av a2s . co  m
        } else if (view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) view;
            for (int j = 0; j < group.getChildCount(); j++) {
                View groupChild = group.getChildAt(j);
                if (groupChild instanceof TextView) {
                    TextView tab = (TextView) groupChild;
                    if (position == i) {
                        tab.setTextColor(getResources().getColor(R.color.sgk_red_common_bg));
                    } else {
                        tab.setTextColor(getResources().getColor(R.color.sgk_black_text_color));
                    }
                }
            }

        }
    }
}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

private String dumpViewGroup(int depth, ViewGroup vg, String existing_text) {
    String text = "";
    Log.d(Constants.LOG_TAG, "root view, depth:" + depth + "; view: " + vg);
    for (int i = 0; i < vg.getChildCount(); ++i) {
        View v = vg.getChildAt(i);
        if (Constants.IS_LOGGABLE) {
            Log.d(Constants.LOG_TAG, "depth: " + depth + "; " + v.getClass().toString() + "; view: " + v);
        }//  w  w  w. j  a  v  a  2s.co  m
        if (v.getId() == android.R.id.title || v instanceof android.widget.Button
                || v.getClass().toString().contains("android.widget.DateTimeView")) {
            if (Constants.IS_LOGGABLE) {
                Log.d(Constants.LOG_TAG, "I am going to skip this, but if I didn't, the text would be: "
                        + ((TextView) v).getText().toString());
            }
            if (existing_text.isEmpty() && v.getId() == android.R.id.title) {
                if (Constants.IS_LOGGABLE) {
                    Log.d(Constants.LOG_TAG,
                            "I was going to skip this, but the existing text was empty, and I need something.");
                }
            } else {
                continue;
            }
        }

        if (v instanceof TextView) {
            TextView tv = (TextView) v;
            if (tv.getText().toString() == "..." || tv.getText().toString() == ""
                    || isInteger(tv.getText().toString())
                    || tv.getText().toString().trim().equalsIgnoreCase(existing_text)) {
                if (Constants.IS_LOGGABLE) {
                    Log.d(Constants.LOG_TAG,
                            "Text is: " + tv.getText().toString() + " but I am going to skip this");
                }
                continue;
            }
            text += tv.getText().toString() + "\n";
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, tv.getText().toString());
            }
        }
        if (v instanceof ViewGroup) {
            text += dumpViewGroup(depth + 1, (ViewGroup) v, existing_text);
        }
    }
    return text;
}

From source file:com.efan.notlonely_android.view.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;// w w w  .  j  a v  a 2s .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.bt.download.android.gui.adapters.TransferListAdapter.java

private void initTouchFeedback(View v, TransferItem item) {
    v.setOnClickListener(viewOnClickListener);
    v.setOnLongClickListener(viewOnLongClickListener);
    v.setTag(item);/*  ww  w.  j  a  v a  2s  .c o m*/

    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;
        int count = vg.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = vg.getChildAt(i);
            initTouchFeedback(child, item);
        }
    }
}

From source file:com.yeahka.mach.android.widget.viewPager.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;//from  ww w  .j  a  va2  s.  c  om
    /* ? */
    ViewGroup tabsLayout = getTabsLayout();
    Log.d("drawable", "drawable=" + (slidingBlockDrawable == null));
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && slidingBlockDrawable != null) {
        resetLayout(tabsLayout);
        View currentTab = tabsLayout.getChildAt(currentPosition);
        if (currentTab != null) {
            float slidingBlockLeft = currentTab.getLeft();
            float slidingBlockRight = currentTab.getRight();
            if (currentPositionOffset > 0f && currentPosition < tabsLayout.getChildCount() - 1) {
                View nextTab = tabsLayout.getChildAt(currentPosition + 1);
                if (nextTab != null) {
                    final float nextTabLeft = nextTab.getLeft();
                    final float nextTabRight = nextTab.getRight();
                    slidingBlockLeft = (currentPositionOffset * nextTabLeft
                            + (1f - currentPositionOffset) * slidingBlockLeft);
                    slidingBlockRight = (currentPositionOffset * nextTabRight
                            + (1f - currentPositionOffset) * slidingBlockRight);
                }
            }
            slidingBlockDrawable.setBounds((int) slidingBlockLeft, 0, (int) slidingBlockRight, getHeight());
            slidingBlockDrawable.draw(canvas);
            currentTab.setBackgroundDrawable(slidingBlockDrawable);
            Log.d("drawable", "drawn");
        }
    }
}

From source file:me.xiaopan.psts.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (bottomLineColor != -1 && bottomLineHeight != -1) {
        if (bottomLinePaint == null) {
            bottomLinePaint = new Paint();
            bottomLinePaint.setColor(bottomLineColor);
        }/*from w w w . j a  va2 s  . c  o m*/
        canvas.drawRect(0, getBottom() - bottomLineHeight, getRight(), getBottom(), bottomLinePaint);
    }

    if (disableViewPager)
        return;
    /* ? */
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && slidingBlockDrawable != null) {
        View currentTab = tabsLayout.getChildAt(currentPosition);
        if (currentTab != null) {
            float slidingBlockLeft = currentTab.getLeft();
            float slidingBlockRight = currentTab.getRight();
            if (currentPositionOffset > 0f && currentPosition < tabsLayout.getChildCount() - 1) {
                View nextTab = tabsLayout.getChildAt(currentPosition + 1);
                if (nextTab != null) {
                    final float nextTabLeft = nextTab.getLeft();
                    final float nextTabRight = nextTab.getRight();
                    slidingBlockLeft = (currentPositionOffset * nextTabLeft
                            + (1f - currentPositionOffset) * slidingBlockLeft);
                    slidingBlockRight = (currentPositionOffset * nextTabRight
                            + (1f - currentPositionOffset) * slidingBlockRight);
                }
            }

            // ?
            if (disableTensileSlidingBlock) {
                int center = (int) (slidingBlockLeft + (slidingBlockRight - slidingBlockLeft) / 2);
                slidingBlockLeft = center - slidingBlockDrawable.getIntrinsicWidth() / 2;
                slidingBlockRight = center + slidingBlockDrawable.getIntrinsicWidth() / 2;
            }

            slidingBlockDrawable.setBounds((int) slidingBlockLeft,
                    getHeight() - slidingBlockDrawable.getIntrinsicHeight(), (int) slidingBlockRight,
                    getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

From source file:cn.wyx.android.swipeback.swipe.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup/* w  w w  .  j  a  v a  2 s.  c om*/
 */
private void findScrollView(ViewGroup viewGroup) {
    scrollChild = viewGroup;
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        View child;
        for (int i = 0; i < count; i++) {
            child = viewGroup.getChildAt(i);
            if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager
                    || child instanceof WebView || child instanceof RecyclerView) {
                scrollChild = child;
                return;
            }
        }
    }
}