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 getScreenResolution(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    int width = outMetrics.widthPixels;
    int height = outMetrics.heightPixels;
    return width * height;
}

From source file:Main.java

public static int getHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);

    return outMetrics.heightPixels;
}

From source file:Main.java

public static int getWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);

    return outMetrics.widthPixels;
}

From source file:Main.java

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

From source file:Main.java

public static int getDPI() {
    if (sContext != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager wm = ((Activity) sContext).getWindowManager();
        if (wm != null) {
            Display d = wm.getDefaultDisplay();
            if (d != null) {
                d.getMetrics(metrics);//w  w w . j a  va2  s .  c o  m
                return (int) (metrics.density * 160.0f);
            }
        }
    }
    return -1;
}

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();
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);// w  w w. j a v  a 2s . co m

    // 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 void getDisplay(Context context) {
    if (width <= 0 || height <= 0) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;/*from  ww  w.jav  a  2  s.co  m*/
        height = dm.heightPixels;
    }
}

From source file:Main.java

/**
 * <pre>//w ww . j a  v a  2 s  . co m
 * Get sizes of screen in pixels.
 * </pre>
 * @return interger array with 2 elements: width and height
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")
public static int[] getDisplaySizes() {
    Context context = getCurrentContext();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    if (Build.VERSION.SDK_INT < 13) {
        return new int[] { display.getWidth(), display.getHeight() };
    } else {
        Point point = new Point();
        display.getSize(point);
        return new int[] { point.x, point.y };
    }
}

From source file:Main.java

public static String getDisplayMetrics(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    DisplayMetrics metrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(metrics);

    return String.format("%dx%d", metrics.widthPixels, metrics.heightPixels);
}

From source file:Main.java

/**
 * Resamples the captured photo to fit the screen for better memory usage.
 *
 * @param context   The application context.
 * @param imagePath The path of the photo to be resampled.
 * @return The resampled bitmap//ww  w.  j  a  va  2  s  .  co m
 */
static Bitmap resamplePic(Context context, String imagePath) {

    // Get device screen size information
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(metrics);

    int targetH = metrics.heightPixels;
    int targetW = metrics.widthPixels;

    // Get the dimensions of the original bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;

    return BitmapFactory.decodeFile(imagePath);
}