Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:Main.java

public static int dp2px(Context context, int dp) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    display.getMetrics(displaymetrics);/*from  w w  w.  jav  a2s .  com*/

    return (int) (dp * displaymetrics.density + 0.5f);
}

From source file:Main.java

public static int px2dp(Context context, int px) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    display.getMetrics(displaymetrics);//from  w w  w .ja  v a2  s  .c o m

    return (int) (px / displaymetrics.density + 0.5f);
}

From source file:Main.java

public static Point getDeviceSize(Context context) {
    Point size = new Point(-1, -1); // invalid size
    if (context == null)
        return size;
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay(); // the display that we see
    display.getSize(size);/*from   w  w  w  . ja va  2 s. c  om*/
    return size;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);//from   w w  w  .  j a v  a 2s  .c  o m

    return metrics.heightPixels;
}

From source file:Main.java

public static DisplayMetrics getScreenPix(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(dm);
    return dm;/*from   w ww  .  j av a 2s  . c o  m*/
}

From source file:Main.java

public static String getScreenDisplayID(Context ctx) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    return String.valueOf(wm.getDefaultDisplay().getDisplayId());
}

From source file:Main.java

public static int getScreenHeight(Context c) {
    WindowManager windowManager = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();

    Point point = new Point();
    display.getSize(point);//from   w  ww . ja  v a  2 s  .  c o  m

    return point.y;
}

From source file:Main.java

public static float getDeviceDensity(Context context) {
    DisplayMetrics dMetrics = new DisplayMetrics();
    WindowManager wManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wManager.getDefaultDisplay();
    display.getMetrics(dMetrics);//from  w w  w  .  ja  v a  2 s. c  om
    return dMetrics.density;
}

From source file:Main.java

public static DisplayMetrics getScreenSize(Context context) {
    DisplayMetrics dMetrics = new DisplayMetrics();
    WindowManager wManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wManager.getDefaultDisplay();
    display.getMetrics(dMetrics);/*from   ww w .  j a  va2 s . co  m*/
    return dMetrics;
}

From source file:Main.java

public static int getScreeWH(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);/*from   ww  w.  ja v  a2  s . c  o m*/
    return outMetrics.heightPixels;

}