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

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

Introduction

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

Prototype

public static int getSmallestScreenWidthDp(@NonNull Resources resources) 

Source Link

Document

Returns The smallest screen size an application will see in normal operation, 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  v  a 2 s .  c om
 */
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;
    }
}