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

/**
 * @return return screen height px unit.
 *//*ww w .  ja v  a  2  s  .  co m*/
public static int getScreenHeigth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:Main.java

/**
 * get the screen height in pixels/*w ww .j av a  2 s .c  om*/
 * @param context
 * @return
 */
public static int getScreenHeight(Context context) {
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:Main.java

/**
 * get the screen width in pixels/*from   w  w  w. j  a va 2  s.com*/
 * @param context
 * @return
 */
public static int getScreenWidth(Context context) {
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:Main.java

/**
 * Computes the navigation bar height comparing the usable screen height and the real display height.
 * Please note that the system status bar is considered part of the usable screen height.
 * @param context Android Context instance
 * @return The height in pixels of the system navigation bar
 *///ww  w . j  av  a 2  s. c o m
public static int getNavigationBarSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    //noinspection ConstantConditions
    Display display = windowManager.getDefaultDisplay();

    Point appUsableSize = new Point();
    display.getSize(appUsableSize);
    Point realScreenSize = new Point();
    display.getRealSize(realScreenSize);

    return realScreenSize.y - appUsableSize.y;
}

From source file:Main.java

public static int getWidthInPx(Context context) {

    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;

    return width;
}

From source file:Main.java

/**
 * Determining the smallest size of the screen to detect "real small devices",
 * the dpi modifier is not reliable on Samsung devices
 *
 * @param activity - current activity// ww w .  ja  va2s .com
 * @return the size of the smallest edge of default display in pixels
 */
private static int getSmallestScreenSize(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    return Math.min(point.x, point.y);
}

From source file:Main.java

public static void getListViewSize(ListView listView, Context context) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null || listAdapter.getCount() < 2) {
        // pre-condition
        return;//from ww  w  .  jav a  2s. c om
    }

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int totalHeight = 0;
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(size.x, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, listItem.getHeight());
        totalHeight += listItem.getMeasuredHeight();
    }

    totalHeight += listView.getPaddingTop() + listView.getPaddingBottom();
    totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() + 1));
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight;
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:Main.java

public static void initDiplaySize(Activity context) {
    if (screenWidth > 0 && screenHeight > 0)
        return;//from   w  w  w . ja v  a  2s .  c o m

    Display dis = context.getWindowManager().getDefaultDisplay();
    Point outSize = new Point(0, 0);
    dis.getSize(outSize);
    if (outSize != null) {
        screenWidth = outSize.x;
        screenHeight = outSize.y;
    }
}

From source file:Main.java

public static int screenHeightInPix(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(size);
        return size.y;
    } else {/*from  w  ww.j a  v a 2 s . c  om*/
        return display.getHeight();
    }
}