Example usage for android.support.v4.content.res ConfigurationHelper getScreenWidthDp

List of usage examples for android.support.v4.content.res ConfigurationHelper getScreenWidthDp

Introduction

In this page you can find the example usage for android.support.v4.content.res ConfigurationHelper getScreenWidthDp.

Prototype

public static int getScreenWidthDp(@NonNull Resources resources) 

Source Link

Document

Returns the current width of the available screen space, in dp units.

Usage

From source file:android.support.v7.view.ActionBarPolicy.java

/**
 * Returns the maximum number of action buttons that should be permitted within an action
 * bar/action mode. This will be used to determine how many showAsAction="ifRoom" items can fit.
 * "always" items can override this.//from  w  w w  .j  a va2 s .com
 */
public int getMaxActionButtons() {
    final Resources res = mContext.getResources();
    final int widthDp = ConfigurationHelper.getScreenWidthDp(res);
    final int heightDp = ConfigurationHelper.getScreenHeightDp(res);
    final int smallest = ConfigurationHelper.getSmallestScreenWidthDp(res);

    if (smallest > 600 || widthDp > 600 || (widthDp > 960 && heightDp > 720)
            || (widthDp > 720 && heightDp > 960)) {
        // For values-w600dp, values-sw600dp and values-xlarge.
        return 5;
    } else if (widthDp >= 500 || (widthDp > 640 && heightDp > 480) || (widthDp > 480 && heightDp > 640)) {
        // For values-w500dp and values-large.
        return 4;
    } else if (widthDp >= 360) {
        // For values-w360dp.
        return 3;
    } else {
        return 2;
    }
}

From source file:android.support.design.widget.FloatingActionButton.java

private int getSizeDimension(@Size final int size) {
    final Resources res = getResources();
    switch (size) {
    case SIZE_AUTO:
        // If we're set to auto, grab the size from resources and refresh
        final int width = ConfigurationHelper.getScreenWidthDp(res);
        final int height = ConfigurationHelper.getScreenHeightDp(res);
        return Math.max(width, height) < AUTO_MINI_LARGEST_SCREEN_WIDTH ? getSizeDimension(SIZE_MINI)
                : getSizeDimension(SIZE_NORMAL);
    case SIZE_MINI:
        return res.getDimensionPixelSize(R.dimen.design_fab_size_mini);
    case SIZE_NORMAL:
    default:/*from w  ww  . ja  v  a  2  s.c  o m*/
        return res.getDimensionPixelSize(R.dimen.design_fab_size_normal);
    }
}