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 boolean isVertical(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//  www.  j a v a2 s  .  co m
    int width = size.x;
    int height = size.y;

    if (width > height) {
        return false;
    } else {
        return true;
    }
}

From source file:Main.java

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

From source file:Main.java

public static float getScreenDensity(Context context) {
    try {//from   www .  j a  v a  2s.c om
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        manager.getDefaultDisplay().getMetrics(dm);
        return dm.density;
    } catch (Exception ex) {

    }
    return 1.0f;
}

From source file:Main.java

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

From source file:Main.java

public static Point getScreenWidthAndHeight(Context context) {
    Display defaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();/* w  ww .  j ava2  s.co m*/
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point;
}

From source file:Main.java

/**
 * @param context//from  ww w .j  a v  a 2s .co m
 * @return DisplayMetrics.
 */
public static DisplayMetrics getDisplayMetrics(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:Main.java

/**
 * Get the constant describing the rotation of the screen.
 *
 * @param context//from ww  w  .java 2s  .co  m
 * @return
 */
public static int getDisplayRotation(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getRotation();
}

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("deprecation")
public static String getDisplayMetrics(Context ctx) {
    String metrics = "";
    try {// ww w.  j a  v a 2 s . co  m
        Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        metrics += width;
        metrics += "x";
        metrics += height;
    } catch (Exception e) {
    }

    return metrics;
}

From source file:Main.java

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

}