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.learn.mobile.customview.henrytao.SmoothAppBarLayout.java

protected void initViews() {
    if (mViewPagerId > 0) {
        vViewPager = (ViewPager) getRootView().findViewById(mViewPagerId);
    } else {/*from w ww  .  j a  v  a 2 s.  c om*/
        int i = 0;
        ViewGroup parent = (ViewGroup) getParent();
        View child;
        for (int z = parent.getChildCount(); i < z; i++) {
            child = parent.getChildAt(i);
            if (child instanceof ViewPager) {
                vViewPager = (ViewPager) child;
                break;
            }
        }
    }
}

From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java

private void findStickyViews(View v) {
    if (!detainStickyView(v) && (v instanceof ViewGroup)) {
        ViewGroup vg = (ViewGroup) v;
        for (int i = 0; i < vg.getChildCount(); i++)
            findStickyViews(vg.getChildAt(i));
    }// w  w w  .j  a  v a 2  s .c om
}

From source file:com.anandbibek.notifyme.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.def_settings:
        startActivity(new Intent(this, EditFilterActivity.class).putExtra("filter", 9999).setAction("edit"));
        return true;

    case R.id.main_menu_settings:
        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return true;

    case R.id.main_menu_checkaccessibility:
        prefs.setPrevVersion(0);//  w  w w . ja v a2 s.co m
        ((TemporaryStorage) getApplicationContext()).accessGranted(false);
        finish();
        startActivity(getIntent());
        return true;

    case R.id.main_menu_help:
        new AlertDialog.Builder(this).setMessage(R.string.main_menu_help_message)
                .setTitle(R.string.main_menu_help_title)
                .setPositiveButton(R.string.main_menu_help_ok_button, null).setNegativeButton(
                        R.string.main_menu_help_question_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("http://forum.xda-developers.com/showthread.php?t=2707698"))
                                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                            }
                        })
                .show();
        return true;

    case R.id.main_menu_about:
        ViewGroup about = (ViewGroup) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_about, null);
        ((TextView) about.getChildAt(0)).setMovementMethod(LinkMovementMethod.getInstance());
        new AlertDialog.Builder(this).setView(about).setTitle(R.string.main_menu_about_title)
                .setPositiveButton(R.string.main_menu_about_ok_button, null).show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.andryr.musicplayer.activities.EqualizerActivity.java

private void updateSeekBars() {
    ViewGroup layout = (ViewGroup) findViewById(R.id.equalizer_layout);

    final short[] range = AudioEffects.getBandLevelRange();

    short bands = AudioEffects.getNumberOfBands();

    for (short band = 0; band < bands; band++) {

        View v = layout.getChildAt(band);

        final TextView freqTextView = (TextView) v.findViewById(R.id.frequency);
        final TextView levelTextView = (TextView) v.findViewById(R.id.level);
        final SeekBar seekBar = (SeekBar) v.findViewById(R.id.seek_bar);

        int freq = AudioEffects.getCenterFreq(band);
        if (freq < 1000 * 1000) {
            freqTextView.setText(freq / 1000 + "Hz");
        } else {//from  w ww  . j a v  a2  s .  c om
            freqTextView.setText(freq / (1000 * 1000) + "kHz");

        }

        short level = AudioEffects.getBandLevel(band);
        seekBar.setProgress(level - range[0]);

        levelTextView.setText((level > 0 ? "+" : "") + level / 100 + "dB");

    }

}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

/**
 * Bind the BottomBar to your Activity, and inflate your layout here.
 * <p/>//  w w w  .  j  av a  2  s.co m
 * Remember to also call {@link #onRestoreInstanceState(Bundle)} inside
 * of your {@link Activity#onSaveInstanceState(Bundle)} to restore the state.
 *
 * @param activity           an Activity to attach to.
 * @param savedInstanceState a Bundle for restoring the state on configuration change.
 * @return a BottomBar at the bottom of the screen.
 */
public static BottomBar attach(Activity activity, Bundle savedInstanceState) {
    BottomBar bottomBar = new BottomBar(activity);
    bottomBar.onRestoreInstanceState(savedInstanceState);

    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    View oldLayout = contentView.getChildAt(0);
    contentView.removeView(oldLayout);

    bottomBar.setPendingUserContentView(oldLayout);
    contentView.addView(bottomBar, 0);

    return bottomBar;
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private void setImage(int imageRes) {
    for (int idx = 0; idx < mImageHolder.getChildCount(); idx++) {
        View view = mImageHolder.getChildAt(idx);
        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;
            if (imageView.getScaleType() != ImageView.ScaleType.MATRIX) {
                setImage(imageView, imageRes);
            }/*from ww  w. jav a  2 s .  c  o  m*/
        } else if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int childIdx = 0; childIdx != viewGroup.getChildCount(); childIdx++) {
                View child = viewGroup.getChildAt(childIdx);
                if (child instanceof ImageView) {
                    ImageView imageView = (ImageView) child;
                    if (imageView.getScaleType() != ImageView.ScaleType.MATRIX) {
                        setImage(imageView, imageRes);
                    }
                }
            }
        }
    }

    mPrevBm1 = fillUpperLeft(getDrawable(imageRes), mUpperLeftFill, mPrevBm1);
    mPrevBm2 = fillLowerLeft(getDrawable(imageRes), mLowerLeftFill, mPrevBm2);
    mPrevBm3 = setScaledImage(getDrawable(imageRes), mCenterFill, mPrevBm3);
}

From source file:com.zzc.androidtrain.view.refresh.SmoothAppBarLayout.java

private void initViews() {
    if (mViewPagerId > 0) {
        vViewPager = (ViewPager) getRootView().findViewById(mViewPagerId);
    } else {/*from   w ww  . j a va  2s .c om*/
        int i = 0;
        ViewGroup parent = (ViewGroup) getParent();
        View child;
        for (int z = parent.getChildCount(); i < z; i++) {
            child = parent.getChildAt(i);
            if (child instanceof ViewPager) {
                vViewPager = (ViewPager) child;
                break;
            }
        }
    }
}

From source file:com.quinsoft.zeidon.android.ZeidonAndroidViewDelegate.java

public void setParentViewForChildViews(android.view.View parent, android.view.View child) {
    if (child instanceof ZeidonDisplayView) {
        ((ZeidonDisplayView) child).setZeidonParent(parent);
        return;/*from  www .  j  a  v  a  2 s  . c  o m*/
    }

    if (child instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) child;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            android.view.View tempChild = viewGroup.getChildAt(i);
            setParentViewForChildViews(parent, tempChild);
        }
    }
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

/**
 * Bind the BottomBar to the specified View's parent, and inflate
 * your layout there. Useful when the BottomBar overlaps some content
 * that shouldn't be overlapped./*  www.  ja v  a2 s  .c  om*/
 * <p/>
 * Remember to also call {@link #onRestoreInstanceState(Bundle)} inside
 * of your {@link Activity#onSaveInstanceState(Bundle)} to restore the state.
 *
 * @param view               a View, which parent we're going to attach to.
 * @param savedInstanceState a Bundle for restoring the state on configuration change.
 * @return a BottomBar at the bottom of the screen.
 */
public static BottomBar attach(View view, Bundle savedInstanceState) {
    BottomBar bottomBar = new BottomBar(view.getContext());
    bottomBar.onRestoreInstanceState(savedInstanceState);

    ViewGroup contentView = (ViewGroup) view.getParent();

    if (contentView != null) {
        View oldLayout = contentView.getChildAt(0);
        contentView.removeView(oldLayout);

        bottomBar.setPendingUserContentView(oldLayout);
        contentView.addView(bottomBar, 0);
    } else {
        bottomBar.setPendingUserContentView(view);
    }

    return bottomBar;
}

From source file:android.databinding.ViewDataBinding.java

private static void mapBindings(DataBindingComponent bindingComponent, View view, Object[] bindings,
        IncludedLayouts includes, SparseIntArray viewsWithIds, boolean isRoot) {
    final int indexInIncludes;
    final ViewDataBinding existingBinding = getBinding(view);
    if (existingBinding != null) {
        return;/*from w  ww.  j  a va 2s.  c  om*/
    }
    final String tag = (String) view.getTag();
    boolean isBound = false;
    if (isRoot && tag != null && tag.startsWith("layout")) {
        final int underscoreIndex = tag.lastIndexOf('_');
        if (underscoreIndex > 0 && isNumeric(tag, underscoreIndex + 1)) {
            final int index = parseTagInt(tag, underscoreIndex + 1);
            if (bindings[index] == null) {
                bindings[index] = view;
            }
            indexInIncludes = includes == null ? -1 : index;
            isBound = true;
        } else {
            indexInIncludes = -1;
        }
    } else if (tag != null && tag.startsWith(BINDING_TAG_PREFIX)) {
        int tagIndex = parseTagInt(tag, BINDING_NUMBER_START);
        if (bindings[tagIndex] == null) {
            bindings[tagIndex] = view;
        }
        isBound = true;
        indexInIncludes = includes == null ? -1 : tagIndex;
    } else {
        // Not a bound view
        indexInIncludes = -1;
    }
    if (!isBound) {
        final int id = view.getId();
        if (id > 0) {
            int index;
            if (viewsWithIds != null && (index = viewsWithIds.get(id, -1)) >= 0 && bindings[index] == null) {
                bindings[index] = view;
            }
        }
    }

    if (view instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) view;
        final int count = viewGroup.getChildCount();
        int minInclude = 0;
        for (int i = 0; i < count; i++) {
            final View child = viewGroup.getChildAt(i);
            boolean isInclude = false;
            if (indexInIncludes >= 0) {
                String childTag = (String) child.getTag();
                if (childTag != null && childTag.endsWith("_0") && childTag.startsWith("layout")
                        && childTag.indexOf('/') > 0) {
                    // This *could* be an include. Test against the expected includes.
                    int includeIndex = findIncludeIndex(childTag, minInclude, includes, indexInIncludes);
                    if (includeIndex >= 0) {
                        isInclude = true;
                        minInclude = includeIndex + 1;
                        final int index = includes.indexes[indexInIncludes][includeIndex];
                        final int layoutId = includes.layoutIds[indexInIncludes][includeIndex];
                        int lastMatchingIndex = findLastMatching(viewGroup, i);
                        if (lastMatchingIndex == i) {
                            bindings[index] = DataBindingUtil.bind(bindingComponent, child, layoutId);
                        } else {
                            final int includeCount = lastMatchingIndex - i + 1;
                            final View[] included = new View[includeCount];
                            for (int j = 0; j < includeCount; j++) {
                                included[j] = viewGroup.getChildAt(i + j);
                            }
                            bindings[index] = DataBindingUtil.bind(bindingComponent, included, layoutId);
                            i += includeCount - 1;
                        }
                    }
                }
            }
            if (!isInclude) {
                mapBindings(bindingComponent, child, bindings, includes, viewsWithIds, false);
            }
        }
    }
}