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:com.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java

@Override
public View getItemView(int position) {
    if (position < 0 || position > mAdapter.getCount() - 1) {
        return null;
    }/*from ww w .jav a2 s.c om*/
    final ViewGroup group = (ViewGroup) getChildAt(position);
    return group.getChildAt(0);
}

From source file:com.mishiranu.dashchan.util.DrawerToggle.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void setActionBarUpIndicatorObsolete(Drawable upDrawable) {
    if (C.API_JELLY_BEAN_MR2) {
        activity.getActionBar().setHomeAsUpIndicator(upDrawable);
    } else {/*  www  .ja v  a2 s  .c o m*/
        if (upIndicatorView == null) {
            View home = activity.findViewById(android.R.id.home);
            if (home == null) {
                return;
            }
            ViewGroup parent = (ViewGroup) home.getParent();
            int childCount = parent.getChildCount();
            if (childCount != 2) {
                return;
            }
            View first = parent.getChildAt(0);
            View second = parent.getChildAt(1);
            View up = first.getId() == android.R.id.home ? second : first;
            if (up instanceof ImageView) {
                upIndicatorView = (ImageView) up;
            }
        }
        if (upIndicatorView != null) {
            upIndicatorView.setImageDrawable(upDrawable);
        }
    }
}

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

private View findViewForItem(MenuItem item) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null)
        return null;

    final int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        if (child instanceof MenuView.ItemView && ((MenuView.ItemView) child).getItemData() == item) {
            return child;
        }//from   www  . ja  v a  2  s  .  c  om
    }
    return null;
}

From source file:com.xengar.android.stocktracker.ui.SettingsActivity.java

/**
 * Set up the {@link android.support.v7.widget.Toolbar}, if the API is available.
 *///w  ww.  j av a 2 s  .co  m
private void setupToolBar() {
    Toolbar toolbar;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        root.addView(toolbar, 0);
    } else {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        root.removeAllViews();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = toolbar.getHeight();
        }
        content.setPadding(0, height, 0, 0);
        root.addView(content);
        root.addView(toolbar);
    }
    toolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:com.github.riotopsys.malforandroid2.fragment.AnimeDetailFragment.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    ViewGroup vg = (ViewGroup) v;
    if (vg.getChildAt(0).getHeight() > v.getHeight()) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            requestDisallowParentInterceptTouchEvent(v, true);
        } else if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            requestDisallowParentInterceptTouchEvent(v, false);
        }// w  w w . j av a  2 s.  c om
    }
    return false;
}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;/*w ww .java  2  s. co  m*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

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

/**
 * ViewPager/*from w  w  w.j  a  v a  2 s  .c  o  m*/
 * @param viewPager ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {
            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset
                            * (view.getWidth() + getLeftMargin(view) + getRightMargin(view))));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    requestLayout();
}

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

/**
 * ViewPager/*from ww  w .  ja va2s .com*/
 *
 * @param viewPager ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.addOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {
            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset
                            * (view.getWidth() + getLeftMargin(view) + getRightMargin(view))));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    requestLayout();
}

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

/**
 * ?//  w w  w .  j a  va 2  s  .  co  m
 */
private void scrollToChild(int position, int offset) {
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && position < tabsLayout.getChildCount()) {
        View view = tabsLayout.getChildAt(position);
        if (view != null) {
            //X??
            int newScrollX = view.getLeft() + offset - getLeftMargin(view);
            if (position > 0 || offset > 0) {
                newScrollX -= getWidth() / 2 - getOffset(view.getWidth()) / 2;
            }

            //?X???
            if (newScrollX != lastScrollX) {
                lastScrollX = newScrollX;
                scrollTo(newScrollX, 0);
            }
        }
    }
}

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

private void resetLayout(ViewGroup viewGroup) {
    if (viewGroup.getChildCount() > 0) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            viewGroup.getChildAt(i).setBackgroundColor(getResources().getColor(android.R.color.white));
        }/*w ww  . j  a  v  a  2  s .  c o  m*/
    }
}