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.ring.widget.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (disableViewPager)
        return;/*w w w  .j  a  v a  2 s  . c  om*/

    /* ? */
    ViewGroup tabsLayout = getTabsLayout();
    int tabCount = tabsLayout.getChildCount();
    if (tabsLayout == null || tabCount == 0) {
        return;
    }

    View currentTab = tabsLayout.getChildAt(currentPosition);
    if (currentTab == null) {
        return;
    }
    int height = getHeight();
    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 (slidingBlockDrawable != null) {
        // ?
        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);
    } else {

        rectPaint.setColor(barColor);

        canvas.drawRect(slidingBlockLeft, height - barHeight, slidingBlockRight, height, rectPaint);
        rectPaint.setColor(underlineColor);
        canvas.drawRect(0, height - underLineHeight, tabsLayout.getWidth(), height, rectPaint);

    }
    if (isAllowDivider) {
        // draw divider

        dividerPaint.setColor(dividerColor);
        for (int i = 0; i < tabCount - 1; i++) {
            View tab = tabsLayout.getChildAt(i);
            canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding,
                    dividerPaint);
        }
    }
}

From source file:com.cgearc.yummy.Act_Main.java

public void setActionBarTranslation(float y) {
    // Figure out the actionbar height
    int actionBarHeight = getActionBarHeight();
    // A hack to add the translation to the action bar
    ViewGroup content = ((ViewGroup) findViewById(android.R.id.content).getParent());
    int children = content.getChildCount();
    for (int i = 0; i < children; i++) {

        View child = content.getChildAt(i);
        if (child.getId() != android.R.id.content) {
            child.setTranslationY(y);//from w  ww  .  j a va  2 s  .  co  m
            //            if (y <= -actionBarHeight) {
            //               child.setVisibility(View.GONE);
            //            } else {
            //               child.setVisibility(View.VISIBLE);
            //               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            //                  
            //                  child.setTranslationY(y);
            //               } else {
            //                  AnimatorProxy.wrap(child).setTranslationY(y);
            //               }
            //            }
        }
    }
}

From source file:com.twotoasters.jazzylistview.JazzyHelper.java

public final void onScrolled(ViewGroup viewGroup, int firstVisibleItem, int visibleItemCount,
        int totalItemCount) {
    boolean shouldAnimateItems = (mFirstVisibleItem != -1 && mLastVisibleItem != -1);

    int lastVisibleItem = firstVisibleItem + visibleItemCount - 1;
    if (mIsScrolling && shouldAnimateItems) {
        setVelocity(firstVisibleItem, totalItemCount);
        int indexAfterFirst = 0;
        while (firstVisibleItem + indexAfterFirst < mFirstVisibleItem) {
            View item = viewGroup.getChildAt(indexAfterFirst);
            if (item != null) {
                doJazziness(item, firstVisibleItem + indexAfterFirst, -1);
            }/*www .j  av a 2s. com*/
            indexAfterFirst++;
        }

        int indexBeforeLast = 0;
        while (lastVisibleItem - indexBeforeLast > mLastVisibleItem) {
            View item = viewGroup.getChildAt(lastVisibleItem - firstVisibleItem - indexBeforeLast);
            if (item != null) {
                doJazziness(item, lastVisibleItem - indexBeforeLast, 1);
            }
            indexBeforeLast++;
        }
    } else if (!shouldAnimateItems) {
        for (int i = firstVisibleItem; i < visibleItemCount; i++) {
            mAlreadyAnimatedItems.add(i);
        }
    }

    mFirstVisibleItem = firstVisibleItem;
    mLastVisibleItem = lastVisibleItem;
}

From source file:ir.newway.jazzylistview.JazzyHelper.java

public final void onScrolled(ViewGroup viewGroup, int firstVisibleItem, int visibleItemCount,
        int totalItemCount) {
    boolean shouldAnimateItems = (mFirstVisibleItem != -1 && mLastVisibleItem != -1);

    int lastVisibleItem = firstVisibleItem + visibleItemCount - 1;
    if (mIsScrolling && shouldAnimateItems) {
        setVelocity(firstVisibleItem, totalItemCount);
        int indexAfterFirst = 0;
        while (firstVisibleItem + indexAfterFirst < mFirstVisibleItem) {
            View item = viewGroup.getChildAt(indexAfterFirst);
            doJazziness(item, firstVisibleItem + indexAfterFirst, -1);
            indexAfterFirst++;//from  w w  w .j a  va  2s  . c o m
        }

        int indexBeforeLast = 0;
        while (lastVisibleItem - indexBeforeLast > mLastVisibleItem) {
            View item = viewGroup.getChildAt(lastVisibleItem - firstVisibleItem - indexBeforeLast);
            doJazziness(item, lastVisibleItem - indexBeforeLast, 1);
            indexBeforeLast++;
        }
    } else if (!shouldAnimateItems) {
        for (int i = firstVisibleItem; i < visibleItemCount; i++) {
            mAlreadyAnimatedItems.add(i);
        }
    }

    mFirstVisibleItem = firstVisibleItem;
    mLastVisibleItem = lastVisibleItem;
}

From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ?TAB//  w  w w. j  a  v  a2s . c o  m
 */
private void selectedTab(int currentSelectedTabPosition) {
    ViewGroup tabsLayout = getTabsLayout();
    if (currentSelectedTabPosition > -1 && tabsLayout != null
            && currentSelectedTabPosition < tabsLayout.getChildCount()) {
        if (currentSelectedTabView != null) {
            currentSelectedTabView.setSelected(false);
        }
        currentSelectedTabView = tabsLayout.getChildAt(currentSelectedTabPosition);
        if (currentSelectedTabView != null) {
            currentSelectedTabView.setSelected(true);
        }
    }
}

From source file:android.support.v7.internal.view.menu.ActionMenuPresenter.java

private View findViewForItem(MenuItem item) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null) {
        return null;
    }//www  .j a va2s  .  co m

    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;
        }
    }
    return null;
}

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;//from   ww w . j  a v  a  2 s  .c  o m
        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:net.openwatch.acluaz.fragment.FormFragment.java

public JSONObject toJson(ViewGroup container, JSONObject json) {
    String TAG = "FormFragment-ToJSON";
    if (container == null) {
        Log.e(TAG, "null container passed to toJson");
        return new JSONObject();
    }//from  ww w. j ava2  s .c  o m

    if (json == null)
        json = new JSONObject();
    View view;
    for (int x = 0; x < container.getChildCount(); x++) {
        view = container.getChildAt(x);

        if (EditText.class.isInstance(view)) {
            if (view.getTag() != null) {
                if (((EditText) view).getText().toString().compareTo("") == 0)
                    continue; // skip blank input
                try {
                    Log.i(TAG, "Mapping: " + view.getTag().toString() + " value: "
                            + ((EditText) view).getText().toString());
                    if (view.getTag().toString().compareTo(getString(R.string.zipcode_tag)) == 0)
                        json.put(view.getTag().toString(),
                                Integer.parseInt(((EditText) view).getText().toString()));
                    else
                        json.put(view.getTag().toString(), ((EditText) view).getText().toString());
                } catch (JSONException e) {
                    Log.e(TAG, "Error jsonifying text input");
                    e.printStackTrace();
                }

            }
        } else if (CompoundButton.class.isAssignableFrom(view.getClass())) {
            if (view.getTag() != null) {
                // if location toggle, bundle location
                if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) != null) {
                    if (((CompoundButton) view).isChecked()) {
                        try {
                            json.put(getString(R.string.device_lat),
                                    ((Location) view.getTag(R.id.view_tag)).getLatitude());
                            json.put(getString(R.string.device_lon),
                                    ((Location) view.getTag(R.id.view_tag)).getLongitude());
                        } catch (JSONException e) {
                            Log.e(TAG, "Error jsonifying toggle input");
                            e.printStackTrace();
                        }
                    }
                } else if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) == null) {
                    // no location tagged, get last known
                    LocationManager lm = (LocationManager) container.getContext()
                            .getSystemService(Context.LOCATION_SERVICE);
                    Location last = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    try {
                        json.put(getString(R.string.device_lat), last.getLatitude());
                        json.put(getString(R.string.device_lon), last.getLongitude());
                    } catch (JSONException e) {
                        Log.e(TAG, "Error jsonifying last location");
                        e.printStackTrace();
                    } catch (NullPointerException e2) {
                        Log.e(TAG, "No current or historical location info on this device");
                    }
                }

            }
        }

        // combine date and time fields into a single datetime
        if (json.has(getString(R.string.date_tag)) && json.has(getString(R.string.time_tag))) {
            Log.i(TAG, "found date and time tag, let's smush 'em");
            try {
                //TESTING
                //String datetime = combineDateAndTime(json.getString(getString(R.string.date_tag)), json.getString(getString(R.string.time_tag)));
                //Log.i(TAG,"datetime: " + datetime);
                json.put(getString(R.string.date_tag),
                        combineDateAndTime(json.getString(getString(R.string.date_tag)),
                                json.getString(getString(R.string.time_tag))));
                Log.i(TAG, json.toString());
                //json.remove(getString(R.string.date_tag));
                json.remove(getString(R.string.time_tag));
            } catch (JSONException e) {
                Log.e(TAG, "Error creating json datetime field from date and time");
                e.printStackTrace();
            }
        }

    }
    Log.i(TAG, "toJson: " + json.toString());
    return json;

}

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    ViewGroup tabViewGroup = getTabsLayout();
    FirstPositionOffset = (float) tabViewGroup.getLeft();

    if (tabViewGroup != null) {

        currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0;
        if (!disableViewPager) {
            scrollToChild(currentPosition, 0);
            selectedTab(currentPosition);
        }/*ww  w .  j  ava 2 s.  c om*/

        for (int w = 0; w < tabViewGroup.getChildCount(); w++) {
            View itemView = tabViewGroup.getChildAt(w);
            itemView.setTag(w);
            itemView.setClickable(true);
            itemView.setOnClickListener(this);
        }
    }
}

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;/* w ww  .  ja  va 2 s  .  com*/
        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<>();
    } 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);
}