Example usage for android.view ViewGroup getPaddingTop

List of usage examples for android.view ViewGroup getPaddingTop

Introduction

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

Prototype

public int getPaddingTop() 

Source Link

Document

Returns the top padding of this view.

Usage

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

/**
 * DrawerLayout ???/*from   w  w  w  .  j a va 2 s . c om*/
 *
 * @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:org.huxizhijian.sdk.util.StatusBarUtil.java

/**
 * DrawerLayout ???//w w  w  .  ja  v a  2  s .c  o  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: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:jahirfiquitiva.iconshowcase.activities.AltWallpaperViewerActivity.java

private void showNotConnectedSnackBar() {
    Snackbar notConnectedSnackBar = Utils.snackbar(this, layout, getString(R.string.no_conn_title),
            Snackbar.LENGTH_LONG);/*from  w w  w .jav a2s  . com*/

    ViewGroup snackbarView = (ViewGroup) notConnectedSnackBar.getView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        snackbarView.setPadding(snackbarView.getPaddingLeft(), snackbarView.getPaddingTop(),
                snackbarView.getPaddingRight(), Utils.getNavigationBarHeight(this));
    }
    notConnectedSnackBar.show();
}

From source file:jahirfiquitiva.iconshowcase.activities.AltWallpaperViewerActivity.java

private void saveWallpaper(final Activity context, final String wallName, final MaterialDialog downloadDialog,
        final Bitmap result) {
    downloadDialog.setContent(context.getString(R.string.saving_wallpaper));
    new Thread(new Runnable() {
        @Override//from w w w.ja va  2s  . c o  m
        public void run() {
            if (mPrefs.getDownloadsFolder() != null) {
                downloadsFolder = new File(mPrefs.getDownloadsFolder());
            } else {
                downloadsFolder = new File(context.getString(R.string.walls_save_location,
                        Environment.getExternalStorageDirectory().getAbsolutePath()));
            }
            //noinspection ResultOfMethodCallIgnored
            downloadsFolder.mkdirs();
            final File destFile = new File(downloadsFolder, wallName + ".png");
            String snackbarText;
            if (!destFile.exists()) {
                try {
                    result.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destFile));
                    snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
                } catch (final Exception e) {
                    snackbarText = context.getString(R.string.error);
                }
            } else {
                snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
            }
            final String finalSnackbarText = snackbarText;
            context.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    downloadDialog.dismiss();
                    Snackbar longSnackbar = Utils.snackbar(AltWallpaperViewerActivity.this, layout,
                            finalSnackbarText, Snackbar.LENGTH_LONG);
                    ViewGroup snackbarView = (ViewGroup) longSnackbar.getView();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        snackbarView.setPadding(snackbarView.getPaddingLeft(), snackbarView.getPaddingTop(),
                                snackbarView.getPaddingRight(),
                                Utils.getNavigationBarHeight(AltWallpaperViewerActivity.this));
                    }
                    longSnackbar.show();
                    longSnackbar.setCallback(new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            reshowFab(fab);
                            setupFullScreen();
                        }
                    });
                }
            });
        }
    }).start();
}

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  av 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(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;/*  w  w w. j  ava 2s  .com*/
    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  www. java2  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.android.deskclock.stopwatch.StopwatchFragment.java

/**
 * Show or hide the list of laps.//from   w ww  .j  a  v  a  2 s.co  m
 */
private void showOrHideLaps(boolean clearLaps) {
    final ViewGroup sceneRoot = (ViewGroup) getView();
    if (sceneRoot == null) {
        return;
    }

    TransitionManager.beginDelayedTransition(sceneRoot);

    if (clearLaps) {
        mLapsAdapter.clearLaps();
    }

    final boolean lapsVisible = mLapsAdapter.getItemCount() > 0;
    mLapsList.setVisibility(lapsVisible ? VISIBLE : GONE);

    if (Utils.isPortrait(getActivity())) {
        // When the lap list is visible, it includes the bottom padding. When it is absent the
        // appropriate bottom padding must be applied to the container.
        final Resources res = getResources();
        final int bottom = lapsVisible ? 0 : res.getDimensionPixelSize(R.dimen.fab_height);
        final int top = sceneRoot.getPaddingTop();
        final int left = sceneRoot.getPaddingLeft();
        final int right = sceneRoot.getPaddingRight();
        sceneRoot.setPadding(left, top, right, bottom);
    }
}

From source file:com.wizardsofm.deskclock.stopwatch.StopwatchFragment.java

/**
 * Show or hide the list of laps./*  w w w .j av  a  2 s .c o  m*/
 */
private void showOrHideLaps(boolean clearLaps) {
    final ViewGroup sceneRoot = (ViewGroup) getView();
    if (sceneRoot == null) {
        return;
    }

    TransitionManager.beginDelayedTransition(sceneRoot);

    if (clearLaps) {
        mLapsAdapter.clearLaps();
    }

    final boolean lapsVisible = mLapsAdapter.getItemCount() > 0;
    mLapsList.setVisibility(lapsVisible ? VISIBLE : GONE);

    if (Utils.isPortrait(getActivity())) {
        // When the lap list is visible, it includes the bottom padding. When it is absent the
        // appropriate bottom padding must be applied to the container.
        final Resources res = getResources();
        final int bottom = lapsVisible ? 0
                : res.getDimensionPixelSize(com.wizardsofm.deskclock.R.dimen.fab_height);
        final int top = sceneRoot.getPaddingTop();
        final int left = sceneRoot.getPaddingLeft();
        final int right = sceneRoot.getPaddingRight();
        sceneRoot.setPadding(left, top, right, bottom);
    }
}