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[] getScreenSize(Context context) {
    int[] size = new int[2];
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(dm);
    size[0] = dm.widthPixels;/*from   w ww.jav  a  2  s.  c  o m*/
    size[1] = dm.heightPixels;
    return size;
}

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);/* w  w w.jav  a 2s. com*/
        screenWidth = size.x;
    }

    return screenWidth;
}

From source file:Main.java

public static float getDensity(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
    wm.getDefaultDisplay().getMetrics(metrics);

    return metrics.density;
}

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);//  w  w w.ja va  2 s  .com
        screenHeight = size.y;
    }

    return screenHeight;
}

From source file:Main.java

public static String getRelation(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager windowMgr = (WindowManager) context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    windowMgr.getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    return String.valueOf(width) + "*" + String.valueOf(height);
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static int getMetricsDensity(Context context, float height) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
            .getMetrics(localDisplayMetrics);
    return Math.round(height * localDisplayMetrics.densityDpi / 160.0F);
}

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 ava  2 s .c om
        return size.y;
    } else {
        return display.getHeight();
    }
}

From source file:Main.java

public static int getOrientation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display getOrient = windowManager.getDefaultDisplay();
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (getOrient.getWidth() == getOrient.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {//from   ww w  . j a va  2  s. c  om
        if (getOrient.getWidth() < getOrient.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}