use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class TabLayoutActions method setupWithViewPager.
/** Wires <code>TabLayout</code> to <code>ViewPager</code> content. */
public static ViewAction setupWithViewPager(@Nullable final ViewPager viewPager) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayingAtLeast(90);
}
@Override
public String getDescription() {
return "Setup with ViewPager content";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
TabLayout tabLayout = (TabLayout) view;
tabLayout.setupWithViewPager(viewPager);
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class TabLayoutActions method setScrollPosition.
/**
* Calls <code>setScrollPosition(position, positionOffset, true)</code> on the <code>TabLayout
* </code>
*/
public static ViewAction setScrollPosition(final int position, final float positionOffset) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(TabLayout.class);
}
@Override
public String getDescription() {
return "setScrollPosition(" + position + ", " + positionOffset + ", true)";
}
@Override
public void perform(UiController uiController, View view) {
TabLayout tabs = (TabLayout) view;
tabs.setScrollPosition(position, positionOffset, true);
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class TestUtilsActions method addTabs.
/** Adds tabs to {@link TabLayout} */
public static ViewAction addTabs(final String... tabs) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(TabLayout.class);
}
@Override
public String getDescription() {
return "TabLayout add tabs";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
TabLayout tabLayout = (TabLayout) view;
for (int i = 0; i < tabs.length; i++) {
tabLayout.addTab(tabLayout.newTab().setText(tabs[i]));
}
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class TestUtilsActions method setTitle.
/** Sets title on the {@link CollapsingToolbarLayout}. */
public static ViewAction setTitle(final CharSequence title) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(CollapsingToolbarLayout.class);
}
@Override
public String getDescription() {
return "set toolbar title";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) view;
collapsingToolbarLayout.setTitle(title);
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction 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();
}
};
}
Aggregations