Java 类org.robolectric.shadows.ShadowDisplay 实例源码

项目:GitHub    文件:ViewTargetTest.java   
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);
  }
}
项目:FullRobolectricTestSample    文件:RobolectricTest.java   
@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);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowDisplay shadowOf(Display instance) {
  return (ShadowDisplay) shadowOf_(instance);
}