Package org.robolectric.shadows
Class ShadowDisplayManager
java.lang.Object
org.robolectric.shadows.ShadowDisplayManager
@Implements(value=android.hardware.display.DisplayManager.class,
looseSignatures=true)
public class ShadowDisplayManager
extends Object
For tests, display properties may be changed and devices may be added or removed
programmatically.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void__constructor__(Context context) static intaddDisplay(String qualifiersStr) Adds a simulated display and drain the main looper queue to ensure all the callbacks are processed.static intaddDisplay(String qualifiersStr, String displayName) Adds a simulated display and drain the main looper queue to ensure all the callbacks are processed.static voidchangeDisplay(int displayId, String qualifiersStr) Changes properties of a simulated display.static voidconfigureDefaultDisplay(Configuration configuration, DisplayMetrics displayMetrics) internal onlyfloatReturns the current display saturation level set viaDisplayManager.setSaturationLevel(float).static voidremoveDisplay(int displayId) Removes a simulated display and idles the main looper to ensure all listeners are notified.static voidreset()protected voidsetBrightnessConfiguration(Object config) protected voidsetBrightnessConfigurationForUser(Object config, Object userId, Object packageName) static voidsetBrightnessEvents(List<BrightnessChangeEvent> events) Set the slider events the system has seen.static voidSet the default brightness configuration for this device.static voidsetNaturallyPortrait(int displayId, boolean isNaturallyPortrait) Changes the display to be naturally portrait or landscape.voidsetSaturationLevel(float level) Sets the current display saturation level.static voidsetSupportedModes(int displayId, Display.Mode... supportedModes) Sets supported modes to the specified display with IDdisplayId.
-
Constructor Details
-
ShadowDisplayManager
public ShadowDisplayManager()
-
-
Method Details
-
reset
-
__constructor__
-
addDisplay
Adds a simulated display and drain the main looper queue to ensure all the callbacks are processed.- Parameters:
qualifiersStr- theQualifiersstring representing characteristics of the new display.- Returns:
- the new display's ID
-
addDisplay
Adds a simulated display and drain the main looper queue to ensure all the callbacks are processed.- Parameters:
qualifiersStr- theQualifiersstring representing characteristics of the new display.displayName- the display name to use while creating the display- Returns:
- the new display's ID
-
configureDefaultDisplay
public static void configureDefaultDisplay(Configuration configuration, DisplayMetrics displayMetrics) internal only -
changeDisplay
Changes properties of a simulated display. If starts with a plus ('+') sign, the display's previous configuration is modified with the given qualifiers; otherwise defaults are applied as described here.Idles the main looper to ensure all listeners are notified.
- Parameters:
displayId- the display id to changequalifiersStr- theQualifiersstring representing characteristics of the new display
-
setNaturallyPortrait
public static void setNaturallyPortrait(int displayId, boolean isNaturallyPortrait) Changes the display to be naturally portrait or landscape. This will ensure that the rotation is configured consistently with orientation when the orientation is configured bychangeDisplay(int, java.lang.String), e.g. if the display is naturally portrait and the orientation is configured as landscape the rotation will be set toSurface.ROTATION_90. -
setSupportedModes
Sets supported modes to the specified display with IDdisplayId.Idles the main looper to ensure all listeners are notified.
- Parameters:
displayId- the display id to changesupportedModes- the display's supported modes
-
removeDisplay
public static void removeDisplay(int displayId) Removes a simulated display and idles the main looper to ensure all listeners are notified.- Parameters:
displayId- the display id to remove
-
getSaturationLevel
public float getSaturationLevel()Returns the current display saturation level set viaDisplayManager.setSaturationLevel(float). -
setSaturationLevel
Sets the current display saturation level.This is a workaround for tests which cannot use the relevant hidden
SystemApi,DisplayManager.setSaturationLevel(float). -
setBrightnessConfiguration
-
setBrightnessConfigurationForUser
@Implementation(minSdk=28) @HiddenApi protected void setBrightnessConfigurationForUser(Object config, Object userId, Object packageName) -
setDefaultBrightnessConfiguration
Set the default brightness configuration for this device. -
setBrightnessEvents
Set the slider events the system has seen.
-