Android Utililty Methods Display Density Get

List of utility methods to do Display Density Get

Description

The list of methods to do Display Density Get are organized into topic(s).

Method

floatgetDensity(Context context)
get Density
return context.getResources().getDisplayMetrics().density;
intgetDensitySize(Context context, int size)
get Density Size
return (int) getDensity(context) * size;
RectgetBounds(Display d, Rect r)
get Bounds
return new Rect(r.left, r.top, d.getWidth() - r.right,
        d.getHeight() - r.bottom);
floatapplyDimension(int unit, float value, DisplayMetrics metrics)
apply Dimension
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
    return value;
case TypedValue.COMPLEX_UNIT_DIP:
    return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
    return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
...
floatgetDisplayPPI()
device methods
DisplayMetrics displayMetrics = Resources.getSystem()
        .getDisplayMetrics();
return (displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f;