/** * 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 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); } }
/** * 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 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); } }
/** * 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); } }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void withQualifiers_changeDisplay_shouldUpdateSmallestAndLargestNominalWidthAndHeight() throws Exception { Point smallest = new Point(); Point largest = new Point(); Display display = ShadowDisplay.getDefaultDisplay(); display.getCurrentSizeRange(smallest, largest); assertThat(smallest).isEqualTo(new Point(320, 320)); assertThat(largest).isEqualTo(new Point(470, 470)); ShadowDisplayManager.changeDisplay(display.getDisplayId(), "w310dp-h460dp"); display.getCurrentSizeRange(smallest, largest); assertThat(smallest).isEqualTo(new Point(310, 310)); assertThat(largest).isEqualTo(new Point(460, 460)); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void forNonexistentDisplay_changeDisplay_shouldThrow() throws Exception { try { ShadowDisplayManager.changeDisplay(3, ""); fail("Expected Exception thrown"); } catch (IllegalStateException e) { assertThat(e).hasMessageThat().contains("no display 3"); } }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void changeAndRemoveDisplay_shouldNotifyListeners() throws Exception { List<String> events = new ArrayList<>(); instance.registerDisplayListener(new MyDisplayListener(events), null); int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); ShadowDisplayManager.changeDisplay(displayId, "w300dp-h400dp"); Display display = getGlobal().getRealDisplay(displayId); assertThat(display.getWidth()).isEqualTo(300); assertThat(display.getHeight()).isEqualTo(400); assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_0); ShadowDisplayManager.removeDisplay(displayId); assertThat(events).containsExactly( "Added " + displayId, "Changed " + displayId, "Removed " + displayId); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void changeDisplay_shouldAllowPartialChanges() throws Exception { List<String> events = new ArrayList<>(); instance.registerDisplayListener(new MyDisplayListener(events), null); int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); ShadowDisplayManager.changeDisplay(displayId, "+h201dp-land"); Display display = getGlobal().getRealDisplay(displayId); assertThat(display.getWidth()).isEqualTo(201); assertThat(display.getHeight()).isEqualTo(100); assertThat(display.getOrientation()).isEqualTo(Surface.ROTATION_90); assertThat(events).containsExactly( "Added " + displayId, "Changed " + displayId); }
/** * 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 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); } }