1 package org.robolectric.shadows.testing; 2 3 import android.app.Activity; 4 import android.app.LocalActivityManager; 5 import android.content.Context; 6 import android.content.Intent; 7 import android.util.AttributeSet; 8 import android.view.View; 9 import android.view.ViewGroup; 10 import android.view.Window; 11 import android.widget.LinearLayout; 12 import org.robolectric.R; 13 14 @SuppressWarnings("UnusedDeclaration") 15 // Used in lam_outer.xml 16 public class LocalActivityManagerContainer extends LinearLayout { LocalActivityManagerContainer(Context context)17 public LocalActivityManagerContainer(Context context) { 18 super(context); 19 init(); 20 } 21 LocalActivityManagerContainer(Context context, AttributeSet attrs)22 public LocalActivityManagerContainer(Context context, AttributeSet attrs) { 23 super(context, attrs); 24 init(); 25 } 26 LocalActivityManagerContainer(Context context, AttributeSet attrs, int defStyle)27 public LocalActivityManagerContainer(Context context, AttributeSet attrs, int defStyle) { 28 super(context, attrs, defStyle); 29 init(); 30 } 31 init()32 private void init() { 33 LocalActivityManager lam = new LocalActivityManager((Activity) getContext(), true); 34 lam.dispatchCreate(null); 35 final Window window = lam.startActivity("foo", new Intent(getContext(), InnerActivity.class)); 36 // Add the decorView's child to this LinearLayout's children. 37 final View innerContents = window.getDecorView().findViewById(R.id.lam_inner_contents); 38 ((ViewGroup) innerContents.getParent()).removeView(innerContents); 39 addView(innerContents); 40 } 41 42 } 43