public List<View> getViews() { return ImmutableList.copyOf(views.get(realObject.getDefaultDisplay().getDisplayId())); }
@Override void collect(@NonNull ReportField reportField, @NonNull Context context, @NonNull CoreConfiguration config, @NonNull ReportBuilder reportBuilder, @NonNull CrashReportData target) { final JSONObject result = new JSONObject(); for (Display display : getDisplays(context)) { try { result.put(String.valueOf(display.getDisplayId()), collectDisplayData(display)); } catch (JSONException e) { ACRA.log.w(ACRA.LOG_TAG, "Failed to collect data for display " + display.getDisplayId(), e); } } target.put(ReportField.DISPLAY, result); }
/** * If {@link #setDisplayId(int)} has been called, this method will return the specified value. * * @deprecated This behavior is deprecated and will be removed in Robolectric 3.7. */ @Deprecated @Implementation protected int getDisplayId() { return displayId == null ? directlyOn(realObject, Display.class).getDisplayId() : displayId; }
public DisplayAssert hasDisplayId(int id) { isNotNull(); int actualId = actual.getDisplayId(); assertThat(actualId) // .overridingErrorMessage("Expected ID <%s> but was <%s>", id, actualId) // .isEqualTo(id); return this; }
/** * 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 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 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 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 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 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); } }
@Implementation public void removeView(View view) { views.remove(realObject.getDefaultDisplay().getDisplayId(), view); directlyOn(realObject, WindowManagerImpl.class, "removeView", ClassParameter.from(View.class, view)); }
@Implementation protected void removeViewImmediate(View view) { views.remove(realObject.getDefaultDisplay().getDisplayId(), view); directlyOn( realObject, WindowManagerImpl.class, "removeViewImmediate", ClassParameter.from(View.class, view)); }
@Implementation public void addView(View view, android.view.ViewGroup.LayoutParams layoutParams) { views.put(realObject.getDefaultDisplay().getDisplayId(), view); // views.add(view); directlyOn( realObject, WindowManagerImpl.class, "addView", ClassParameter.from(View.class, view), ClassParameter.from(ViewGroup.LayoutParams.class, layoutParams)); }
/** * 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 addDisplay() throws Exception { int displayId = ShadowDisplayManager.addDisplay("w100dp-h200dp"); assertThat(displayId).isGreaterThan(0); DisplayInfo di = getGlobal().getDisplayInfo(displayId); assertThat(di.appWidth).isEqualTo(100); assertThat(di.appHeight).isEqualTo(200); Display display = instance.getDisplay(displayId); assertThat(display.getDisplayId()).isEqualTo(displayId); }