Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

In this page you can find the example usage for android.view Display getSize.

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getWidth(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);
        return size.x;
    } else/* ww w .  j a v a 2  s.  c  o m*/
        return display.getWidth();
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
// Whole Screen includes StatusBar and ActionBar
public static int getHeight(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);
        return size.y;
    } else// ww w  .java 2  s  .  c om
        return display.getHeight();
}

From source file:Main.java

public static Point getDisplaySize(Activity context) {
    Display display = context.getWindowManager().getDefaultDisplay();
    final Point point = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        display.getSize(point);
    } else {/*from  w ww. j  a  v  a2  s  .  c  o m*/
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}

From source file:Main.java

@SuppressWarnings("deprecation")
private static Point getDefaultDisplaySize(Activity activity, Point size) {
    Display d = activity.getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        d.getSize(size);
    } else {/*from w w  w.ja  va 2  s  . c  o  m*/
        size.set(d.getWidth(), d.getHeight());
    }
    return size;
}

From source file:Main.java

/**
 * Gets the screen size in pixels in a backwards compatible way
 *
 * @param caller        Activity calling; needed to get access to the {@link android.view.WindowManager}
 * @return              Size in pixels of the screen, or default {@link Point} if caller is null
 *//*from  w  ww .  j av a  2  s .c o m*/
public static Point getScreenSize(Activity caller) {
    Point size = new Point();
    if (caller != null) {
        Display display = caller.getWindowManager().getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
            display.getSize(size);
        } else {
            size.set(display.getWidth(), display.getHeight());
        }
    }
    return size;
}

From source file:Main.java

public static Point getRealScreenSize(Activity activity) {
    Point result = new Point();
    Display display = activity.getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealSize(result);//from w w  w .ja  v a2 s . c  o m
    } else {
        display.getSize(result);
    }
    return result;
}

From source file:Main.java

/**
 * <p>/*from  ww w.  j  a va  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

/**
 * Method that get the Screen Size//from   w  ww  . j a va 2 s.c  o m
 * @param activity Actual Activity
 * @return array type int 
 */
public static int[] getScreenSize(Activity activity) {

    //Obtain default display
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();

    //Set Size in case of ICS
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        display.getSize(size);
        return new int[] { size.x, size.y };
    } else {
        return new int[] { display.getWidth(), display.getHeight() };
    }
}

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  av  a2  s  .c o  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

/**
 * Calculate displey size./*  ww w.jav a2  s. com*/
 * @param context Context.
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private static void calculateDisplaySize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point screenSize = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(screenSize);

        displayWidth = screenSize.x;
        displayHeight = screenSize.y;
    } else {
        displayWidth = display.getWidth();
        displayHeight = display.getHeight();
    }
}