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

/**
 * @param wm/* w ww. j a  v  a2  s .c o  m*/
 * @param baseY
 * @param baseX
 * @return
 */
public static float sizeYByX(WindowManager wm, float baseY, float baseX) {

    final Display disp = wm.getDefaultDisplay();
    Point mPoint = new Point();
    getSize(disp, mPoint);
    float displayWidth = mPoint.x;

    float scaleX = displayWidth / baseX;

    return baseY * scaleX + 0.5f;
}

From source file:Main.java

public static int getScreenHeight(Context c) {
    if (screenHeight == 0) {
        WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);/*from   ww w  . ja  v a2  s.  co  m*/
        screenHeight = size.y;
    }

    return screenHeight;
}

From source file:Main.java

public static int getScreenWidth(Context c) {
    if (screenWidth == 0) {
        WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);/*from  ww  w .  j a va  2  s.  co  m*/
        screenWidth = size.x;
    }

    return screenWidth;
}

From source file:Main.java

public static int[] getRealScreenSize(Activity activity) {
    int[] size = new int[2];
    int screenWidth = 0, screenHeight = 0;
    WindowManager w = activity.getWindowManager();
    Display d = w.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);//from w w  w  .  j  a  v a  2s. c  o  m
    // since SDK_INT = 1;
    screenWidth = metrics.widthPixels;
    screenHeight = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            screenWidth = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            screenHeight = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            screenWidth = realSize.x;
            screenHeight = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = screenWidth;
    size[1] = screenHeight;
    return size;
}

From source file:Main.java

public static Point getScreenResolution(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point screenResolution = new Point();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        display.getSize(screenResolution);
    } else {/* w  w w .  j  a  v a 2s .c  om*/
        screenResolution.set(display.getWidth(), display.getHeight());
    }
    return screenResolution;
}

From source file:Main.java

public static int screenHeightInPix(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(size);//  w  w w. j  a  v a2 s . c o  m
        return size.y;
    } else {
        return display.getHeight();
    }
}

From source file:Main.java

public static float[] get_show(Context context) {
    float[] greenshow = new float[2];
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*from   w w w.j  ava2  s. c  o m*/
    greenshow[0] = size.x;
    greenshow[1] = size.y;
    return greenshow;
}

From source file:Main.java

public static int getHeightScreen(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from ww w.  j ava2  s.c  o m
    return size.y;
}

From source file:Main.java

public static Point getScreenResolution(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point screenResolution = new Point();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        display.getSize(screenResolution);
    } else {/*from  www  .j  a  va  2  s  .c  om*/
        screenResolution.set(display.getWidth(), display.getHeight());
    }

    return screenResolution;
}

From source file:Main.java

/**
 * Returns the screen/display size//from   w w  w. j  a  v a  2  s  .  c  om
 *
 * @param context
 * @return
 */
@SuppressWarnings("deprecation")
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}