/** * Changes the horizontal DPI for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setXdpi(float xdpi) { if (isJB()) { this.xdpi = xdpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.physicalXDpi = xdpi); } }
/** * Changes the vertical DPI for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setYdpi(float ydpi) { if (isJB()) { this.ydpi = ydpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.physicalYDpi = ydpi); } }
/** * Changes the density for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setDensityDpi(int densityDpi) { if (isJB()) { this.densityDpi = densityDpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalDensityDpi = densityDpi); } }
/** * Changes the name for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setName(String name) { if (isJB()) { this.name = name; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.name = name); } }
/** * Changes the width available to the application for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param width the new width in pixels */ public void setWidth(int width) { if (isJB()) { this.width = width; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.appWidth = width); } }
/** * Changes the height available to the application for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param height new height in pixels */ public void setHeight(int height) { if (isJB()) { this.height = height; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.appHeight = height); } }
/** * Changes the simulated state for this display, such as whether it is on or off * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param state the new state: one of {@link Display#STATE_OFF}, {@link Display#STATE_ON}, * {@link Display#STATE_DOZE}, {@link Display#STATE_DOZE_SUSPEND}, or * {@link Display#STATE_UNKNOWN}. */ public void setState(int state) { if (!isJB()) { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.state = state); } }
/** * If {@link #setScaledDensity(float)} has been called, {@link DisplayMetrics#scaledDensity} will * be modified to reflect the value specified. Note that this is not a realistic state. * * @deprecated This behavior is deprecated and will be removed in Robolectric 3.7. */ @Deprecated @Implementation protected void getMetrics(DisplayMetrics outMetrics) { if (isJB()) { outMetrics.density = densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; outMetrics.densityDpi = densityDpi; outMetrics.scaledDensity = scaledDensity; outMetrics.widthPixels = width; outMetrics.heightPixels = height; outMetrics.xdpi = xdpi; outMetrics.ydpi = ydpi; } else { directlyOn(realObject, Display.class).getMetrics(outMetrics); if (scaledDensity != null) { outMetrics.scaledDensity = scaledDensity; } } }
/** * Changes the simulated physical width for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param width the new width in pixels */ public void setRealWidth(int width) { if (isJB()) { this.realWidth = width; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalWidth = width); } }
/** * Changes the simulated physical height for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param height the new height in pixels */ public void setRealHeight(int height) { if (isJB()) { this.realHeight = height; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalHeight = height); } }
/** * Changes the rotation for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param rotation one of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90}, * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270} */ public void setRotation(int rotation) { if (isJB()) { this.rotation = rotation; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.rotation = rotation); } }
/** * If {@link #setScaledDensity(float)} has been called, {@link DisplayMetrics#scaledDensity} will * be modified to reflect the value specified. Note that this is not a realistic state. * * @deprecated This behavior is deprecated and will be removed in Robolectric 3.7. */ @Deprecated @Implementation protected void getRealMetrics(DisplayMetrics outMetrics) { if (isJB()) { getMetrics(outMetrics); outMetrics.widthPixels = realWidth; outMetrics.heightPixels = realHeight; } else { directlyOn(realObject, Display.class).getRealMetrics(outMetrics); if (scaledDensity != null) { outMetrics.scaledDensity = scaledDensity; } } }
/** * Changes the flags for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setFlags(int flags) { reflector(_Display_.class, realObject).setFlags(flags); if (!isJB()) { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.flags = flags); } }
/** * Changes the density for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setDensityDpi(int densityDpi) { if (isJB()) { this.densityDpi = densityDpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalDensityDpi = densityDpi); } }
/** * Changes the horizontal DPI for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setXdpi(float xdpi) { if (isJB()) { this.xdpi = xdpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.physicalXDpi = xdpi); } }
/** * Changes the vertical DPI for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setYdpi(float ydpi) { if (isJB()) { this.ydpi = ydpi; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.physicalYDpi = ydpi); } }
/** * Changes the name for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setName(String name) { if (isJB()) { this.name = name; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.name = name); } }
/** * Changes the simulated physical width for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param width the new width in pixels */ public void setRealWidth(int width) { if (isJB()) { this.realWidth = width; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalWidth = width); } }
/** * Changes the simulated physical height for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. * * @param height the new height in pixels */ public void setRealHeight(int height) { if (isJB()) { this.realHeight = height; } else { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.logicalHeight = height); } }
/** * Changes the flags for this display. * * Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be * notified of the change. */ public void setFlags(int flags) { ReflectionHelpers.setField(realObject, "mFlags", flags); if (!isJB()) { ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.flags = flags); } }