Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:Main.java

public static int getDisplayHeight(Context context) {
    if (displayHeight <= 0) {
        WindowManager wm = (WindowManager) context.getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        displayHeight = dm.heightPixels;
    }/*from w  w w .  j a v  a  2  s . c om*/
    return displayHeight;
}

From source file:Main.java

public static int getDisplayWidth(Context context) {
    if (displayWidth <= 0) {
        WindowManager wm = (WindowManager) context.getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        displayWidth = dm.widthPixels;//from   ww w .  j  ava 2 s  .c  om
    }
    return displayWidth;
}

From source file:Main.java

public static Bitmap getFitableBitmapWithReflection(Context context, Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }/*  www .  j  a v  a2 s .com*/
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    float scale = 1.0f;
    if (width > 400) {
        scale = 1.8f;
    } else if (width > 300) {
        scale = 1.2f;
    } else {
        scale = 1.0f;
    }
    Log.i(TAG, "" + scale);
    Bitmap scaleBitmap = zoomBitmap(bitmap, scale);
    return createReflectionImageWithOrigin(scaleBitmap);
}

From source file:Main.java

/**
 * <p>/*from   w  w w.j  a  v a  2s .c  o m*/
 * This method takes in the WindowManager and returns the Screen Dimensions in pixels.</br></br>
 * </p>
 * <p>To get width (getWindowDisplaySize(wm).x) or height (getWindowDisplaySize(wm).y)</p>
 *
 * @return WindowDisplaySize
 */
public static Point getWindowDisplaySize(WindowManager wm) {
    Display display;
    Point WindowDisplaySize = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        display = wm.getDefaultDisplay();
        display.getSize(WindowDisplaySize);
    } else {
        DisplayMetrics displaymetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(displaymetrics);
        int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;
        WindowDisplaySize.set(width, height);
    }
    return WindowDisplaySize;
}

From source file:Main.java

/**
 * Set Camera orientation to correct one
 * @param context app context/* www . jav a  2s.  com*/
 * @param camera camera to set orientation
 */
public static void setCameraDisplayOrientation(Context context, Camera camera) {
    if (camera == null) {
        return;
    }

    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(getCameraInformationId(), info);

    WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int rotation = winManager.getDefaultDisplay().getRotation();

    int degrees = 0;

    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
}

From source file:Main.java

/**
 * Method getDeviceScreenWidth(), It's used for checking the screen's with
 * and To develop the functionality of horizontal direction or vertical
 * direction, we can used this for seperating the raised issues
 * //ww w  .ja  v  a  2  s.  co  m
 * @return Integer Type.
 */
public static int getDeviceScreenWidth(Context context) {
    int width;
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        width = wm.getDefaultDisplay().getHeight();
    } else {
        width = wm.getDefaultDisplay().getWidth();
    }
    return width;
}

From source file:Main.java

public static Pair<Integer, Integer> getWindowDimensionsWithoutMargin(Context context,
        WindowManager windowManager, int dpMarginX, int dpMarginY) {

    dpMarginX *= 2;//w w  w  .j  a  v  a2s .  c o  m
    dpMarginY *= 2;

    DisplayMetrics displayMetrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;
    int screenHeight = displayMetrics.heightPixels;

    int marginX = dpToPx(context, dpMarginX);
    if (hasSoftNavigation(context)) {
        dpMarginY += 30;
    }
    int marginY = dpToPx(context, dpMarginY);

    Pair<Integer, Integer> dimensions = new Pair<Integer, Integer>(screenWidth - marginX,
            screenHeight - marginY);

    return dimensions;
}

From source file:Main.java

/**
 * Method getDeviceScreenHeight(). It's used for checking the screen's with
 * and To develop the functionality of horizontal direction or vertical
 * direction, we can used this for seperating the raised issues
 * /*from  w  w  w.j  ava2 s  .c  om*/
 * @return Integer Type.
 */
public static int getDeviceScreenHeight(Context context) {
    int height;
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        height = wm.getDefaultDisplay().getWidth();
    } else {
        height = wm.getDefaultDisplay().getHeight();
    }
    return height;

}

From source file:Main.java

public static Point getScreenResolution(Context context) {

    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();

    int width = display.getWidth();
    int height = display.getHeight();

    return new Point(width, height);

}

From source file:com.gitstudy.rili.liarbry.YearViewSelectLayout.java

/**
 * /*  w  w w . jav a2s. com*/
 *
 * @param context context
 * @param view    view
 * @return ?
 */
private static int getHeight(Context context, View view) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    assert manager != null;
    Display display = manager.getDefaultDisplay();
    int h = display.getHeight();
    int[] location = new int[2];
    view.getLocationInWindow(location);
    view.getLocationOnScreen(location);
    return h - location[1];
}