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();
}
};
}
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();
}
};
}
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();
}
};
}
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();
}
};
}
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();
}
};
}
Aggregations