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

/**
 * Gets device's display resolution.//from w ww. j a  va 2s .co m
 * @since   0.1.0
 * @param   aContext The context from which the system service is retrieved to get the window's information.
 * @return   The struct of Point with x attribute contains the width and y attribute contains the height.
 */
public static Point getDisplayResolution(Context aContext) {
    WindowManager wm = (WindowManager) (aContext.getSystemService(Context.WINDOW_SERVICE));
    Point p = new Point();
    wm.getDefaultDisplay().getSize(p);
    return p;
}

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    if (metrics == null) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);
    }//from w  w  w  .  j  ava2  s  .c  o m

    return metrics;
}

From source file:Main.java

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

From source file:Main.java

/**
 * @return return screen height px unit.
 *//*from  w w  w .j  av  a 2 s  . c om*/
public static int getScreenHeigth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:Main.java

public static int getWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:Main.java

public static Integer getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);

    return metrics.widthPixels;
}

From source file:Main.java

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

    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);

    return metrics.heightPixels;
}

From source file:Main.java

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

From source file:Main.java

public static float getScreenHeightPPI(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.ydpi;
}

From source file:Main.java

public static int getScreenDensityDpi(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.densityDpi;
}