Java Code Examples for android.app.Activity#setContentView()

The following examples show how to use android.app.Activity#setContentView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnackbarBuilderTest.java    From SnackbarBuilder with Apache License 2.0 6 votes vote down vote up
@Test
public void givenActivity_whenCreated_thenParentViewFoundUsingParentViewId() {
  Activity activity = Robolectric.setupActivity(Activity.class);
  activity.setTheme(R.style.TestSnackbarBuilder_CustomTheme);
  LinearLayout layout = new LinearLayout(activity);
  layout.setId(R.id.snackbarbuilder_icon);
  activity.setContentView(layout);

  SnackbarBuilder builder = new SnackbarBuilder(activity);

  assertThat(builder.parentViewId).isEqualTo(R.id.snackbarbuilder_icon);
  assertThat(builder.parentView).isEqualTo(layout);
  assertThat(builder.context).isEqualTo(activity);
  assertThat(builder.actionTextColor).isEqualTo(0xFF454545);
  assertThat(builder.messageTextColor).isEqualTo(0xFF987654);
}
 
Example 2
Source File: BoletoTextWatcherTest.java    From canarinho with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {

    final ActivityController<MainActivity> activityController = buildActivity(MainActivity.class);
    final Activity activity = activityController.create().get();

    final TextInputLayout textInputLayout = new TextInputLayout(activity);
    textInputLayout.addView(editText = new EditText(activity));
    activityController.start().resume().visible();

    final Watchers.SampleEventoDeValidacao sampleEventoDeValidacao =
            new Watchers.SampleEventoDeValidacao(textInputLayout);

    editText.addTextChangedListener(watcher = new BoletoBancarioTextWatcher(sampleEventoDeValidacao));

    activity.setContentView(textInputLayout);
}
 
Example 3
Source File: ButtonPresenterTest.java    From react-native-navigation with MIT License 6 votes vote down vote up
@Override
public void beforeEach() {
    Activity activity = newActivity();
    titleBar = new TitleBar(activity);
    activity.setContentView(titleBar);
    Button button = createButton();

    uut = new ButtonPresenter(button, new IconResolverFake(activity));
    buttonController = new TitleBarButtonController(
            activity,
            uut,
            button,
            mock(TitleBarButtonCreator.class),
            mock(TitleBarButtonController.OnClickListener.class)
    );
}
 
Example 4
Source File: TranslucentHelper.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public void setContentView(Activity activity, int layoutResID) {
    if (VALID) {
        mTranslucentLayout = new TranslucentLayout(activity);
        mTranslucentLayout.setShowStatusBar(mShowStatusBar);
        mTranslucentLayout.setShowNavigationBar(mShowNavigationBar);
        mTranslucentLayout.setStatusBarColor(mStatusBarColor);
        mTranslucentLayout.setNavigationBarColor(mNavigationBarColor);
        activity.getLayoutInflater().inflate(layoutResID, mTranslucentLayout);
        activity.setContentView(mTranslucentLayout);
    } else {
        if (activity instanceof SuperActivity) {
            ((SuperActivity) activity).superSetContentView(layoutResID);
        } else {
            throw new IllegalStateException("The Activity must implements SuperActivity");
        }
    }
}
 
Example 5
Source File: ModalPresenterTest.java    From react-native-navigation with MIT License 6 votes vote down vote up
@Override
public void beforeEach() {
    Activity activity = newActivity();
    ChildControllersRegistry childRegistry = new ChildControllersRegistry();

    root = spy(new SimpleViewController(activity, childRegistry, "root", new Options()));
    FrameLayout contentLayout = new FrameLayout(activity);
    FrameLayout rootLayout = new FrameLayout(activity);
    rootLayout.addView(root.getView());
    modalsLayout = new CoordinatorLayout(activity);
    contentLayout.addView(rootLayout);
    contentLayout.addView(modalsLayout);
    activity.setContentView(contentLayout);

    animator = spy(new ModalAnimator(activity));
    uut = new ModalPresenter(animator);
    uut.setModalsLayout(modalsLayout);
    uut.setRootLayout(rootLayout);
    modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
    modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
}
 
Example 6
Source File: ClockHandViewTouchTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Before
public void createClockFace() {
  ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_MaterialComponents_Light);
  Activity activity = Robolectric.buildActivity(Activity.class).setup().start().get();
  clockHandView = new ClockHandView(activity);
  clockHandView.setCircleRadius(100);
  LinearLayout container = new LinearLayout(activity);
  container.setPadding(50, 50, 50, 50);
  container.setOrientation(LinearLayout.VERTICAL);
  container.setId(android.R.id.content);
  container.addView(clockHandView, new LayoutParams(300, 300));

  activity.setContentView(container);
}
 
Example 7
Source File: UIHelper.java    From coolreader with MIT License 5 votes vote down vote up
/**
 * Set up the application theme based on Preferences:Constants.PREF_INVERT_COLOR
 * 
 * @param activity
 *            target activity
 * @param layoutId
 *            layout to use
 */
public static void SetTheme(Activity activity, Integer layoutId) {
	CheckScreenRotation(activity);
	if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(Constants.PREF_INVERT_COLOR, false)) {
		activity.setTheme(R.style.AppTheme2);
	} else {
		activity.setTheme(R.style.AppTheme);
	}
	if (layoutId != null) {
		activity.setContentView(layoutId);
	}
}
 
Example 8
Source File: ValorMonetarioWatcherTest.java    From canarinho with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    final ActivityController<Activity> activityController = buildActivity(Activity.class);
    final Activity activity = activityController.create().get();
    activityController.start().resume().visible();

    TextInputLayout textInputLayout;
    activity.setContentView(textInputLayout = new TextInputLayout(activity));
    textInputLayout.addView(editText = new EditText(activity));
    editText.setText("0,00");
}
 
Example 9
Source File: LayoutUtil.java    From CommonAdapter with Apache License 2.0 5 votes vote down vote up
public static void setContentView(Activity activity,View view) {
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(params);
    activity.setContentView(view);
}
 
Example 10
Source File: BehaviorTest.java    From simple-view-behavior with MIT License 5 votes vote down vote up
@Before
public void setup() {
    Activity activity = Robolectric.setupActivity(Activity.class);
    activity.setTheme(R.style.Theme_AppCompat);
    coordinatorLayout = new CoordinatorLayout(activity);
    activity.setContentView(coordinatorLayout);
    firstView = new View(activity);
    secondView = new TestPercentageChildView(activity);

    CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200);
    coordinatorLayout.addView(firstView, params);
    coordinatorLayout.addView(secondView, params);
}
 
Example 11
Source File: IRecoveryCallback.java    From Neptune with Apache License 2.0 5 votes vote down vote up
@Override
public void onSetContentView(Activity activity, String pkgName, String className) {
    TextView textView = new TextView(activity);
    textView.setText(R.string.under_recovery);
    FrameLayout frameLayout = new FrameLayout(activity);
    LayoutParams lp = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER);
    frameLayout.addView(textView, lp);
    activity.setContentView(frameLayout);
}
 
Example 12
Source File: MaterialTapTargetPromptUnitTest.java    From MaterialTapTargetPrompt with Apache License 2.0 5 votes vote down vote up
private MaterialTapTargetPrompt.Builder createBuilder(final int screenWidth,
                                                      final int screenHeight)
{
    final Activity activity = spy(Robolectric.buildActivity(Activity.class).create().get());
    final FrameLayout layout = spy(new FrameLayout(activity));
    final ResourceFinder resourceFinder = spy(new ActivityResourceFinder(activity));
    activity.setContentView(layout);
    setViewBounds(layout, screenWidth, screenHeight);
    final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(
            resourceFinder, 0);
    builder.setClipToView(null);
    return builder;
}
 
Example 13
Source File: OverlayManagerTest.java    From react-native-navigation with MIT License 5 votes vote down vote up
@Override
public void beforeEach() {
    Activity activity = newActivity();
    contentLayout = new FrameLayout(activity);
    contentLayout.layout(0, 0, 1000, 1000);
    activity.setContentView(contentLayout);
    overlayContainer = new FrameLayout(activity);
    contentLayout.addView(overlayContainer);

    ChildControllersRegistry childRegistry = new ChildControllersRegistry();
    overlay1 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_1, new Options()));
    overlay2 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_2, new Options()));
    uut = new OverlayManager();
}
 
Example 14
Source File: PageStateLayout.java    From MaterialPageStateLayout with MIT License 5 votes vote down vote up
/**
 * Load the container and succeedView defined by user
 * Display
 *
 * @param activity
 * @param succeedView
 */
public void load(@NonNull Activity activity, @NonNull View succeedView) {
    if (null != mSucceedView) {
        removeView(mSucceedView);
    }
    mSucceedView = succeedView;
    addView(mSucceedView, 0);
    activity.setContentView(this);
}
 
Example 15
Source File: MainUIUtil.java    From MainActivityUIUtil with Apache License 2.0 5 votes vote down vote up
private MainUIUtil(Activity activity){
    this.activity = activity;
    activity. setContentView(R.layout.activity_main2);
    viewPager = (ViewPager) activity.findViewById(R.id.vp_container);
    bottomTabLayout = (PagerBottomTabLayout) activity.findViewById(R.id.tab);


}
 
Example 16
Source File: MainActivityView.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private MainActivityView(Activity activity, MainViewCallBack mainViewCallBack) {
    this.mainViewCallBack = mainViewCallBack;
    activityWeakReference = new WeakReference<>(activity);
    activity.setContentView(R.layout.activity_main);
    initView(activity);
    picList = new ArrayList<>();
    refreshGridLayout();
}
 
Example 17
Source File: MainActivityView.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private MainActivityView(Activity activity, MainViewCallBack mainViewCallBack) {
    this.mainViewCallBack = mainViewCallBack;
    activityWeakReference = new WeakReference<>(activity);
    activity.setContentView(R.layout.activity_main);
    initView(activity);
    picList = new ArrayList<>();
    refreshGridLayout();
}
 
Example 18
Source File: ViewRouter.java    From android-router with MIT License 4 votes vote down vote up
public ViewRouter(Activity a) {
	CACHE.put(a, new SoftReference<>(this));
	mParent = new FrameLayout(a);
	a.setContentView(mParent);
}
 
Example 19
Source File: SwipeBackDelegate.java    From Readhub with Apache License 2.0 4 votes vote down vote up
public void attach(Activity activity, int layoutResID) {
    View root = getContainer(activity);
    View view = LayoutInflater.from(activity).inflate(layoutResID, null);
    swipeBackLayout.addView(view);
    activity.setContentView(root);
}
 
Example 20
Source File: DebugViewContainer.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Override public ViewGroup forActivity(final Activity activity) {
  activity.setContentView(R.layout.debug_activity_frame);

  final ViewHolder viewHolder = new ViewHolder();
  ButterKnife.bind(viewHolder, activity);

  final Context drawerContext = new ContextThemeWrapper(activity, R.style.Theme_U2020_Debug);
  final DebugView debugView = new DebugView(drawerContext);
  viewHolder.debugDrawer.addView(debugView);

  // Set up the contextual actions to watch views coming in and out of the content area.
  ContextualDebugActions contextualActions = debugView.getContextualDebugActions();
  contextualActions.setActionClickListener(v -> viewHolder.drawerLayout.closeDrawers());
  viewHolder.content.setOnHierarchyChangeListener(
      HierarchyTreeChangeListener.wrap(contextualActions));

  viewHolder.drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, GravityCompat.END);
  viewHolder.drawerLayout.setDrawerListener(new DebugDrawerLayout.SimpleDrawerListener() {
    @Override public void onDrawerOpened(View drawerView) {
      debugView.onDrawerOpened();
    }
  });

  TelescopeLayout.cleanUp(activity); // Clean up any old screenshots.
  viewHolder.telescopeLayout.setLens(new BugReportLens(activity, lumberYard));

  // If you have not seen the debug drawer before, show it with a message
  if (!seenDebugDrawer.get()) {
    viewHolder.drawerLayout.postDelayed(() -> {
      viewHolder.drawerLayout.openDrawer(GravityCompat.END);
      Toast.makeText(drawerContext, R.string.debug_drawer_welcome, Toast.LENGTH_LONG).show();
    }, 1000);
    seenDebugDrawer.set(true);
  }

  final CompositeSubscription subscriptions = new CompositeSubscription();
  setupMadge(viewHolder, subscriptions);
  setupScalpel(viewHolder, subscriptions);

  final Application app = activity.getApplication();
  app.registerActivityLifecycleCallbacks(new EmptyActivityLifecycleCallbacks() {
    @Override public void onActivityDestroyed(Activity lifecycleActivity) {
      if (lifecycleActivity == activity) {
        subscriptions.unsubscribe();
        app.unregisterActivityLifecycleCallbacks(this);
      }
    }
  });

  riseAndShine(activity);
  return viewHolder.content;
}