private void setDisplayDimens(Integer width, Integer height) { WindowManager windowManager = (WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE); ShadowDisplay shadowDisplay = Shadows.shadowOf(Preconditions.checkNotNull(windowManager).getDefaultDisplay()); if (width != null) { shadowDisplay.setWidth(width); } if (height != null) { shadowDisplay.setHeight(height); } }
@Test public void shouldUseSetDisplayForContexts() throws Exception { assertThat(new Activity().getResources().getDisplayMetrics().widthPixels).isEqualTo(480); assertThat(new Activity().getResources().getDisplayMetrics().heightPixels).isEqualTo(800); Display display = Robolectric.newInstanceOf(Display.class); ShadowDisplay shadowDisplay = shadowOf(display); shadowDisplay.setWidth(100); shadowDisplay.setHeight(200); Robolectric.setDefaultDisplay(display); assertThat(new Activity().getResources().getDisplayMetrics().widthPixels).isEqualTo(100); assertThat(new Activity().getResources().getDisplayMetrics().heightPixels).isEqualTo(200); }
public static ShadowDisplay shadowOf(Display instance) { return (ShadowDisplay) shadowOf_(instance); }