Example usage for android.view ViewGroup getPaddingBottom

List of usage examples for android.view ViewGroup getPaddingBottom

Introduction

In this page you can find the example usage for android.view ViewGroup getPaddingBottom.

Prototype

public int getPaddingBottom() 

Source Link

Document

Returns the bottom padding of this view.

Usage

From source file:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * DrawerLayout ???//  w w w.  j a v a2s .c o m
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color,
        int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // ????
    //  statusBarView 
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
        contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        StatusBarView statusBarView = createStatusBarView(activity, color);
        contentLayout.addView(statusBarView, 0);
    }
    // ? LinearLayout ,padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(),
                getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(),
                contentLayout.getPaddingBottom());
    }
    // 
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);

    addTranslucentView(activity, statusBarAlpha);
}

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

private void onDecorViewInitialized() {
    // measure status bar & navigation bar height
    final ViewGroup contents = (ViewGroup) findViewById(R.id.activity_contents);
    final int statusBarOffset = contents.getPaddingTop();
    final int navBarOffset = contents.getPaddingBottom();

    // apply to navigation drawer
    mNavigationDrawerFragment.setSystemBarsOffset(statusBarOffset, navBarOffset);
}

From source file:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 * DrawerLayout ???//from   w ww . j av  a  2s .co  m
 *
 * @param activity       ?activity
 * @param drawerLayout   DrawerLayout
 * @param color          ??
 * @param statusBarAlpha ???
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
        int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // ????
    //  statusBarView 
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
        contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        StatusBarView statusBarView = createStatusBarView(activity, color);
        contentLayout.addView(statusBarView, 0);
    }
    // ? LinearLayout ,padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(),
                getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(),
                contentLayout.getPaddingBottom());
    }
    // 
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);

    addTranslucentView(activity, statusBarAlpha);
}

From source file:org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*//w  ww. j  a va 2  s. c  o  m
       * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid,
            container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
       * Adjust the layout of the gridview to a square.
     *
     * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use
                * a hard coded value of 8 dip.
                *
                * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step
                * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value?
                */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid unnecessary updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:com.mfh.framework.uikit.widget.SideSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;/*from   w  w  w  . j  a v a2  s. c  o  m*/
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        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));
    }

    adjustChildHeightWithParent(tabViews,
            getMeasuredHeight() - tabsLayout.getPaddingTop() - tabsLayout.getPaddingBottom(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:ti.org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*/*from w w  w .j  a  v  a  2 s.  c  o  m*/
     * TODO: build the layout programmatically to get rid of the resources,
     * so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater
            .inflate(RHelper.getLayout("org_dmfs_colorpickerdialog_palette_grid"), container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
     * Adjust the layout of the gridview to a square.
     * 
     * Inspired by Bill Lahti, see
     * http://blahti.wordpress.com/2012/07/23/three
     * -variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                 * TODO: getHorizontalSpacing() has been introduced
                 * in SDK level 16. We need to find a way to get get
                 * the actual spacing. Until then we use a hard
                 * coded value of 8 dip.
                 * 
                 * One way would be to use a dimension in the
                 * layout. That would allow us to resolve the
                 * dimension here. However, that would be one step
                 * away from a library without resource
                 * dependencies. Maybe there is an Android dimension
                 * resource with a reasonable value?
                 */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the
                    // entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the
            // entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid
            // unnecessary
            // updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void adjustAccordingToAnchor() {
    Bundle bundle = getArguments();/* ww w. ja  va  2  s.  co m*/
    if (bundle == null || getView() == null) {
        return;
    }
    View view = getView();
    ViewGroup viewGroup = (ViewGroup) view.getParent();
    Rect rect = bundle.getParcelable(ARG_ANCHOR_RECT);
    int posX = bundle.getInt(ARG_POS_X);
    int posY = bundle.getInt(ARG_POS_Y);

    final int widthSpec = View.MeasureSpec.makeMeasureSpec(
            viewGroup.getMeasuredWidth() - viewGroup.getPaddingLeft() - viewGroup.getPaddingRight(),
            View.MeasureSpec.AT_MOST);
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(
            viewGroup.getMeasuredHeight() - viewGroup.getPaddingTop() - viewGroup.getPaddingBottom(),
            View.MeasureSpec.AT_MOST);
    view.measure(widthSpec, heightSpec);

    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dialogFrameLayout
            .getLayoutParams();
    int rootHeight = dialogFrameLayout.getMeasuredHeight();
    int rootWidth = dialogFrameLayout.getMeasuredWidth();

    int dialogHeight = rootHeight + layoutParams.bottomMargin + layoutParams.topMargin;
    int dialogWidth = rootWidth + layoutParams.leftMargin + layoutParams.rightMargin;

    setDialogPosition(rect, posX, posY, dialogWidth, dialogHeight);
}