Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

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

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

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();
    p.y = display.getHeight();/* w  w  w  .j av  a2  s  . c  om*/
    return p;
}

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//from ww w.  j a  va2 s.  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:com.activiti.android.ui.utils.UIUtils.java

/**
 * Retrieve screen dimension.//w w  w. j av  a  2 s.  c  o 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 };
}

From source file:org.alfresco.mobile.android.ui.utils.UIUtils.java

/**
 * Retrieve screen dimension./* w  ww .  jav  a2 s .c  om*/
 * 
 * @param activity
 * @return
 */
public static int[] getScreenDimension(FragmentActivity 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 };
}

From source file:org.kontalk.util.SystemUtils.java

@SuppressWarnings("deprecation")
public static Point getDisplaySize(Context context) {
    Point displaySize = null;/*  w  w  w .  ja v  a2s  . c  om*/
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    if (display != null) {
        displaySize = new Point();
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
            displaySize.set(display.getWidth(), display.getHeight());
        } else {
            display.getSize(displaySize);
        }
    }

    return displaySize;
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static Point getRealScreenSize(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealSize(size);//from   ww w . j  a va 2s.  c  om
    } else {
        try {
            size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
        } catch (Exception e) {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
    }
    return size;
}

From source file:Main.java

public static Point getSize(Display display) {
    if (Build.VERSION.SDK_INT >= 17) {
        Point outPoint = new Point();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getRealMetrics(metrics);
        outPoint.x = metrics.widthPixels;
        outPoint.y = metrics.heightPixels;
        return outPoint;
    }/*w ww  .java  2s  .c om*/
    if (Build.VERSION.SDK_INT >= 14) {
        Point outPoint = getRealSize(display);
        if (outPoint != null)
            return outPoint;
    }
    Point outPoint = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(outPoint);
    } else {
        outPoint.x = display.getWidth();
        outPoint.y = display.getHeight();
    }
    return outPoint;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static boolean m932a(Context context) {
    DisplayMetrics displayMetrics = context.getApplicationContext().getResources().getDisplayMetrics();
    Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    int width = defaultDisplay.getWidth();
    int height = defaultDisplay.getHeight();
    float f = displayMetrics.density;
    if (((float) width) / f < 600.0f || ((float) height) / f < 600.0f) {
        return false;
    }//  ww w .  j  a v a2 s  .  c  o  m
    return true;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Point getFullDisplaySize(Context context) {
    Point point = new Point();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    Display display = wm.getDefaultDisplay();
    Method mGetRawH = null, mGetRawW = null;

    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);/*from w  ww  .  j a v a 2 s  . c o m*/

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        display.getRealMetrics(outMetrics);
        point.x = outMetrics.widthPixels;
        point.y = outMetrics.heightPixels;
    } else {
        try {
            mGetRawH = Display.class.getMethod("getRawHeight");
            mGetRawW = Display.class.getMethod("getRawWidth");
            point.x = (Integer) mGetRawW.invoke(display);
            point.y = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            display.getMetrics(outMetrics);
            point.x = display.getWidth();
            point.y = display.getHeight();
            e.printStackTrace();
        }
    }

    return point;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m965k(Context context) {
    String str = "";
    if (context == null) {
        return str;
    }//from  w  w  w. j  a  va2  s  .  c  om
    Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    if (VERSION.SDK_INT < NETWORK_TYPE_LTE) {
        return "" + defaultDisplay.getWidth() + "_" + defaultDisplay.getHeight();
    }
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point.x + "_" + point.y;
}