Class ShadowDisplayManager

java.lang.Object
org.robolectric.shadows.ShadowDisplayManager

For tests, display properties may be changed and devices may be added or removed programmatically.
  • Constructor Details

    • ShadowDisplayManager

      public ShadowDisplayManager()
  • Method Details

    • reset

      @Resetter public static void reset()
    • __constructor__

      @Implementation protected void __constructor__(Context context)
    • addDisplay

      public static int addDisplay(String qualifiersStr)
      Adds a simulated display and drain the main looper queue to ensure all the callbacks are processed.
      Parameters:
      qualifiersStr - the Qualifiers string representing characteristics of the new display.
      Returns:
      the new display's ID
    • configureDefaultDisplay

      public static void configureDefaultDisplay(Configuration configuration, DisplayMetrics displayMetrics)
      internal only
    • changeDisplay

      public static void changeDisplay(int displayId, String qualifiersStr)
      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 change
      qualifiersStr - the Qualifiers string 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 by changeDisplay(int, java.lang.String), e.g. if the display is naturally portrait and the orientation is configured as landscape the rotation will be set to Surface.ROTATION_90.
    • setSupportedModes

      public static void setSupportedModes(int displayId, Display.Mode... supportedModes)
      Sets supported modes to the specified display with ID displayId.

      Idles the main looper to ensure all listeners are notified.

      Parameters:
      displayId - the display id to change
      supportedModes - 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 via DisplayManager.setSaturationLevel(float).
    • setSaturationLevel

      @Implementation(minSdk=28) public void setSaturationLevel(float level)
      Sets the current display saturation level.

      This is a workaround for tests which cannot use the relevant hidden SystemApi, DisplayManager.setSaturationLevel(float).

    • setBrightnessConfiguration

      @Implementation(minSdk=28) @HiddenApi protected void setBrightnessConfiguration(Object config)
    • setBrightnessConfigurationForUser

      @Implementation(minSdk=28) @HiddenApi protected void setBrightnessConfigurationForUser(Object config, Object userId, Object packageName)
    • setDefaultBrightnessConfiguration

      public static void setDefaultBrightnessConfiguration(Object config)
      Set the default brightness configuration for this device.
    • setBrightnessEvents

      public static void setBrightnessEvents(List<BrightnessChangeEvent> events)
      Set the slider events the system has seen.