public class DisplayUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DisplayUtil.DeviceType
Contains all possible types of devices, depending on their display size.
|
static class |
DisplayUtil.Orientation
Contains all possible orientations of devices.
|
| Modifier and Type | Field and Description |
|---|---|
protected static float |
PIXEL_DP_RATIO
The ratio, which can be used to convert values, which are measured in pixels, into values,
which are measured in dp, and vice versa.
|
| Modifier and Type | Method and Description |
|---|---|
static double |
dpToPixels(android.content.Context context,
double dp)
Converts a
Double value, which is measured in dp, into a value, which is measured in
pixels. |
static float |
dpToPixels(android.content.Context context,
float dp)
Converts a
Float value, which is measured in dp, into a value, which is measured in
pixels. |
static int |
dpToPixels(android.content.Context context,
int dp)
Converts an
Integer value, which is measured in dp, into a value, which is measured
in pixels. |
static long |
dpToPixels(android.content.Context context,
long dp)
Converts an
Integer value, which is measured in dp, into a value, which is measured
in pixels. |
static float |
getDensity(android.content.Context context)
Returns the logical density of the device's display.
|
static DisplayUtil.DeviceType |
getDeviceType(android.content.Context context)
Returns the type of the device, depending on its display size.
|
static int |
getDisplayHeight(android.content.Context context)
Returns the height of the device's display.
|
static int |
getDisplayWidth(android.content.Context context)
Returns the width of the device's display.
|
static int |
getNavigationBarHeight(android.content.Context context)
Returns the height of the navigation bar, which is shown at the bottom of the display
(containing for example back, home and recent apps soft-keys).
|
static DisplayUtil.Orientation |
getOrientation(android.content.Context context)
Returns the orientation of the device.
|
static int |
getStatusBarHeight(android.content.Context context)
Returns the height of the status bar, which is shown at the top of the display (containing
the clock, battery indicator, etc.).
|
static double |
pixelsToDp(android.content.Context context,
double pixels)
Converts a
Double value, which is measured in pixels, into a value, which is measured
in dp. |
static float |
pixelsToDp(android.content.Context context,
float pixels)
Converts a
Float value, which is measured in pixels, into a value, which is measured
in dp. |
static int |
pixelsToDp(android.content.Context context,
int pixels)
Converts an
Integer value, which is measured in pixels, into a value, which is
measured in dp. |
static long |
pixelsToDp(android.content.Context context,
long pixels)
Converts an
Long value, which is measured in pixels, into a value, which is measured
in dp. |
protected static final float PIXEL_DP_RATIO
public static int pixelsToDp(android.content.Context context,
int pixels)
Integer value, which is measured in pixels, into a value, which is
measured in dp.context - The context, which should be used, as an instance of the class Context. The
context may not be nullpixels - The pixel value, which should be converted, as an Integer valueInteger value. The value might be roundedpublic static long pixelsToDp(android.content.Context context,
long pixels)
Long value, which is measured in pixels, into a value, which is measured
in dp.context - The context, which should be used, as an instance of the class Context. The
context may not be nullpixels - The pixel value, which should be converted, as an Long valueLong value. The value might be roundedpublic static float pixelsToDp(android.content.Context context,
float pixels)
Float value, which is measured in pixels, into a value, which is measured
in dp.context - The context, which should be used, as an instance of the class Context. The
context may not be nullpixels - The pixel value, which should be converted, as a Float valueFloat valuepublic static double pixelsToDp(android.content.Context context,
double pixels)
Double value, which is measured in pixels, into a value, which is measured
in dp.context - The context, which should be used to, as an instance of the class Context.
The context may not be nullpixels - The pixel value, which should be converted, as a Double valueDouble valuepublic static int dpToPixels(android.content.Context context,
int dp)
Integer value, which is measured in dp, into a value, which is measured
in pixels.context - The context, which should be used, as an instance of the class Context. The
context may not be nulldp - The dp value, which should be converted, as an Integer valueInteger value. The value might be roundedpublic static long dpToPixels(android.content.Context context,
long dp)
Integer value, which is measured in dp, into a value, which is measured
in pixels.context - The context, which should be used, as an instance of the class Context. The
context may not be nulldp - The dp value, which should be converted, as an Integer valueInteger value. The value might be roundedpublic static float dpToPixels(android.content.Context context,
float dp)
Float value, which is measured in dp, into a value, which is measured in
pixels.context - The context, which should be used, as an instance of the class Context. The
context may not be nulldp - The dp value, which should be converted, as a Float valueFloat valuepublic static double dpToPixels(android.content.Context context,
double dp)
Double value, which is measured in dp, into a value, which is measured in
pixels.context - The context, which should be used, as an instance of the class Context. The
context may not be nulldp - The dp value, which should be converted, as a Double valueDouble valuepublic static DisplayUtil.Orientation getOrientation(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullDisplayUtil.Orientation. The
orientation may either be PORTRAIT, LANDSCAPE or
SQUAREpublic static DisplayUtil.DeviceType getDeviceType(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullDisplayUtil.DeviceType. The type may either
be PHONE, PHABLET or TABLETpublic static int getDisplayWidth(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullInteger valuepublic static int getDisplayHeight(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullInteger valuepublic static float getDensity(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullFloat valuepublic static int getStatusBarHeight(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullInteger valuepublic static int getNavigationBarHeight(android.content.Context context)
context - The context, which should be used, as an instance of the class Context. The
context may not be nullInteger value or 0, if no
navigation bar is shown