Search in sources :

Example 1 with OtrSwitch

use of com.waz.zclient.ui.views.e2ee.OtrSwitch in project wire-android by wireapp.

the class CustomMatchers method otrSwitchWithId.

public static Matcher<View> otrSwitchWithId(final int id) {
    return new TypeSafeMatcher<View>() {

        Resources resources = null;

        @Override
        public void describeTo(Description description) {
            String idDescription = Integer.toString(id);
            if (resources != null) {
                try {
                    idDescription = resources.getResourceName(id);
                } catch (Resources.NotFoundException e) {
                    // No big deal, will just use the int value.
                    idDescription = String.format("%s (resource name not found)", id);
                }
            }
            description.appendText("with id: " + idDescription);
        }

        @Override
        public boolean matchesSafely(View view) {
            resources = view.getResources();
            ViewParent parent = view.getParent();
            return parent != null && parent instanceof OtrSwitch && id == ((OtrSwitch) parent).getId() && view instanceof SwitchCompat;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) Resources(android.content.res.Resources) OtrSwitch(com.waz.zclient.ui.views.e2ee.OtrSwitch) View(android.view.View) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

Resources (android.content.res.Resources)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 View (android.view.View)1 ViewParent (android.view.ViewParent)1 OtrSwitch (com.waz.zclient.ui.views.e2ee.OtrSwitch)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1