Search in sources :

Example 51 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class NavigationViewActions method setItemBackground.

/** Sets item background on the content of the navigation view. */
public static ViewAction setItemBackground(@Nullable final Drawable itemBackground) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayed();
        }

        @Override
        public String getDescription() {
            return "Set item background";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.setItemBackground(itemBackground);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 52 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class NavigationViewActions method addHeaderView.

/** Add the specified view as a header to the navigation view. */
public static ViewAction addHeaderView(@NonNull final LayoutInflater inflater, @LayoutRes final int res) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayed();
        }

        @Override
        public String getDescription() {
            return "Add header view";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.addHeaderView(inflater.inflate(res, null, false));
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 53 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class NavigationViewActions method removeHeaderView.

/** Removes a previously added header view from the navigation view. */
public static ViewAction removeHeaderView(@Nullable final View headerView) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayed();
        }

        @Override
        public String getDescription() {
            return "Remove header view";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.removeHeaderView(headerView);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 54 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class NavigationViewActions method setItemTextColor.

/** Sets item text color on the content of the navigation view. */
public static ViewAction setItemTextColor(final ColorStateList textColor) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayed();
        }

        @Override
        public String getDescription() {
            return "Set item text color";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.setItemTextColor(textColor);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 55 with UiController

use of android.support.test.espresso.UiController in project material-components-android by material-components.

the class TabLayoutWithViewPagerTest method addItemsToPager.

private static <Q> ViewAction addItemsToPager(final String[] title, final Q[] content) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewPager.class);
        }

        @Override
        public String getDescription() {
            return "Add items and notify on content change";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final ViewPager viewPager = (ViewPager) view;
            // no way to avoid this cast
            @SuppressWarnings("unchecked") final BasePagerAdapter<Q> viewPagerAdapter = (BasePagerAdapter<Q>) viewPager.getAdapter();
            int itemCount = title.length;
            for (int i = 0; i < itemCount; i++) {
                viewPagerAdapter.add(title[i], content[i]);
            }
            viewPagerAdapter.notifyDataSetChanged();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) ViewPager(android.support.v4.view.ViewPager) TabLayoutActions.setupWithViewPager(android.support.design.testutils.TabLayoutActions.setupWithViewPager)

Aggregations

UiController (android.support.test.espresso.UiController)64 View (android.view.View)64 ViewAction (android.support.test.espresso.ViewAction)63 NavigationView (android.support.design.widget.NavigationView)18 Espresso.onView (android.support.test.espresso.Espresso.onView)14 TextView (android.widget.TextView)14 ViewPager (android.support.v4.view.ViewPager)9 TabLayout (android.support.design.widget.TabLayout)8 TextInputLayout (android.support.design.widget.TextInputLayout)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 BottomNavigationView (android.support.design.widget.BottomNavigationView)4 ViewGroup (android.view.ViewGroup)4 Matcher (org.hamcrest.Matcher)4 BaseMatcher (org.hamcrest.BaseMatcher)3 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)3 TabLayoutActions.setupWithViewPager (android.support.design.testutils.TabLayoutActions.setupWithViewPager)2 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 RecyclerView (android.support.v7.widget.RecyclerView)2 HorizontalScrollView (android.widget.HorizontalScrollView)2