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 int getDisplayWidth(Context context) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    int displayWidth = displayMetrics.widthPixels;
    return displayWidth;
}

From source file:Main.java

public static float getWidthDpi(Context context) {
    DisplayMetrics dm = null;//from   w  w  w  .jav a2s  .  co  m
    try {
        if (context != null) {
            dm = new DisplayMetrics();
            dm = context.getApplicationContext().getResources().getDisplayMetrics();
        }

        return dm.densityDpi;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;

}

From source file:Main.java

public static int getDisplayHeight(Context context) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    int displayHeight = displayMetrics.heightPixels;
    return displayHeight;
}

From source file:Main.java

public static int getDeviceHeigh(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    }//from  w  w  w.ja  v  a  2s.  com
    return dm.heightPixels;
}

From source file:Main.java

public static int getDeviceWidth(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    }//from www .ja  v a  2 s.c  om
    return dm.widthPixels;
}

From source file:Main.java

public static int getWidth(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
    }//from ww w . j a  v  a  2  s.c  o m
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}

From source file:Main.java

public static int getHeight(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
    }/*from   w ww  . ja v  a2s  .  c om*/
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.heightPixels;
}

From source file:Main.java

public static DisplayMetrics screenSize(Activity c) {
    DisplayMetrics dm = new DisplayMetrics();
    c.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm;/*  w w w  . j  a  v a  2s.  c  o m*/
}

From source file:Main.java

public static int getScreenHeight(WindowManager windowManager) {
    if (screenHeight == null) {
        DisplayMetrics dm = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(dm);
        screenHeight = dm.heightPixels;//from w ww.  j  ava2 s .c  om
    }
    return screenHeight;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    int screenHeight = 0;
    if (screenHeight <= 0) {
        try {//from w w  w.j  a va 2  s  .  c o  m
            DisplayMetrics dm = new DisplayMetrics();
            dm = context.getResources().getDisplayMetrics();
            screenHeight = dm.heightPixels;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return screenHeight;
}