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[] getRealScreenSize(Context context) {

    int[] size = new int[2];

    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();//from   w  ww .  j  a v  a 2s  . c om
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);

    // since SDK_INT = 1;
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
        try {
            widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    } else if (Build.VERSION.SDK_INT >= 17) {// includes window decorations (statusbar bar/menu bar)
        Point realSize = new Point();
        d.getRealSize(realSize);
        widthPixels = realSize.x;
        heightPixels = realSize.y;
    }

    size[0] = widthPixels;
    size[1] = heightPixels;
    return size;
}

From source file:Main.java

private static int getDeviceOrientationDegree(Context context) {

    int degrees = 0;
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*w  ww .  j av a  2  s  .  co m*/
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    return degrees;

}

From source file:Main.java

/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is twice the device screen diagonal for default implementation (extra quality to zoom image).
 * Size cannot exceed max texture size.//  w  w w . j a  v a 2  s.  co m
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({ "SuspiciousNameCombination", "deprecation" })
public static int calculateMaxBitmapSize(@NonNull Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }

    int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

    Canvas canvas = new Canvas();
    return Math.min(screenDiagonal * 2,
            Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()));
}

From source file:Main.java

public static int[] getWidthAndHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(metrics);
    return new int[] { metrics.widthPixels, metrics.heightPixels };
}

From source file:Main.java

public static Display getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay();
}

From source file:Main.java

public static String getScreenDisplayID(Context ctx) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    return String.valueOf(wm.getDefaultDisplay().getDisplayId());
}

From source file:Main.java

private static float getDefaultDisplayRefreshRate(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return manager.getDefaultDisplay().getRefreshRate();
}

From source file:Main.java

public static DisplayMetrics getScreenSize(Context context) {
    if (displayMetrics == null) {
        try {/*from w  w  w.  j a va  2 s  . co  m*/

            displayMetrics = new DisplayMetrics();
            displayMetrics.widthPixels = 1280;
            displayMetrics.heightPixels = 720;
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            wm.getDefaultDisplay().getMetrics(displayMetrics);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

    }
    return displayMetrics;
}

From source file:Main.java

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

From source file:Main.java

public static DisplayMetrics getScreenPixels(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics;
}