Example usage for android.content.res Configuration SCREENLAYOUT_SIZE_LARGE

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

Introduction

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

Prototype

int SCREENLAYOUT_SIZE_LARGE

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

Click Source Link

Document

Constant for #screenLayout : a #SCREENLAYOUT_SIZE_MASK value indicating the screen is at least approximately 480x640 dp units, corresponds to the large resource qualifier.

Usage

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.
 *//*from w ww  .j a v a 2 s.  co  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

/**
 * Is tablet boolean.//from w  ww. ja v  a2 s .c om
 *
 * @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
 * //from  w  w w.  j a  va  2s  .c  o  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 va 2s  . 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;
}

From source file:Main.java

/**
 * Method that returns if the device is a tablet
 *
 * @param ctx The current context//from   w  w  w  .j av  a 2 s  . c om
 * @return boolean If device is a table
 */
public static boolean isTablet(Context ctx) {
    Configuration configuration = ctx.getResources().getConfiguration();
    return (configuration.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

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  ww  . j a v a2  s . com
            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

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

From source file:Main.java

/**
 * Uses the device's screen size to determine if the current device is a tablet or is tablet-sized.
 * @param context required to provide access to the device configuration information
 * @return true if the device has a large enough screen to be considered a tablet (for UI purposes).
 */// w  w w  . j ava 2s  .  c o m
public static boolean isTablet(Context context) {
    boolean xlarge = ((context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
    boolean large = ((context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    return (xlarge || large);
}

From source file:Main.java

/**
 * Checks if the device is a tablet or a phone
 *
 * @param activityContext/*from w  w w. j a v a2  s.  c o m*/
 *          The Activity Context.
 * @return Returns true if the device is a Tablet
 */
public static boolean isTabletDevice(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) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
        DisplayMetrics metrics = new DisplayMetrics();
        Activity activity = (Activity) activityContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
        // DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
            // Yes, this is a tablet!
            return true;
        }
    }
    // No, this is not a tablet!
    return false;
}