Search in sources :

Example 16 with FloatingActionButton

use of android.support.design.widget.FloatingActionButton in project material-components-android by material-components.

the class TestUtilsMatchers method withFabBackgroundFill.

/**
   * Returns a matcher that matches FloatingActionButtons with the specified background fill color.
   */
public static Matcher withFabBackgroundFill(@ColorInt final int fillColor) {
    return new BoundedMatcher<View, View>(View.class) {

        private String failedCheckDescription;

        @Override
        public void describeTo(final Description description) {
            description.appendText(failedCheckDescription);
        }

        @Override
        public boolean matchesSafely(final View view) {
            if (!(view instanceof FloatingActionButton)) {
                return false;
            }
            final FloatingActionButton fab = (FloatingActionButton) view;
            // Since the FAB background is round, and may contain the shadow, we'll look at
            // just the center half rect of the content area
            final Rect area = new Rect();
            fab.getContentRect(area);
            final int rectHeightQuarter = area.height() / 4;
            final int rectWidthQuarter = area.width() / 4;
            area.left += rectWidthQuarter;
            area.top += rectHeightQuarter;
            area.right -= rectWidthQuarter;
            area.bottom -= rectHeightQuarter;
            try {
                TestUtils.assertAllPixelsOfColor("", fab.getBackground(), view.getWidth(), view.getHeight(), false, fillColor, area, 0, true);
            } catch (Throwable t) {
                failedCheckDescription = t.getMessage();
                return false;
            }
            return true;
        }
    };
}
Also used : Rect(android.graphics.Rect) Description(org.hamcrest.Description) FloatingActionButton(android.support.design.widget.FloatingActionButton) BoundedMatcher(android.support.test.espresso.matcher.BoundedMatcher) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 17 with FloatingActionButton

use of android.support.design.widget.FloatingActionButton in project material-components-android by material-components.

the class FloatingActionButtonActions method showThenHide.

public static ViewAction showThenHide(final int animDuration) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Calls show() then hide()";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            FloatingActionButton fab = (FloatingActionButton) view;
            fab.show();
            fab.hide();
            uiController.loopMainThreadForAtLeast(animDuration + 50);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View)

Example 18 with FloatingActionButton

use of android.support.design.widget.FloatingActionButton in project material-components-android by material-components.

the class FloatingActionButtonActions method setSize.

public static ViewAction setSize(@FloatingActionButton.Size final int size) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets FloatingActionButton size";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final FloatingActionButton fab = (FloatingActionButton) view;
            fab.setSize(size);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View)

Example 19 with FloatingActionButton

use of android.support.design.widget.FloatingActionButton in project material-components-android by material-components.

the class FloatingActionButtonActions method hideThenShow.

public static ViewAction hideThenShow(final int animDuration) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Calls hide() then show()";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            FloatingActionButton fab = (FloatingActionButton) view;
            fab.hide();
            fab.show();
            uiController.loopMainThreadForAtLeast(animDuration + 100);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) FloatingActionButton(android.support.design.widget.FloatingActionButton) View(android.view.View)

Example 20 with FloatingActionButton

use of android.support.design.widget.FloatingActionButton in project material-components-android by material-components.

the class FloatingActionButtonActions method setImageResource.

public static ViewAction setImageResource(@DrawableRes final int resId) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Sets FloatingActionButton image resource";
        }

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

Aggregations

FloatingActionButton (android.support.design.widget.FloatingActionButton)79 View (android.view.View)56 Toolbar (android.support.v7.widget.Toolbar)29 TextView (android.widget.TextView)18 ImageView (android.widget.ImageView)15 Intent (android.content.Intent)12 RecyclerView (android.support.v7.widget.RecyclerView)11 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 ColorStateList (android.content.res.ColorStateList)8 Bundle (android.os.Bundle)8 NavigationView (android.support.design.widget.NavigationView)8 TabLayout (android.support.design.widget.TabLayout)8 ViewPager (android.support.v4.view.ViewPager)8 ActionBar (android.support.v7.app.ActionBar)7 UiController (android.support.test.espresso.UiController)6 ViewAction (android.support.test.espresso.ViewAction)6 AdapterView (android.widget.AdapterView)6 DrawerLayout (android.support.v4.widget.DrawerLayout)4 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)4 MenuItem (android.view.MenuItem)4