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:io.lqd.sdk.model.LQDevice.java

@SuppressWarnings("deprecation")
private static String getScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    int width = display.getWidth(); // deprecated
    int height = display.getHeight(); // deprecated
    return width + "x" + height;
}

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);/*  www . java2s . c  o m*/
        widthAndHeight[0] = size.x;
        widthAndHeight[1] = size.y;
    } else {
        widthAndHeight[0] = display.getWidth();
        widthAndHeight[1] = display.getHeight();
    }

    return widthAndHeight;
}

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./*from  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

/**
 * Compute the minimum cache size for a view. When the cache is created we do not actually
 * know the size of the mapview, so the screenRatio is an approximation of the required size.
 *
 * @param c              the context/* www.  j a  va  2s.  c o  m*/
 * @param tileSize       the tile size
 * @param overdrawFactor the overdraw factor applied to the mapview
 * @param screenRatio    the part of the screen the view covers
 * @return the minimum cache size for the view
 */
@SuppressWarnings("deprecation")
@TargetApi(13)
public static int getMinimumCacheSize(Context c, int tileSize, double overdrawFactor, float screenRatio) {
    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int height;
    int width;
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point p = new Point();
        display.getSize(p);
        height = p.y;
        width = p.x;
    } else {
        // deprecated since Android 13
        height = display.getHeight();
        width = display.getWidth();
    }

    // height  * overdrawFactor / tileSize calculates the number of tiles that would cover
    // the view port, adding 1 is required since we can have part tiles on either side,
    // adding 2 adds another row/column as spare and ensures that we will generally have
    // a larger number of tiles in the cache than a TileLayer will render for a view.
    // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part
    // of a screen (the result can be too low if a MapView is very narrow).
    // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the
    // middle of a view.
    return (int) Math.max(4, screenRatio * (2 + (height * overdrawFactor / tileSize))
            * (2 + (width * overdrawFactor / tileSize)));
}

From source file:org.solovyev.android.calculator.App.java

@SuppressWarnings("deprecation")
public static int getScreenOrientation(@Nonnull Activity activity) {
    final android.view.Display display = activity.getWindowManager().getDefaultDisplay();
    if (display.getWidth() <= display.getHeight()) {
        return Configuration.ORIENTATION_PORTRAIT;
    } else {//ww  w .j  a v  a 2s.c  om
        return Configuration.ORIENTATION_LANDSCAPE;
    }
}

From source file:Main.java

/**
 * Calculate displey size.//from ww w  . j a  va2s  .  c om
 * @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();
    }
}

From source file:com.ichi2.anki.Whiteboard.java

private static int getDisplayHeight() {
    Display display = ((WindowManager) AnkiDroidApp.getInstance().getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    return display.getHeight();
}

From source file:com.kayac.slidingmenu.ui.views.DraggableLayout.java

public static Point getScreenSize(Context c) {
    Point p = new Point();
    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    p.x = display.getWidth();//from   w  w  w .ja  v a  2s .  com
    p.y = display.getHeight();
    return p;
}

From source file:Main.java

public static HashMap<String, Integer> parseImageSizeWithUrl(Activity activity, String imageUrl) {

    int widthPx = DEFAULT_POST_IMAGE_WIDTH;
    int heightPx = DEFAULT_POST_IMAGE_HEIGHT;

    String[] file = imageUrl.split("\\.");
    int index = file.length - 2;
    String[] snippet = file[index].split("_");

    int snippetCount = snippet.length;
    if (snippetCount >= 3) {

        if (null != snippet[1]) {
            widthPx = Integer.parseInt(snippet[1]);
        }/*  w  w w.ja v a2  s  .  c o m*/

        if (null != snippet[2]) {
            heightPx = Integer.parseInt(snippet[2]);
        }
    }
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    int screenWidth = 0;
    int screenHeight = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    if (widthPx > screenWidth) {
        widthPx = screenWidth;
    } else if (widthPx < DEFAULT_POST_IMAGE_WIDTH) {
        widthPx = DEFAULT_POST_IMAGE_WIDTH;
    }

    if (heightPx > screenHeight) {
        heightPx = screenHeight;
    } else if (heightPx < DEFAULT_POST_IMAGE_HEIGHT) {
        heightPx = DEFAULT_POST_IMAGE_HEIGHT;
    }

    HashMap<String, Integer> imageSize = new HashMap<String, Integer>();
    imageSize.put("widthPx", widthPx);
    imageSize.put("heightPx", heightPx);
    return imageSize;
}

From source file:com.activiti.android.ui.utils.UIUtils.java

/**
 * Retrieve screen dimension.//from   w  w  w. j av  a  2 s .  co  m
 *
 * @param activity
 * @return
 */
public static int[] getScreenDimension(Activity activity) {
    int width = 0;
    int height = 0;

    Display display = activity.getWindowManager().getDefaultDisplay();
    if (AndroidVersion.isHCMR2OrAbove()) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth(); // deprecated
        height = display.getHeight(); // deprecated
    }

    return new int[] { width, height };
}