AccessibilityViewMatchers.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:espresso-support 作者:
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static Matcher<? super View> withUsageHintOnLongClick(@StringRes final int resourceId) {
    return new TypeSafeMatcher<View>() {

        private String resourceName;
        private String expectedText;

        @Override
        protected boolean matchesSafely(View view) {
            if (!view.isLongClickable()) {
                return false;
            }

            expectedText = view.getResources().getString(resourceId);
            resourceName = view.getResources().getResourceEntryName(resourceId);

            if (expectedText == null) {
                return false;
            }

            AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_LONG_CLICK);
            return expectedText.equals(clickAction.getLabel());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is long clickable and has custom usage hint for ACTION_LONG_CLICK from resource id: ").appendValue(resourceId);
            appendResourceNameAndExpectedTextToDescription(description, resourceName, expectedText);
        }
    };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号