Example usage for android.view Display getHeight

List of usage examples for android.view Display getHeight

Introduction

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

Prototype

@Deprecated
public int getHeight() 

Source Link

Usage

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);/*w  ww  . j a  v a2s. co m*/
    } else {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}

From source file:Main.java

public static int[] getWindowSize(Context context) {
    final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point point = new Point();
        display.getSize(point);//  w  w  w  .j a va  2  s . c  om
        return new int[] { point.x, point.y };
    } else {
        return new int[] { display.getWidth(), display.getHeight() };
    }
}

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
 *//*w ww .j a  v  a2 s.co  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 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 {//from   w w w .ja  v  a  2s .com
        windowSize.x = defaultDisplay.getWidth();
        windowSize.y = defaultDisplay.getHeight();
    }
    return windowSize;
}

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);//from   ww w.jav a  2 s  .  c om
        return size;
    } else {
        size.x = display.getWidth();
        size.y = display.getHeight();
        return size;
    }
}

From source file:com.wwtv.player.utils.Utils.java

@SuppressWarnings("deprecation")
/**//from ww  w.j  a  v  a2s .co  m
 * Returns the screen/display size
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:com.google.sample.cast.refplayer.utils.Utils.java

@SuppressWarnings("deprecation")
/**//from ww  w .  ja  v  a 2s  .  co m
 * Returns the screen/display size
 *
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:Main.java

/**
 * @Thach Feb 21, 2014//from  w ww. j a  v  a  2 s .c o m
 * @Desc lock Orientation
 * @param b
 */
@SuppressWarnings("deprecation")
public static void lockOrientation(Activity act, boolean isLock) {
    if (act == null) {
        return;
    }
    if (isLock) {
        Display display = act.getWindowManager().getDefaultDisplay();
        int rotation = display.getRotation();
        int height;
        int width;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
            height = display.getHeight();
            width = display.getWidth();
        } else {
            Point size = new Point();
            display.getSize(size);
            height = size.y;
            width = size.x;
        }
        switch (rotation) {
        case Surface.ROTATION_90:
            if (width > height)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            else
                act.setRequestedOrientation(9/* reversePortait */);
            break;
        case Surface.ROTATION_180:
            if (height > width)
                act.setRequestedOrientation(9/* reversePortait */);
            else
                act.setRequestedOrientation(8/* reverseLandscape */);
            break;
        case Surface.ROTATION_270:
            if (width > height)
                act.setRequestedOrientation(8/* reverseLandscape */);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        default:
            if (height > width)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else {
        act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:Main.java

/**
 * Method that get the Screen Size//from  w ww.jav  a2 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

@SuppressWarnings("deprecation")
private static boolean hasOnScreenSystemBar(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    int rawDisplayHeight = 0;
    try {//from   w  w  w  . ja v  a  2  s.  c o  m
        Method getRawHeight = Display.class.getMethod("getRawHeight");
        rawDisplayHeight = (Integer) getRawHeight.invoke(display);
    } catch (Exception ex) {
    }

    int uiRequestedHeight = display.getHeight();
    return rawDisplayHeight - uiRequestedHeight > 0;
}