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

public static Point getScreenWidthAndHeight(Context context) {
    Display defaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//  ww w.  jav a  2s  .  c om
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    Display defaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();/* ww  w  . ja v  a 2  s . co  m*/
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point.y;
}

From source file:Main.java

public static Point getWindowSize(Display defaultDisplay) {
    Point windowSize = new Point();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
        defaultDisplay.getSize(windowSize);
    } else {/*www .j  a va  2  s .co m*/
        windowSize.x = defaultDisplay.getWidth();
        windowSize.y = defaultDisplay.getHeight();
    }
    return windowSize;
}

From source file:Main.java

public static Point getScreenSize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
    } else {//w ww .j av  a  2s .c  o m
        size.set(display.getWidth(), display.getHeight());
    }

    return size;
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static int[] getScreenWidthHeight(Context context) {

    int[] widthAndHeight = new int[2];

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

    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        widthAndHeight[0] = size.x;/*from  ww  w.ja v a2 s.  co m*/
        widthAndHeight[1] = size.y;
    } else {
        widthAndHeight[0] = display.getWidth();
        widthAndHeight[1] = display.getHeight();
    }

    return widthAndHeight;
}

From source file:Main.java

public static Point getScreenSize(Context appContext) {
    final Display display = ((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//from w  w w . j a  va2 s  .com
    final Point point = new Point();
    display.getSize(point);
    return point;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Point getScreenSize(Context mContext) {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        return size;
    } else {//from   w  ww.j  ava  2 s  .  com
        size.x = display.getWidth();
        size.y = display.getHeight();
        return size;
    }
}

From source file:Main.java

public static Point getScreenSize(Context applicationContext) {

    WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
        display.getSize(size);
    else {//w  w  w. jav a2 s  .  co m
        size.x = display.getWidth();
        size.y = display.getHeight();
    }
    return size;
}

From source file:Main.java

public static int getScreenWidth(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    int width = 800;
    if (Build.VERSION.SDK_INT > 13) {
        display.getSize(size);
        width = size.x;//from  w  w  w  .  j a  v a  2 s  . c om
    } else {
        width = display.getWidth();
    }
    return width;
}

From source file:Main.java

public static int getScreenHeight(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    int height = 200;
    if (Build.VERSION.SDK_INT > 13) {
        display.getSize(size);
        height = size.y;//w  w w  .  java 2 s.c o  m
    } else {
        height = display.getHeight();
    }
    return height;
}