Example usage for android.content.res Configuration SCREENLAYOUT_SIZE_MASK

List of usage examples for android.content.res Configuration SCREENLAYOUT_SIZE_MASK

Introduction

In this page you can find the example usage for android.content.res Configuration SCREENLAYOUT_SIZE_MASK.

Prototype

int SCREENLAYOUT_SIZE_MASK

To view the source code for android.content.res Configuration SCREENLAYOUT_SIZE_MASK.

Click Source Link

Document

Constant for #screenLayout : bits that encode the size.

Usage

From source file:Main.java

/**
 * Determining the current screen's size related to Large, XLarge or not.
 * //from w  ww.  ja va 2 s  .com
 * @param context
 *            The Application Context.
 * @return boolean Type
 */
public static boolean isLargeOrXLarge(Context context) {
    int mask = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
    return (mask == Configuration.SCREENLAYOUT_SIZE_XLARGE) || (mask == Configuration.SCREENLAYOUT_SIZE_LARGE);
}

From source file:Main.java

@TargetApi(13)
public static int getColumnCount(Context context) {
    if (!API_13) {
        int screenSize = context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK;
        if (screenSize == Configuration.SCREENLAYOUT_SIZE_SMALL)
            return 1;

        int orientation = context.getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE)
            return 2;
    } else {//  ww  w .j  a  v a  2 s . c  o  m
        int screenWidthDp = context.getResources().getConfiguration().screenWidthDp;
        //    if (screenWidthDp > 820) return 4;
        if (screenWidthDp >= 720)
            return 3;
        if (screenWidthDp >= 480)
            return 2;
    }

    return 1;
}

From source file:Main.java

/**
 * Determines whether or not the device has an extra large screen.
 *
 * @param context The Android context.//from   w  w  w  .  j a v  a 2s.c  om
 * @return boolean value indicating if the screen size is extra large.
 */
public static boolean isExtraLargeScreen(Context context) {
    int screenSizeMask = context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK;
    if (screenSizeMask == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

private static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

From source file:Main.java

/**
 * Returns true if the device has a LARGE or XLARGE screen size.
 */// w  w  w .  j a  va 2s  . c  o  m
public static boolean isTablet(Context ctx) {
    int screenLayout = ctx.getResources().getConfiguration().screenLayout;
    return Configuration.SCREENLAYOUT_SIZE_LARGE <= (screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
}

From source file:Main.java

/**
 * Determining the current screen's size is xlarge or not..
 * //from www  .  ja va2  s . c o m
 * @param context
 *            The Application Context.
 * @return Boolean Type.
 */
public static boolean isXLarge(Context context) {
    return ((context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
}

From source file:Main.java

@TargetApi(4)
public static boolean isTabletDevice(android.content.Context activityContext) {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= //Changed this from == to >= because my tablet was returning 8 instead of 4.
    Configuration.SCREENLAYOUT_SIZE_LARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI (160dpi)
    if (xlarge) {
        android.util.DisplayMetrics metrics = new android.util.DisplayMetrics();
        Activity activity = (Activity) activityContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        //This next block lets us get constants that are not available in lower APIs.
        // If they aren't available, it's safe to assume that the device is not a tablet.
        // If you have a tablet or TV running Android 1.5, what the fuck is wrong with you.
        int xhigh = -1, tv = -1;
        try {/*from w w  w  .j  av a2s . c o  m*/
            Field f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_XHIGH");
            xhigh = (Integer) f.get(null);
            f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_TV");
            xhigh = (Integer) f.get(null);
        } catch (Exception e) {
        }

        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == android.util.DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == android.util.DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == android.util.DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == tv
                || metrics.densityDpi == xhigh) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Is tablet boolean./*  w w w  .  j a  va2  s  . c  o m*/
 *
 * @param context given context
 * @return true if its a tablet
 */
public static boolean isTablet(@NonNull Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

From source file:Main.java

/**
 * Used to determine if the device is a tablet or not
 * // ww w. java  2 s .  co m
 * @param context The {@link Context} to use.
 * @return True if the device is a tablet, false otherwise.
 */
public static final boolean isTablet(final Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

From source file:Main.java

/**
 * Used to determine if the device is a tablet or not
 * /*from  www  .j  a  v a  2  s.co  m*/
 * @param context The {@link Context} to use.
 * @return True if the device is a tablet, false otherwise.
 */
public static final boolean isTablet(final Context context) {
    final int layout = context.getResources().getConfiguration().screenLayout;
    return (layout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}