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 getScreenWidth(Context context) {
    if (screenWidth != -1) {
        return screenWidth;
    }// ww  w  .ja va  2 s . c o  m

    Point size = new Point();
    ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);

    screenWidth = size.x;
    return screenWidth;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static Point getDisplayInfo(Context ctx) {
    Point info = new Point();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getSize(info);
    ;// w ww .jav  a2 s  . c  o  m
    return info;
}

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);// w w w  .  j av a  2s .  c om
    return size;
}

From source file:Main.java

public static DisplayMetrics getDisplayMetric(Context context) {
    if (context != null) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics displayMetrics = new DisplayMetrics();
        Display display = windowManager.getDefaultDisplay();
        display.getMetrics(displayMetrics);
        return displayMetrics;
    }//from  w  w  w . jav  a 2 s. c o m
    return null;
}

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);//  w ww .j a v a2  s. c o m
    return dMetrics;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    if (screenHeight != -1) {
        return screenHeight;
    }/* w w w  .j  a  va 2  s  .  c om*/

    Point size = new Point();
    ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);

    screenHeight = size.y;
    return screenHeight;
}

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 av a  2 s  .  co  m*/

    return metrics;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getWidth();
}

From source file:Main.java

/**
 * DisplayMetrics//from   w  w  w  .  j  a v  a 2 s .c  o  m
 *
 * @return
 */
public static DisplayMetrics getDisplayMetrics(Context context) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics;
}

From source file:Main.java

public static int getWindowWidth(Context context) {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);//w w w  .  j  a  va 2  s .co m
    }
    if (screenSize != null)
        return screenSize.x;
    else
        return 0;
}