public void onCreate() { activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000)); sivViewer = new ScaledImageView(activity); sivViewer.setScaleType(ScaleType.MATRIX); activity.setContentView(sivViewer); if (pic != null) { sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this); } }
public void onCreate() { activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000)); sivViewer = new ScaledImageView(activity); sivViewer.setScaleType(ScaleType.MATRIX); activity.setContentView(sivViewer); if (pic != null) { sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this); } }
@Override public DefaultWebCreator create() { if (mIsCreated) { return this; } mIsCreated = true; ViewGroup mViewGroup = this.mViewGroup; if (mViewGroup == null) { mViewGroup = this.mFrameLayout = (FrameLayout) createLayout(); mActivity.setContentView(mViewGroup); } else { if (mIndex == -1) { mViewGroup.addView(this.mFrameLayout = (FrameLayout) createLayout(), mLayoutParams); } else { mViewGroup.addView(this.mFrameLayout = (FrameLayout) createLayout(), mIndex, mLayoutParams); } } return this; }
public void onCreate() { super.onCreate(); int screenHeight = ResHelper.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_HEIGHT; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
public void onCreate() { super.onCreate(); int screenHeight = R.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
public void onCreate() { super.onCreate(); int screenHeight = ResHelper.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
public void onCreate() { super.onCreate(); int screenHeight = R.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_HEIGHT; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
@Test public void shouldSetTextAndTextColorWhileInflatingXmlLayout() throws Exception { Activity activity = activityController.get(); activity.setContentView(R.layout.text_views); TextView black = (TextView) activity.findViewById(R.id.black_text_view); assertThat(black.getText().toString()).isEqualTo("Black Text"); assertThat(black.getCurrentTextColor()).isEqualTo(0xff000000); TextView white = (TextView) activity.findViewById(R.id.white_text_view); assertThat(white.getText().toString()).isEqualTo("White Text"); assertThat(white.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white)); TextView grey = (TextView) activity.findViewById(R.id.grey_text_view); assertThat(grey.getText().toString()).isEqualTo("Grey Text"); assertThat(grey.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42)); }
@Before public void setUp() { activity = Robolectric.setupActivity(Activity.class); view = new View(activity); activity.setContentView(view); listener = new TestListener(); }
@Test public void setContentView_shouldReplaceOldContentView() throws Exception { View view1 = new View(application); view1.setId(R.id.burritos); View view2 = new View(application); view2.setId(R.id.button); Activity activity = buildActivity(Activity.class).create().get(); activity.setContentView(view1); assertSame(view1, activity.findViewById(R.id.burritos)); activity.setContentView(view2); assertNull(activity.findViewById(R.id.burritos)); assertSame(view2, activity.findViewById(R.id.button)); }
@Test // unclear what the correct behavior should be here... public void shouldPopulateWindowDecorViewWithMergeLayoutContents() throws Exception { Activity activity = Robolectric.buildActivity(Activity.class).create().get(); activity.setContentView(R.layout.toplevel_merge); View contentView = activity.findViewById(android.R.id.content); assertThat(((ViewGroup) contentView).getChildCount()).isEqualTo(2); }
@Test public void shouldSetHintAndHintColorWhileInflatingXmlLayout() throws Exception { Activity activity = activityController.get(); activity.setContentView(R.layout.text_views_hints); TextView black = (TextView) activity.findViewById(R.id.black_text_view_hint); assertThat(black.getHint().toString()).isEqualTo("Black Hint"); assertThat(black.getCurrentHintTextColor()).isEqualTo(0xff000000); TextView white = (TextView) activity.findViewById(R.id.white_text_view_hint); assertThat(white.getHint().toString()).isEqualTo("White Hint"); assertThat(white.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white)); TextView grey = (TextView) activity.findViewById(R.id.grey_text_view_hint); assertThat(grey.getHint().toString()).isEqualTo("Grey Hint"); assertThat(grey.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42)); }
@Test @Config(qualifiers = "w0dp") public void testSetContentViewByItemResource() throws Exception { Activity activity = buildActivity(Activity.class).create().get(); activity.setContentView(R.layout.main_layout); TextView tv1 = activity.findViewById(R.id.hello); TextView tv2 = activity.findViewById(R.id.world); assertNotNull(tv1); assertNull(tv2); }
@Test @Config(qualifiers = "w820dp") public void testSetContentViewByItemResourceWithW820dp() throws Exception { Activity activity = buildActivity(Activity.class).create().get(); activity.setContentView(R.layout.main_layout); TextView tv1 = activity.findViewById(R.id.hello); TextView tv2 = activity.findViewById(R.id.world); assertNotNull(tv1); assertNotNull(tv2); }
@Test public void shouldFindContentViewContainerWithChild() throws Exception { Activity activity = buildActivity(Activity.class).create().get(); View contentView = new View(activity); activity.setContentView(contentView); FrameLayout contentViewContainer = (FrameLayout) activity.findViewById(android.R.id.content); assertThat(contentViewContainer.getChildAt(0)).isSameAs(contentView); }
@Test public void usesDefaultGlobalVisibleRect() { final ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class); final Activity activity = activityController.get(); activity.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); activityController.setup(); Rect globalVisibleRect = new Rect(); assertThat(view.getGlobalVisibleRect(globalVisibleRect)) .isTrue(); assertThat(globalVisibleRect) .isEqualTo(new Rect(0, 25, DeviceConfig.DEFAULT_SCREEN_SIZE.width, DeviceConfig.DEFAULT_SCREEN_SIZE.height)); }
@Before public void setUp() { sdkVersion = Build.VERSION.SDK_INT; MockitoAnnotations.initMocks(this); activity = Robolectric.buildActivity(Activity.class).create().start().postCreate(null).resume(); view = new View(activity.get()); target = new TestViewTarget(view); attachStateTarget = new AttachStateTarget(view); LinearLayout linearLayout = new LinearLayout(activity.get()); View expandView = new View(activity.get()); LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, /*height=*/ 0); linearLayoutParams.weight = 1f; expandView.setLayoutParams(linearLayoutParams); linearLayout.addView(expandView); parent = new FrameLayout(activity.get()); parent.addView(view); linearLayout.addView(parent); activity.get().setContentView(linearLayout); }
@Test public void testInvalidOnClickAttribute() throws Exception { Activity activity = buildActivity(Activity.class).create().get(); activity.setContentView(R.layout.with_invalid_onclick); Button button = activity.findViewById(R.id.invalid_onclick_button); IllegalStateException exception = null; try { button.performClick(); } catch (IllegalStateException e) { exception = e; } assertNotNull(exception); assertThat(exception.getMessage()) .named("The error message should contain the id name of the faulty button") .contains("invalid_onclick_button"); }
@Test public void shouldRetrieveTheCurrentViewFromViewId() { Activity activity = Robolectric.buildActivity(Activity.class).create().get(); activity.setContentView(org.robolectric.R.layout.main); TabHost tabHost = new TabHost(activity); TabHost.TabSpec foo = tabHost.newTabSpec("Foo") .setContent(org.robolectric.R.id.title); tabHost.addTab(foo); tabHost.setCurrentTabByTag("Foo"); TextView textView = (TextView) tabHost.getCurrentView(); assertThat(textView.getText().toString()).isEqualTo("Main Layout"); }
@Before public void setUp() throws Exception { activityController = buildActivity(Activity.class); Activity activity = activityController.create().get(); textView = new TextView(activity); activity.setContentView(textView); activityController.start().resume().visible(); }