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 getHeightWindowWithContext(Context mContext) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from w  ww .j av a  2  s.c  om
    return size.y;
}

From source file:Main.java

public static int getOrientation(Context context) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    displayMetrics.widthPixels = 1280;//from w  w  w  .jav a2  s . c o m
    displayMetrics.heightPixels = 720;
    try {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(displayMetrics);
    } catch (Exception e) {
        //do nothing
    }

    if (displayMetrics.heightPixels > displayMetrics.widthPixels) {
        return PORTRAIT;
    } else {
        return LANDSCAPE;
    }
}

From source file:Main.java

/**
 * Get the screen height.//from w ww . j  a  va  2  s .  co  m
 *
 * @param context
 * @return the screen height
 */
public static int getScreenHeight(Context context) {
    if (context != null) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);

        return displayMetrics.heightPixels;
    } else {
        return 1920;
    }
}

From source file:Main.java

/**
 * Get the screen width.// ww w  .j  ava 2 s . c  om
 *
 * @param context
 * @return the screen width
 */
public static int getScreenWidth(Context context) {
    if (context != null) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);

        return displayMetrics.widthPixels;
    } else {
        return 1080;
    }
}

From source file:Main.java

public static String getScreenWxH(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//w w w.j  av a  2  s  . co m
    int width = size.x;
    int height = size.y;

    return width + "x" + height;
}

From source file:Main.java

public static Point getScreenDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point point = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(point);/* w  ww .ja  v a  2  s  .c o m*/
    } else {
        point = new Point(display.getWidth(), display.getHeight());
    }

    return point;
}

From source file:Main.java

public static int screenWidthInPix(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);//from   w w w. j  a  v a  2  s  . c  o  m
        return size.x;
    } else {
        return display.getWidth();
    }

}

From source file:Main.java

public static Point getDisplaySize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);/*from   w  w w. j av a  2  s  .  c  o m*/
    return point;
}

From source file:Main.java

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

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);//from   w ww  .  j a  v  a  2 s .c  o  m
    return metrics.widthPixels;
}