public final class Display extends Object
The display area is described in two different ways.
getSize(android.graphics.Point)
, getRectSize(android.graphics.Rect)
and getMetrics(android.util.DisplayMetrics)
.getRealSize(android.graphics.Point)
, getRealMetrics(android.util.DisplayMetrics)
.A logical display does not necessarily represent a particular physical display device such as the built-in screen or an external monitor. The contents of a logical display may be presented on one or more physical displays according to the devices that are currently attached and whether mirroring has been enabled.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DISPLAY
The default Display id, which is the id of the built-in primary display
assuming there is one.
|
static int |
FLAG_SECURE
Display flag: Indicates that the display has a secure video output and
supports compositing secure surfaces.
|
static int |
FLAG_SUPPORTS_PROTECTED_BUFFERS
Display flag: Indicates that the display supports compositing content
that is stored in protected graphics buffers.
|
static int |
TYPE_BUILT_IN
Display type: Built-in display.
|
static int |
TYPE_HDMI
Display type: HDMI display.
|
static int |
TYPE_OVERLAY
Display type: Overlay display.
|
static int |
TYPE_UNKNOWN
Display type: Unknown display type.
|
static int |
TYPE_WIFI
Display type: WiFi display.
|
Constructor and Description |
---|
Display(DisplayManagerGlobal global,
int displayId,
DisplayInfo displayInfo,
CompatibilityInfoHolder compatibilityInfo)
Internal method to create a display.
|
Modifier and Type | Method and Description |
---|---|
String |
getAddress()
Gets the display address, or null if none.
|
CompatibilityInfoHolder |
getCompatibilityInfo()
Gets the compatibility info used by this display instance.
|
void |
getCurrentSizeRange(Point outSmallestSize,
Point outLargestSize)
Return the range of display sizes an application can expect to encounter
under normal operation, as long as there is no physical change in screen
size.
|
int |
getDisplayId()
Gets the display id.
|
boolean |
getDisplayInfo(DisplayInfo outDisplayInfo)
Gets a full copy of the display information.
|
int |
getFlags()
Returns a combination of flags that describe the capabilities of the display.
|
int |
getHeight()
Deprecated.
Use
getSize(Point) instead. |
int |
getLayerStack()
Gets the display's layer stack.
|
int |
getMaximumSizeDimension()
Return the maximum screen size dimension that will happen.
|
void |
getMetrics(DisplayMetrics outMetrics)
Gets display metrics that describe the size and density of this display.
|
String |
getName()
Gets the name of the display.
|
int |
getOrientation()
Deprecated.
use
getRotation() |
int |
getPixelFormat()
Deprecated.
This method is no longer supported.
The result is always
PixelFormat.RGBA_8888 . |
void |
getRealMetrics(DisplayMetrics outMetrics)
Gets display metrics based on the real size of this display.
|
void |
getRealSize(Point outSize)
Gets the real size of the display without subtracting any window decor or
applying any compatibility scale factors.
|
void |
getRectSize(Rect outSize)
Gets the size of the display as a rectangle, in pixels.
|
float |
getRefreshRate()
Gets the refresh rate of this display in frames per second.
|
int |
getRotation()
Returns the rotation of the screen from its "natural" orientation.
|
void |
getSize(Point outSize)
Gets the size of the display, in pixels.
|
int |
getType()
Gets the display type.
|
int |
getWidth()
Deprecated.
Use
getSize(Point) instead. |
boolean |
isValid()
Returns true if this display is still valid, false if the display has been removed.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static String |
typeToString(int type) |
public static final int DEFAULT_DISPLAY
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS
If this flag is set then the display device supports compositing protected buffers.
If this flag is not set then the display device may not support compositing protected buffers; the user may see a blank region on the screen instead of the protected content.
Secure (DRM) video decoders may allocate protected graphics buffers to request that a hardware-protected path be provided between the video decoder and the external display sink. If a hardware-protected path is not available, then content stored in protected graphics buffers may not be composited.
An application can use the absence of this flag as a hint that it should not use protected buffers for this display because the content may not be visible. For example, if the flag is not set then the application may choose not to show content on this display, show an informative error message, select an alternate content stream or adopt a different strategy for decoding content that does not rely on protected buffers.
getFlags()
,
Constant Field Valuespublic static final int FLAG_SECURE
If this flag is set then the display device has a secure video output
and is capable of showing secure surfaces. It may also be capable of
showing protected buffers
.
If this flag is not set then the display device may not have a secure video output; the user may see a blank region on the screen instead of the contents of secure surfaces or protected buffers.
Secure surfaces are used to prevent content rendered into those surfaces by applications from appearing in screenshots or from being viewed on non-secure displays. Protected buffers are used by secure video decoders for a similar purpose.
An application creates a window with a secure surface by specifying the
WindowManager.LayoutParams.FLAG_SECURE
window flag.
Likewise, an application creates a SurfaceView
with a secure surface
by calling SurfaceView#setSecure
before attaching the secure view to
its containing window.
An application can use the absence of this flag as a hint that it should not create secure surfaces or protected buffers on this display because the content may not be visible. For example, if the flag is not set then the application may choose not to show content on this display, show an informative error message, select an alternate content stream or adopt a different strategy for decoding content that does not rely on secure surfaces or protected buffers.
getFlags()
,
Constant Field Valuespublic static final int TYPE_UNKNOWN
public static final int TYPE_BUILT_IN
public static final int TYPE_HDMI
public static final int TYPE_WIFI
public static final int TYPE_OVERLAY
public Display(DisplayManagerGlobal global, int displayId, DisplayInfo displayInfo, CompatibilityInfoHolder compatibilityInfo)
WindowManager.getDefaultDisplay()
or DisplayManager.getDisplay(int)
to get a display object.public int getDisplayId()
Each logical display has a unique id.
The default display has id DEFAULT_DISPLAY
.
public boolean isValid()
Display
object after the display's demise.
It's possible for a display that was previously invalid to become
valid again if a display with the same id is reconnected.public boolean getDisplayInfo(DisplayInfo outDisplayInfo)
outDisplayInfo
- The object to receive the copy of the display information.public int getLayerStack()
public int getFlags()
FLAG_SUPPORTS_PROTECTED_BUFFERS
,
FLAG_SECURE
public int getType()
TYPE_UNKNOWN
,
TYPE_BUILT_IN
,
TYPE_HDMI
,
TYPE_WIFI
,
TYPE_OVERLAY
public String getAddress()
public CompatibilityInfoHolder getCompatibilityInfo()
public String getName()
Note that some displays may be renamed by the user.
public void getSize(Point outSize)
Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decoration elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays.
outSize
- A Point
object to receive the size information.public void getRectSize(Rect outSize)
outSize
- A Rect
object to receive the size information.getSize(Point)
public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize)
outSmallestSize
- Filled in with the smallest width and height
that the application will encounter, in pixels (not dp units). The x
(width) dimension here directly corresponds to
Configuration.smallestScreenWidthDp
, except the value here is in raw
screen pixels rather than dp units. Your application may of course
still get smaller space yet if, for example, a soft keyboard is
being displayed.outLargestSize
- Filled in with the largest width and height
that the application will encounter, in pixels (not dp units). Your
application may of course still get larger space than this if,
for example, screen decorations like the status bar are being hidden.public int getMaximumSizeDimension()
@Deprecated public int getWidth()
getSize(Point)
instead.@Deprecated public int getHeight()
getSize(Point)
instead.public int getRotation()
Surface.ROTATION_0
(no rotation), Surface.ROTATION_90
,
Surface.ROTATION_180
, or
Surface.ROTATION_270
. For
example, if a device has a naturally tall screen, and the user has
turned it on its side to go into a landscape orientation, the value
returned here may be either Surface.ROTATION_90
or Surface.ROTATION_270
depending on
the direction it was turned. The angle is the rotation of the drawn
graphics on the screen, which is the opposite direction of the physical
rotation of the device. For example, if the device is rotated 90
degrees counter-clockwise, to compensate rendering will be rotated by
90 degrees clockwise and thus the returned value here will be
Surface.ROTATION_90
.@Deprecated public int getOrientation()
getRotation()
@Deprecated public int getPixelFormat()
PixelFormat.RGBA_8888
.PixelFormat
.public float getRefreshRate()
public void getMetrics(DisplayMetrics outMetrics)
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decor elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays.
outMetrics
- A DisplayMetrics
object to receive the metrics.public void getRealSize(Point outSize)
The size is adjusted based on the current rotation of the display.
The real size may be smaller than the physical size of the screen when the window manager is emulating a smaller display (using adb shell am display-size).
outSize
- Set to the real size of the display.public void getRealMetrics(DisplayMetrics outMetrics)
The size is adjusted based on the current rotation of the display.
The real size may be smaller than the physical size of the screen when the window manager is emulating a smaller display (using adb shell am display-size).
outMetrics
- A DisplayMetrics
object to receive the metrics.public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
public static String typeToString(int type)