Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

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 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 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);/*  ww  w  .j  a  v a2  s.  com*/
        return size.x;
    } else {
        return display.getWidth();
    }

}

From source file:Main.java

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

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);/*  w  ww  . jav a 2 s .  c o m*/
        screenWidth = size.x;
    }
    return screenWidth;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics metric = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metric);
    return metric.heightPixels;
}

From source file:Main.java

public static Point getScreenSize(Context ctx) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getSize(sPoint);//w  w w  . j  a v  a  2  s  .  c  om
    return sPoint;
}

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   ww w  . j  a  v a2s  .c om
    greenshow[0] = size.x;
    greenshow[1] = size.y;
    return greenshow;
}

From source file:Main.java

public static int getScreenWidth(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);//from   ww  w . ja va 2 s  .  c  o m
    return point.x;
}

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);/*w ww.  jav a2 s. c  om*/
    return dMetrics.density;
}