Example usage for android.view View getPaddingTop

List of usage examples for android.view View getPaddingTop

Introduction

In this page you can find the example usage for android.view View getPaddingTop.

Prototype

public int getPaddingTop() 

Source Link

Document

Returns the top padding of this view.

Usage

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerView.java

protected void onMeasurePage(int widthMeasureSpec, int heightMeasureSpec) {
    Log.d("TEST", "onMeasurePage" + getCurrentItem());
    View child = pagerAdapter.getViewAtPosition(getCurrentItem());
    if (child == null) {
        child = getChildAt(0);//from w  w w .  j av  a 2s  .c o m
    }
    if (child == null) {
        return;
    }
    for (int i = 0; i < getChildCount(); i++) {
        View view = getChildAt(i);
        if ((view.getPaddingLeft() != itemMarginLeft || view.getPaddingTop() != itemMarginTop
                || view.getPaddingRight() != itemMarginRight || view.getPaddingBottom() != itemMarginBottom)) {
            view.setPadding(itemMarginLeft, itemMarginTop, itemMarginRight, itemMarginBottom);
        }
    }

    ViewGroup.LayoutParams lp = child.getLayoutParams();
    final int childWidthSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
    final int childHeightSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);

    int childWidth = (int) ((MeasureSpec.getSize(childWidthSpec) - getPaddingLeft() - getPaddingRight())
            * pagerAdapter.getPageWidth(getCurrentItem()));
    int childHeight = MeasureSpec.getSize(childHeightSpec) - getPaddingTop() - getPaddingBottom();

    if (!needsMeasurePage || childWidth == 0 && childHeight == 0) {
        return;
    }

    if (!Double.isNaN(itemRatio)) {
        int itemHeight = (int) (childWidth / itemRatio);
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(itemHeight, MeasureSpec.EXACTLY));
        }
    } else {
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            if (pagerAdapter.getPageWidth(getCurrentItem()) != 1) {
                view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            } else {
                view.measure(childWidthSpec, childHeightSpec);
            }
        }
    }

    final boolean isHorizontalScroll = scrollMode == UltraViewPager.ScrollMode.HORIZONTAL;

    childWidth = itemMarginLeft + child.getMeasuredWidth() + itemMarginRight;
    childHeight = itemMarginTop + child.getMeasuredHeight() + itemMarginBottom;

    if (!Float.isNaN(ratio)) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (getMeasuredWidth() / ratio),
                MeasureSpec.EXACTLY);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
        }
    } else {
        if (autoMeasureHeight) {
            if (isHorizontalScroll) {
                constrainLength = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY);
                setMeasuredDimension(getMeasuredWidth(), childHeight);
            } else {
                constrainLength = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
                setMeasuredDimension(childWidth, getMeasuredHeight());
            }

            needsMeasurePage = childHeight == itemMarginTop + itemMarginBottom;
        }
    }

    if (!pagerAdapter.isEnableMultiScr()) {
        return;
    }

    int pageLength = isHorizontalScroll ? getMeasuredWidth() : getMeasuredHeight();

    final int childLength = isHorizontalScroll ? child.getMeasuredWidth() : child.getMeasuredHeight();

    // Check that the measurement was successful
    if (childLength > 0) {
        needsMeasurePage = false;
        int difference = pageLength - childLength;
        if (getPageMargin() == 0) {
            setPageMargin(-difference);
        }
        int offscreen = (int) Math.ceil((float) pageLength / (float) childLength) + 1;
        setOffscreenPageLimit(offscreen);
        requestLayout();
    }
}

From source file:org.cm.podd.report.fragment.SwipeRefreshFragment.java

protected boolean canViewScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(view, -1);
    } else {/*from   ww w  . jav a  2  s.  co m*/
        // Pre-ICS we need to manually check the first visible item and the child view's top
        // value
        return (view.getVerticalScrollbarPosition() > 0 || view.getTop() < view.getPaddingTop());
    }
}

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * Adds an extra bottom padding in case there is a Software Navigation Bar
 *
 * @param view//  ww  w .ja v a2 s . co m
 */
public void addBottomPaddingforSoftNavbar(View view) {
    if (!ViewConfiguration.get(mContext).hasPermanentMenuKey()) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(),
                view.getPaddingBottom() + navigationBarSize());
    }
}

From source file:app.daeng.tokped.Utils.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from w  w  w .ja  v  a2  s .c  o m

    mTabStrip = new SlidingTabStrip(context);
    //mTabStrip.setVisibility(View.INVISIBLE);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            // Set spacer tab widths
            View firstTab = mTabStrip.getChildAt(0);
            int firstTabPadding = (getWidth() - mTabStrip.getChildAt(1).getMeasuredWidth()) / 2;
            firstTab.setPadding(firstTabPadding, firstTab.getPaddingTop(), firstTab.getPaddingRight(),
                    firstTab.getPaddingBottom());

            View lastTab = mTabStrip.getChildAt(mTabStrip.getChildCount() - 1);
            int lastTabPadding = (getWidth()
                    - mTabStrip.getChildAt(mTabStrip.getChildCount() - 2).getMeasuredWidth()) / 4;
            lastTab.setPadding(lastTabPadding, 0, lastTabPadding, 0);

            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            else
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}

From source file:com.brq.wallet.lt.activity.buy.AdSearchFragment.java

private void setBackgroundResource(View theView, int backgroundResource) {
    int bottom = theView.getPaddingBottom();
    int top = theView.getPaddingTop();
    int right = theView.getPaddingRight();
    int left = theView.getPaddingLeft();
    theView.setBackgroundResource(backgroundResource);
    theView.setPadding(left, top, right, bottom);
}

From source file:ti.modules.titanium.ui.widget.TiSwipeRefreshLayout.java

/**
 * Called when this view's measure() method gets called. Typically called by the parent view.
 * Updates this view's width and height based on the given width and height constraints.
 * <p>/*w  w  w. ja  va  2 s.c o  m*/
 * Given arguments size and size mode can be extracted by the Android "View.MeasureSpec" class.
 * @param widthMeasureSpec Provides the parent's width contraints and size mode.
 * @param heightMeasureSpec Provides the parent's height contraints and size mode.
 */
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // If height mode not set to "exactly", then change height to match view's tallest child.
    // Note: We need to do this since Google's "SwipeRefreshLayout" class ignores the
    //       WRAP_CONTENT setting and will fill the height of the parent view instead.
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode != MeasureSpec.EXACTLY) {
        // Determine the min height needed to fit this view's tallest child view.
        int minHeight = 0;
        for (int index = getChildCount() - 1; index >= 0; index--) {
            // Fetch the next child.
            View child = getChildAt(index);
            if (child == null) {
                continue;
            }

            // Skip child views that are flagged as excluded from the layout.
            if (child.getVisibility() == View.GONE) {
                continue;
            }

            // Determine the height of the child.
            child.measure(widthMeasureSpec, heightMeasureSpec);
            int childHeight = child.getMeasuredHeight();
            childHeight += child.getPaddingTop() + child.getPaddingBottom();

            // Store the child's height if it's the tallest so far.
            minHeight = Math.max(minHeight, childHeight);
        }

        // Make sure we're not exceeding the suggested min height assigned to this view.
        minHeight = Math.max(minHeight, getSuggestedMinimumHeight());

        // Update this view's given height spec to match the tallest child view, but only if:
        // - Height mode is UNSPECIFIED. (View can be any height it wants.)
        // - Height mode is AT_MOST and the min height is less than given height.
        if ((heightMode == MeasureSpec.UNSPECIFIED) || (minHeight < MeasureSpec.getSize(heightMeasureSpec))) {
            heightMode = MeasureSpec.AT_MOST;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(minHeight, heightMode);
        }
    }

    // Update this view's measurements.
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.icenler.lib.view.support.percentlayout.PercentLayoutHelper.java

private void supportPadding(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    int left = view.getPaddingLeft(), right = view.getPaddingRight(), top = view.getPaddingTop(),
            bottom = view.getPaddingBottom();
    PercentLayoutInfo.PercentVal percentVal = info.paddingLeftPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        left = (int) (base * percentVal.percent);
    }/*from ww  w . j  av  a2 s  .  c  o m*/
    percentVal = info.paddingRightPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        right = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingTopPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        top = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingBottomPercent;
    if (percentVal != null) {
        int base = percentVal.isBaseWidth ? widthHint : heightHint;
        bottom = (int) (base * percentVal.percent);
    }
    view.setPadding(left, top, right, bottom);

}

From source file:org.thoughtcrime.securesms.ConversationItem.java

@Override
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    if (groupSenderHolder != null && groupSenderHolder.getVisibility() == View.VISIBLE) {
        View content = (View) groupSenderHolder.getParent();

        groupSenderHolder.layout(content.getPaddingLeft(), content.getPaddingTop(),
                content.getWidth() - content.getPaddingRight(),
                content.getPaddingTop() + groupSenderHolder.getMeasuredHeight());

        if (ViewCompat.getLayoutDirection(groupSenderProfileName) == ViewCompat.LAYOUT_DIRECTION_RTL) {
            groupSenderProfileName.layout(groupSenderHolder.getPaddingLeft(), groupSenderHolder.getPaddingTop(),
                    groupSenderHolder.getPaddingLeft() + groupSenderProfileName.getWidth(),
                    groupSenderHolder.getPaddingTop() + groupSenderProfileName.getHeight());
        } else {/*from  w w w .ja  va2s.com*/
            groupSenderProfileName.layout(
                    groupSenderHolder.getWidth() - groupSenderHolder.getPaddingRight()
                            - groupSenderProfileName.getWidth(),
                    groupSenderHolder.getPaddingTop(),
                    groupSenderHolder.getWidth() - groupSenderProfileName.getPaddingRight(),
                    groupSenderHolder.getPaddingTop() + groupSenderProfileName.getHeight());
        }
    }
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.NavigationDrawerFragment.java

public void setSystemBarsOffset(int statusBarOffset, int navBarOffset) {
    if (mModeSelectListView != null) {
        View v = mModeSelectListView;
        v.setPadding(ViewCompat.getPaddingStart(v), statusBarOffset, ViewCompat.getPaddingEnd(v),
                v.getPaddingBottom());/*from ww  w.j av  a 2 s .  c  om*/
    }
    if (mPageSelectListView != null) {
        View v = mPageSelectListView;
        v.setPadding(ViewCompat.getPaddingStart(v), v.getPaddingTop(), ViewCompat.getPaddingEnd(v),
                navBarOffset);
    }
}

From source file:com.homechart.app.commont.matertab.MaterialTabs.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom());
        TextView tab_title = (TextView) v.findViewById(R.id.mt_tab_title);

        if (tab_title != null) {
            tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab_title.setTextColor(tabTextColorUnselected);
            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a pre-ICS-build.
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab_title.setAllCaps(true);
                } else {
                    tab_title.setText(tab_title.getText().toString().toUpperCase(locale));
                }//ww  w .ja  v  a 2  s .c  om
            }
        }
    }
}