Example usage for android.util DisplayMetrics DisplayMetrics

List of usage examples for android.util DisplayMetrics DisplayMetrics

Introduction

In this page you can find the example usage for android.util DisplayMetrics DisplayMetrics.

Prototype

public DisplayMetrics() 

Source Link

Usage

From source file:Main.java

public static String getDisplay(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wMgr.getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    return width + "*" + height;
}

From source file:Main.java

public static double getDeviceXDPI(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager mgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mgr.getDefaultDisplay().getMetrics(metrics);
    return metrics.xdpi;
}

From source file:Main.java

public static int getScreenDpi(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics.densityDpi;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.widthPixels;
    return height;
}

From source file:Main.java

public static String getRelation(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager windowMgr = (WindowManager) context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    windowMgr.getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    return String.valueOf(width) + "*" + String.valueOf(height);
}

From source file:Main.java

public static float getDensity(Context context) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics.density;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(metrics);
    return metrics.widthPixels;
}

From source file:Main.java

public static float getDeviceDensity(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    return metrics.density;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(metrics);
    return metrics.heightPixels;
}

From source file:Main.java

public static int[] getDisplayResolutionWH(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return new int[] { dm.widthPixels, dm.heightPixels };
}