Search in sources :

Example 36 with UiController

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

the class TestUtilsActions method replaceTabLayout.

/**
   * Replaces an existing {@link TabLayout} with a new one inflated from the specified layout
   * resource.
   */
public static ViewAction replaceTabLayout(@LayoutRes final int tabLayoutResId) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Replace TabLayout";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final ViewGroup viewGroup = (ViewGroup) view;
            final int childCount = viewGroup.getChildCount();
            // Iterate over children and find TabLayout
            for (int i = 0; i < childCount; i++) {
                View child = viewGroup.getChildAt(i);
                if (child instanceof TabLayout) {
                    // Remove the existing TabLayout
                    viewGroup.removeView(child);
                    // Create a new one
                    final LayoutInflater layoutInflater = LayoutInflater.from(view.getContext());
                    final TabLayout newTabLayout = (TabLayout) layoutInflater.inflate(tabLayoutResId, viewGroup, false);
                    // Make sure we're adding the new TabLayout at the same index
                    viewGroup.addView(newTabLayout, i);
                    break;
                }
            }
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) ViewGroup(android.view.ViewGroup) TabLayout(android.support.design.widget.TabLayout) LayoutInflater(android.view.LayoutInflater) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View)

Example 37 with UiController

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

the class TextInputLayoutActions method setErrorTextAppearance.

public static ViewAction setErrorTextAppearance(final int resId) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the error text appearance";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setErrorTextAppearance(resId);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 38 with UiController

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

the class TextInputLayoutActions method setErrorEnabled.

public static ViewAction setErrorEnabled(final boolean enabled) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Enables/disables the error";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setErrorEnabled(enabled);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 39 with UiController

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

the class TextInputLayoutActions method setCounterEnabled.

public static ViewAction setCounterEnabled(final boolean enabled) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets the counter enabled";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TextInputLayout layout = (TextInputLayout) view;
            layout.setCounterEnabled(enabled);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View)

Example 40 with UiController

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

the class ViewPagerActions method scrollRight.

/** Moves <code>ViewPager</code> to the right by one page. */
public static ViewAction scrollRight() {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "ViewPager scroll one page to the right";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ViewPager viewPager = (ViewPager) view;
            int current = viewPager.getCurrentItem();
            viewPager.setCurrentItem(current + 1, false);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Aggregations

UiController (android.support.test.espresso.UiController)57 View (android.view.View)57 ViewAction (android.support.test.espresso.ViewAction)56 NavigationView (android.support.design.widget.NavigationView)18 TextView (android.widget.TextView)11 ViewPager (android.support.v4.view.ViewPager)8 TabLayout (android.support.design.widget.TabLayout)7 TextInputLayout (android.support.design.widget.TextInputLayout)7 Espresso.onView (android.support.test.espresso.Espresso.onView)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 ViewGroup (android.view.ViewGroup)4 Matcher (org.hamcrest.Matcher)4 BaseMatcher (org.hamcrest.BaseMatcher)3 TabLayoutActions.setupWithViewPager (android.support.design.testutils.TabLayoutActions.setupWithViewPager)2 BottomNavigationView (android.support.design.widget.BottomNavigationView)2 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 TimeoutException (java.util.concurrent.TimeoutException)2 NotFoundException (android.content.res.Resources.NotFoundException)1