Example usage for android.content.res Configuration getClass

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

@TargetApi(4)
public static boolean isTabletDevice(android.content.Context activityContext) {
    if (!androidAPIover(4)) //VERSION
        return false; //If there is a tablet running 1.5.....GOD HELP YOU

    try {/* w  w  w .ja  v  a  2 s.com*/

        // Verifies if the Generalized Size of the device is XLARGE to be
        // considered a Tablet
        Configuration config = activityContext.getResources().getConfiguration();
        Log.i("screenlayout",
                Integer.parseInt(
                        Configuration.class.getDeclaredField("SCREENLAYOUT_SIZE_LARGE").get(config).toString())
                        + "!!!");
        boolean xlarge =
                //activityContext.getResources().getConfiguration().screenLayout &
                Boolean.parseBoolean(config.getClass().getField("screenLayout").get(config).toString())
                        & getStaticInt(config, "SCREENLAYOUT_SIZE_MASK") >= //Changed this from == to >= because my tablet was returning 8 instead of 4.
                        Integer.parseInt(Configuration.class.getDeclaredField("SCREENLAYOUT_SIZE_LARGE")
                                .get(config).toString());
        getStaticInt(config, "SCREENLAYOUT_SIZE_MASK");

        // 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 {
                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
            int densityDpi = Integer
                    .parseInt(metrics.getClass().getDeclaredField("densityDpi").get(metrics).toString());
            if (densityDpi == 240 || //DENSITY_HIGH
                    densityDpi == 160 || //DENSITY_MEDIUM
                    //densityDpi == android.util.DisplayMetrics.DENSITY_DEFAULT ||
                    //densityDpi == android.util.DisplayMetrics.DENSITY_HIGH ||
                    //densityDpi == android.util.DisplayMetrics.DENSITY_MEDIUM ||
                    densityDpi == tv || densityDpi == xhigh) {
                return true;
            }
        }
    } catch (Exception e) {
    }
    return false;
}

From source file:com.newsrob.EntryManager.java

public boolean shouldActionBarLocationOnlyAllowGone() {

    int sdkLevel = SDKVersionUtil.getVersion();
    if (sdkLevel < 4 || sdkLevel == 5 || sdkLevel == 6)
        return true;

    // Tiny screens
    if (true)/*from  w w  w.j  av a2 s.  co  m*/
        return false;

    Configuration cfg = ctx.getResources().getConfiguration();
    int screenLayout = -1;
    try {
        screenLayout = (Integer) cfg.getClass().getField("screenLayout").get(cfg);
    } catch (Exception e) {
        return false;
    }
    // if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
    // Configuration.SCREENLAYOUT_SIZE_SMALL)
    if ((screenLayout & 0x0000000f) == 0x00000001)
        return true;

    return false;
}

From source file:com.grazerss.EntryManager.java

public boolean shouldActionBarLocationOnlyAllowGone() {

    // Tiny screens
    if (true) {//  ww w .  j a  v a2 s.  co m
        return false;
    }

    Configuration cfg = ctx.getResources().getConfiguration();
    int screenLayout = -1;
    try {
        screenLayout = (Integer) cfg.getClass().getField("screenLayout").get(cfg);
    } catch (Exception e) {
        return false;
    }
    // if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
    // Configuration.SCREENLAYOUT_SIZE_SMALL)
    if ((screenLayout & 0x0000000f) == 0x00000001) {
        return true;
    }

    return false;
}