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.cp.mylibrary.custom.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;/*from   w  ww .  j  a v  a 2 s  .  co  m*/
    /* ? */
    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);
                }
            }

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

From source file:com.xnf.henghenghui.ui.view.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //      if (disableViewPager)
    //         return;
    /* ? *///from ww w .j a v  a  2 s .c  o m
    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);
                }
            }
            slidingBlockDrawable.setBounds((int) slidingBlockLeft, 0, (int) slidingBlockRight, getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

From source file:cn.liuguangqiang.swipeback.SwipeBackLayout.java

/**
 * Find out the scrollable child view from a ViewGroup.
 *
 * @param viewGroup//from ww w .j a v a  2s.co m
 */
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) {
                scrollChild = child;
                return;
            }
        }
    }
}

From source file:com.ohso.omgubuntu.BaseFragment.java

private void toggleFooter(int visibleItemCount, int firstVisibleItem, int totalItemCount, ViewGroup view) {
    if (visibleItemCount > 0 && (firstVisibleItem + visibleItemCount >= totalItemCount) && footerEnabled) {
        final View child = view.getChildAt((adapter.getRealCount() - 1) - firstVisibleItem);
        if (child != null) {
            if (child.getBottom() > view.getBottom() - (adapter.getFooterHeight() / 1.5)) {
                // Above
                if (footerView.isShown())
                    hidefooterView();/*from ww w  .ja va 2 s  .  com*/
            } else {
                // Below
                if (!footerView.isShown())
                    showFooterView();
            }
        }
    }
}

From source file:com.cicada.startup.common.ui.view.indicator.ViewPagerIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;//from   w  ww .jav  a2s .c  o m
    /* ? */
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && slidingBlockDrawable != null) {
        View currentTab = tabsLayout.getChildAt(currentPosition);
        if (currentTab != null) {
            float slidingBlockLeft = getTabTextLeft((ViewGroup) currentTab);
            float slidingBlockRight = getTabTextRight((ViewGroup) currentTab);
            if (currentPositionOffset > 0f && currentPosition < tabsLayout.getChildCount() - 1) {
                View nextTab = tabsLayout.getChildAt(currentPosition + 1);
                if (nextTab != null) {
                    final float nextTabLeft = getTabTextLeft((ViewGroup) nextTab);
                    final float nextTabRight = getTabTextRight((ViewGroup) nextTab);
                    slidingBlockLeft = (currentPositionOffset * nextTabLeft
                            + (1f - currentPositionOffset) * slidingBlockLeft);
                    slidingBlockRight = (currentPositionOffset * nextTabRight
                            + (1f - currentPositionOffset) * slidingBlockRight);
                }
            }
            slidingBlockDrawable.setBounds((int) slidingBlockLeft, getHeight() - slidingBlockHeight,
                    (int) slidingBlockRight, getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

From source file:com.java2s.intents4.IntentsDemo4Activity.java

private IntentFilter createFilterFromEditTextFields() {
    IntentFilter filter = new IntentFilter();

    if (filterActionsLayout != null) {
        int count = filterActionsLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String action = ((EditText) ((ViewGroup) filterActionsLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();/*  w  w w. j a  v a 2s .  c  om*/
            if (action.length() != 0) {
                filter.addAction(action);
            }
        }
    }

    if (filterSchemeLayout != null) {
        int count = filterSchemeLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String scheme = ((EditText) ((ViewGroup) filterSchemeLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (scheme.length() != 0) {
                filter.addDataScheme(scheme);
            }
        }
    }

    if (filterAuthLayout != null) {
        int count = filterAuthLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String auth = ((EditText) ((ViewGroup) filterAuthLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (auth.length() != 0) {
                Scanner scanner = new Scanner(auth);
                scanner.useDelimiter(":");
                String host = null;
                String port = null;
                if (scanner.hasNext()) {
                    host = scanner.next();
                }
                if (scanner.hasNext()) {
                    port = scanner.next();
                }
                filter.addDataAuthority(host, port);
            }
        }
    }

    if (filterPathLayout != null) {
        int count = filterPathLayout.getChildCount();
        for (int i = 0; i < count; i++) {

            ViewGroup group = (ViewGroup) filterPathLayout.getChildAt(i);
            String path = ((EditText) group.getChildAt(1)).getText().toString().trim();
            String pattern = ((TextView) ((ViewGroup) group.getChildAt(2)).getChildAt(0)).getText().toString()
                    .trim(); // ((TextView)

            int patternInt = 0;
            if (pattern.equals(pathPatterns[0])) {
                patternInt = PatternMatcher.PATTERN_LITERAL;
            }
            if (pattern.equals(pathPatterns[1])) {
                patternInt = PatternMatcher.PATTERN_PREFIX;
            }
            if (pattern.equals(pathPatterns[2])) {
                patternInt = PatternMatcher.PATTERN_SIMPLE_GLOB;
            }
            if (path.length() != 0) {
                filter.addDataPath(path, patternInt);
            }
        }
    }

    if (filterTypeLayout != null) {
        int count = filterTypeLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String aType = ((EditText) ((ViewGroup) filterTypeLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (aType.length() != 0) {
                try {
                    filter.addDataType(aType);
                } catch (MalformedMimeTypeException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    if (filterCategoriesLayout != null) {
        int count = filterCategoriesLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String cat = ((EditText) ((ViewGroup) filterCategoriesLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (cat.length() != 0) {
                filter.addCategory(cat);
            }
        }
    }
    return filter;
}

From source file:com.normalexception.app.rx8club.fragment.pm.PrivateMessageInboxFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MainApplication.setState(AppState.State.PMINBOX, this);

    if (TimeoutFactory.getInstance().checkTimeout(this)) {
        pmlist = new ArrayList<PMModel>();
        lv = (ListView) view.findViewById(R.id.mainlistview);

        ViewGroup header = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.view_inbox_header, lv,
                false);//from w w  w.  j  a  v a  2 s.c  om

        InboxHeaderListener ihl = new InboxHeaderListener();
        View v = null;
        for (int i = 0; i < header.getChildCount(); i++) {
            v = header.getChildAt(i);
            if (v instanceof Button)
                v.setOnClickListener(ihl);
        }
        lv.addHeaderView(header);

        Log.v(TAG, "PM Activity Started");

        if (savedInstanceState == null || (pmva == null || pmva.getCount() == 0))
            constructView();
        else {
            updateList();
        }
    }
}

From source file:connect.app.com.connect.calendar.DayPickerView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    //        final TypedArray a = context.obtainStyledAttributes(attrs,
    //                R.styleable.CalendarView, defStyleAttr, defStyleRes);
    ////from w w  w .  j ava2 s . com
    //        final int firstDayOfWeek = a.getInt(R.styleable.CalendarView_firstDayOfWeek,
    //                LocaleData.get(Locale.getDefault()).firstDayOfWeek);
    final int firstDayOfWeek = 1;
    //
    //        final String minDate = a.getString(R.styleable.CalendarView_minDate);
    final String minDate = null;
    //        final String maxDate = a.getString(R.styleable.CalendarView_maxDate);
    final String maxDate = null;
    //
    //        final int monthTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_monthTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_Month);
    //        final int dayOfWeekTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_weekDayTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek);
    //        final int dayTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_dateTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_Day);
    //
    //        final ColorStateList daySelectorColor = a.getColorStateList(
    //                R.styleable.CalendarView_daySelectorColor);
    //
    //        a.recycle();

    // Set up adapter.
    mAdapter = new DayPickerPagerAdapter(context, R.layout.layout_test, com.retrofit.R.id.scrollView);
    //        mAdapter.setMonthTextAppearance(monthTextAppearanceResId);
    //        mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId);
    //        mAdapter.setDayTextAppearance(dayTextAppearanceResId);
    //        mAdapter.setDaySelectorColor(daySelectorColor);

    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false);

    // Transfer all children from content to here.
    while (content.getChildCount() > 0) {
        final View child = content.getChildAt(0);
        content.removeViewAt(0);
        addView(child);
    }

    mPrevButton = (ImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mOnClickListener);

    mNextButton = (ImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mOnClickListener);

    mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(mOnPageChangedListener);

    // Proxy the month text color into the previous and next buttons.
    //        if (monthTextAppearanceResId != 0) {
    //            final TypedArray ta = mContext.obtainStyledAttributes(null,
    //                    ATTRS_TEXT_COLOR, 0, monthTextAppearanceResId);
    //            final ColorStateList monthColor = ta.getColorStateList(0);
    //            if (monthColor != null) {
    //                mPrevButton.setImageTintList(monthColor);
    //                mNextButton.setImageTintList(monthColor);
    //            }
    //            ta.recycle();
    //        }

    // Set up min and max dates.
    final Calendar tempDate = Calendar.getInstance();
    if (!CalendarView.parseDate(minDate, tempDate)) {
        tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
    }
    final long minDateMillis = tempDate.getTimeInMillis();

    if (!CalendarView.parseDate(maxDate, tempDate)) {
        tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
    }
    final long maxDateMillis = tempDate.getTimeInMillis();

    if (maxDateMillis < minDateMillis) {
        throw new IllegalArgumentException("maxDate must be >= minDate");
    }

    final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis);

    setFirstDayOfWeek(firstDayOfWeek);
    setMinDate(minDateMillis);
    setMaxDate(maxDateMillis);
    setDate(setDateMillis, false);

    // Proxy selection callbacks to our own listener.
    mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() {
        @Override
        public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) {
            if (mOnDaySelectedListener != null) {
                mOnDaySelectedListener.onDaySelected(DayPickerView.this, day);
            }
        }
    });
}

From source file:com.artemchep.horario.ui.widgets.SwipeBackLayout.java

private View findScrollViewR(ViewGroup viewGroup) {
    if (viewGroup.getChildCount() > 0) {
        int count = viewGroup.getChildCount();
        for (int i = 0; i < count; i++) {
            View view = viewGroup.getChildAt(i);
            if (view instanceof AbsListView || view instanceof ScrollView || view instanceof ScrollingView
                    || view instanceof ViewPager || view instanceof WebView) {
                return view;
            } else if (view instanceof ViewGroup) {
                view = findScrollViewR((ViewGroup) view);
                if (view != null) {
                    return view;
                }/*  w w  w.  ja v  a 2  s.  com*/
            }
        }
    }
    return null;
}

From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java

@Override
public void endSearchMode(boolean animate) {
    Utils.hideKeyboard(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (animate) {
            // If the device has rotated, we need to calculate a new center for the animation.
            if (searchButtonCenter == null) {
                final View actionMenuView = searchToolbar.getChildAt(2);
                final ViewGroup actionMenuViewGroup = (ViewGroup) actionMenuView;
                final View button = actionMenuViewGroup.getChildAt(0);
                System.out.println(button.getClass());

                searchButtonCenter = new Point(
                        (int) (button.getX() + actionMenuView.getX() - button.getWidth() / 2),
                        (int) (button.getY() + actionMenuView.getY() + button.getHeight() / 2));
            }/*from   ww w  .jav  a  2s  .  c o m*/

            final Animator animator = ViewAnimationUtils.createCircularReveal(searchToolbar,
                    searchButtonCenter.x, searchButtonCenter.y, searchToolbar.getWidth(), 0);
            animator.setDuration(revealStatusBarDuration);
            animator.addListener(new EndSearchModeAnimationListener(searchToolbar));
            toolbar.setVisibility(View.VISIBLE);
            animator.start();
        } else {
            searchToolbar.setVisibility(View.INVISIBLE);
        }

        setSupportActionBar(toolbar);
    } else {
        toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.primary));

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setCustomView(R.layout.toolbar_search);
            actionBar.setDisplayShowCustomEnabled(false);
            actionBar.setDisplayShowTitleEnabled(true);
        }
    }

    viewPager.setVisibility(View.VISIBLE);
    if (animate) {
        searchResults.animate().alpha(0).setDuration(crossfadeViewPagerSearchDuration)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        searchResults.setVisibility(View.GONE);
                    }
                });

        viewPager.animate().alpha(1).setDuration(crossfadeViewPagerSearchDuration).setListener(null);
    } else {
        viewPager.setAlpha(1);
        searchResults.setAlpha(0);
        searchResults.setVisibility(View.GONE);
    }

    searchInputSub.unsubscribe();
    searchInputLengthSub.unsubscribe();
    invalidateOptionsMenu();
}