Class ShadowDisplay

java.lang.Object
org.robolectric.shadows.ShadowDisplay

@Implements(android.view.Display.class) public class ShadowDisplay extends Object
It is possible to override some display properties using setters on ShadowDisplay.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Display
    Returns the default display.
    protected void
    Deprecated.
    This behavior is deprecated and will be removed in Robolectric 4.13.
    protected void
    Deprecated.
    This behavior is deprecated and will be removed in Robolectric 4.13.
    protected float
    Deprecated.
    This behavior is deprecated and will be removed in Robolectric 3.7.
    void
    setDensity(float density)
    Changes the density for this display.
    void
    setDensityDpi(int densityDpi)
    Changes the density for this display.
    void
    setDisplayCutout(Object displayCutout)
    Changes the display cutout for this display.
    void
    setDisplayHdrCapabilities(int displayId, float maxLuminance, float maxAverageLuminance, float minLuminance, int... supportedHdrTypes)
    Set HDR capabilities to the display sourced with displayId.
    void
    setFlags(int flags)
    Changes the flags for this display.
    void
    setHdrSdrRatio(float hdrSdrRatio)
    Sets current hdr/sdr ratio expressed as the ratio of targetHdrPeakBrightnessInNits / targetSdrWhitePointInNits.
    void
    setHeight(int height)
    Changes the height available to the application for this display.
    void
    Changes the name for this display.
    void
    setRealHeight(int height)
    Changes the simulated physical height for this display.
    void
    setRealWidth(int width)
    Changes the simulated physical width for this display.
    void
    setRefreshRate(float refreshRate)
    Changes the refresh rate for this display.
    void
    setRotation(int rotation)
    Changes the rotation for this display.
    void
    setScaledDensity(float scaledDensity)
    Deprecated.
    This method is deprecated and will be removed in Robolectric 4.13.
    void
    setState(int state)
    Changes the simulated state for this display, such as whether it is on or off
    void
    setWidth(int width)
    Changes the width available to the application for this display.
    void
    setXdpi(float xdpi)
    Changes the horizontal DPI for this display.
    void
    setYdpi(float ydpi)
    Changes the vertical DPI for this display.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShadowDisplay

      public ShadowDisplay()
  • Method Details

    • getDefaultDisplay

      public static Display getDefaultDisplay()
      Returns the default display.
      Returns:
      the default display
    • getMetrics

      @Deprecated @Implementation protected void getMetrics(DisplayMetrics outMetrics)
      Deprecated.
      This behavior is deprecated and will be removed in Robolectric 4.13.
      If setScaledDensity(float) has been called, DisplayMetrics.scaledDensity will be modified to reflect the value specified. Note that this is not a realistic state.
    • getRealMetrics

      @Deprecated @Implementation protected void getRealMetrics(DisplayMetrics outMetrics)
      Deprecated.
      This behavior is deprecated and will be removed in Robolectric 4.13.
      If setScaledDensity(float) has been called, DisplayMetrics.scaledDensity will be modified to reflect the value specified. Note that this is not a realistic state.
    • setScaledDensity

      @Deprecated public void setScaledDensity(float scaledDensity)
      Deprecated.
      This method is deprecated and will be removed in Robolectric 4.13.
      Changes the scaled density for this display.
    • getRefreshRate

      @Deprecated @Implementation protected float getRefreshRate()
      Deprecated.
      This behavior is deprecated and will be removed in Robolectric 3.7.
      If setRefreshRate(float) has been called, this method will return the specified value.
    • setDensity

      public void setDensity(float density)
      Changes the density for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setDensityDpi

      public void setDensityDpi(int densityDpi)
      Changes the density for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setXdpi

      public void setXdpi(float xdpi)
      Changes the horizontal DPI for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setYdpi

      public void setYdpi(float ydpi)
      Changes the vertical DPI for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setName

      public void setName(String name)
      Changes the name for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setFlags

      public void setFlags(int flags)
      Changes the flags for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setWidth

      public void setWidth(int width)
      Changes the width available to the application for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      width - the new width in pixels
    • setHeight

      public void setHeight(int height)
      Changes the height available to the application for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      height - new height in pixels
    • setRealWidth

      public void setRealWidth(int width)
      Changes the simulated physical width for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      width - the new width in pixels
    • setRealHeight

      public void setRealHeight(int height)
      Changes the simulated physical height for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      height - the new height in pixels
    • setRefreshRate

      public void setRefreshRate(float refreshRate)
      Changes the refresh rate for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

    • setRotation

      public void setRotation(int rotation)
      Changes the rotation for this display.

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      rotation - one of Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270
    • setState

      public void setState(int state)
      Changes the simulated state for this display, such as whether it is on or off

      Any registered DisplayManager.DisplayListeners will be notified of the change.

      Parameters:
      state - the new state: one of Display.STATE_OFF, Display.STATE_ON, Display.STATE_DOZE, Display.STATE_DOZE_SUSPEND, or Display.STATE_UNKNOWN.
    • setDisplayHdrCapabilities

      public void setDisplayHdrCapabilities(int displayId, float maxLuminance, float maxAverageLuminance, float minLuminance, int... supportedHdrTypes)
      Set HDR capabilities to the display sourced with displayId. see Display.HdrCapabilities for supportedHdrTypes.
      Throws:
      UnsupportedOperationException - if the method is called below Android vesrsion N.
    • setHdrSdrRatio

      public void setHdrSdrRatio(float hdrSdrRatio)
      Sets current hdr/sdr ratio expressed as the ratio of targetHdrPeakBrightnessInNits / targetSdrWhitePointInNits. This will have the intended side effect of making Display.isHdrSdrRatioAvailable() equal to true if set to any value other than Float.NaN.
      Throws:
      UnsupportedOperationException - if the method is called below Android version U.
    • setDisplayCutout

      public void setDisplayCutout(Object displayCutout)
      Changes the display cutout for this display.
      Throws:
      UnsupportedOperationException - if the method is called below Android version Q.