List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getText
public CharSequence getText()
From source file:Main.java
/** * Returns whether the specified node has text. * * @param node The node to check.// ww w . j a v a2s . c o m * @return {@code true} if the node has text. */ private static boolean hasText(AccessibilityNodeInfoCompat node) { if (node == null) { return false; } return (!TextUtils.isEmpty(node.getText()) || !TextUtils.isEmpty(node.getContentDescription())); }
From source file:Main.java
/** * Returns whether the specified node has text or a content description. * * @param node The node to check.// w w w. j av a 2 s. c om * @return {@code true} if the node has text. */ public static boolean hasText(@Nullable AccessibilityNodeInfoCompat node) { if (node == null) { return false; } return !TextUtils.isEmpty(node.getText()) || !TextUtils.isEmpty(node.getContentDescription()); }
From source file:com.android.utils.AutomationUtils.java
/** * Returns whether a node matches the class specified by * {@code className} and exactly match the text or content description * specified by {@code text}.// ww w. ja v a 2 s . co m */ private static boolean nodeMatchesFilter(AccessibilityNodeInfoCompat node, CharSequence referenceClassName, String findText) { return ClassLoadingCache.checkInstanceOf(node.getClassName(), referenceClassName) && (TextUtils.equals(findText, node.getText()) || TextUtils.equals(findText, node.getContentDescription())); }
From source file:com.android.talkback.menurules.RuleSpannables.java
/** * Retrieves SpannableString in the accessibility node. The content description and text of the * node is checked in order.//w w w . ja v a 2s. c o m * @param node * @return SpannableString with at least 1 UrlSpan. null if no UrlSpan found in the node. */ private static SpannableString getStringWithUrlSpan(AccessibilityNodeInfoCompat node) { CharSequence text = node.getContentDescription(); if (!TextUtils.isEmpty(text)) { if (!(text instanceof SpannableString)) { return null; } } else { text = node.getText(); if (TextUtils.isEmpty(text) || !(text instanceof SpannableString)) { return null; } } SpannableString spannable = (SpannableString) text; final URLSpan[] urlSpans = spannable.getSpans(0, spannable.length(), URLSpan.class); if (urlSpans == null || urlSpans.length == 0) { return null; } return spannable; }
From source file:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java
@Nullable public static CharSequence getDescription(AccessibilityNodeInfoCompat node, View view) { CharSequence contentDescription = node.getContentDescription(); CharSequence nodeText = node.getText(); boolean hasNodeText = !TextUtils.isEmpty(nodeText); boolean isEditText = view instanceof EditText; // EditText's prioritize their own text content over a contentDescription if (!TextUtils.isEmpty(contentDescription) && (!isEditText || !hasNodeText)) { return contentDescription; }/*from w w w . j a v a 2 s. com*/ if (hasNodeText) { return nodeText; } // If there are child views and no contentDescription the text of all non-focusable children, // comma separated, becomes the description. if (view instanceof ViewGroup) { final StringBuilder concatChildDescription = new StringBuilder(); final String separator = ", "; ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { final View child = viewGroup.getChildAt(i); AccessibilityNodeInfoCompat childNodeInfo = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(child, childNodeInfo); CharSequence childNodeDescription = null; if (AccessibilityUtil.isSpeakingNode(childNodeInfo, child) && !AccessibilityUtil.isAccessibilityFocusable(childNodeInfo, child)) { childNodeDescription = getDescription(childNodeInfo, child); } if (!TextUtils.isEmpty(childNodeDescription)) { if (concatChildDescription.length() > 0) { concatChildDescription.append(separator); } concatChildDescription.append(childNodeDescription); } childNodeInfo.recycle(); } return concatChildDescription.length() > 0 ? concatChildDescription.toString() : null; } return null; }
From source file:Main.java
/** * Gets the text of a <code>node</code> by returning the content description * (if available) or by returning the text. * * @param node The node./* ww w. j a v a 2 s . co m*/ * @return The node text. */ public static CharSequence getNodeText(AccessibilityNodeInfoCompat node) { if (node == null) { return null; } // Prefer content description over text. // TODO: Why are we checking the trimmed length? final CharSequence contentDescription = node.getContentDescription(); if (!TextUtils.isEmpty(contentDescription) && (TextUtils.getTrimmedLength(contentDescription) > 0)) { return contentDescription; } final CharSequence text = node.getText(); if (!TextUtils.isEmpty(text) && (TextUtils.getTrimmedLength(text) > 0)) { return text; } return null; }
From source file:com.googlecode.eyesfree.utils.TreeDebug.java
/** * Gets a description of the properties of a node. */// w w w .j a v a2 s . com public static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) { StringBuilder sb = new StringBuilder(); sb.append(node.getWindowId()); if (node.getClassName() != null) { appendSimpleName(sb, node.getClassName()); } else { sb.append("??"); } if (!node.isVisibleToUser()) { sb.append(":invisible"); } if (node.getText() != null) { sb.append(":"); sb.append(node.getText().toString().trim()); } if (node.getContentDescription() != null) { sb.append(":"); sb.append(node.getContentDescription().toString().trim()); } int actions = node.getActions(); if (actions != 0) { sb.append(":"); if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) { sb.append("F"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) { sb.append("A"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { sb.append("a"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) { sb.append("-"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) { sb.append("+"); } } if (node.isCheckable()) { sb.append(":"); if (node.isChecked()) { sb.append("(X)"); } else { sb.append("( )"); } } if (node.isFocusable()) { sb.append(":focusable"); } if (node.isFocused()) { sb.append(":focused"); } if (node.isSelected()) { sb.append(":selected"); } if (node.isClickable()) { sb.append(":clickable"); } if (node.isLongClickable()) { sb.append(":longClickable"); } if (node.isAccessibilityFocused()) { sb.append(":accessibilityFocused"); } if (!node.isEnabled()) { sb.append(":disabled"); } return sb.toString(); }
From source file:com.google.android.marvin.utils.AutomationUtils.java
/** * Returns whether a node matches the class specified by * {@code className} and exactly match the text or content description * specified by {@code text}./*from w ww .ja v a 2s . c o m*/ */ private static boolean nodeMatchesFilter(Context context, AccessibilityNodeInfoCompat node, CharSequence referenceClassName, String findText) { final ClassLoadingManager loader = ClassLoadingManager.getInstance(); final CharSequence nodeClass = node.getClassName(); final CharSequence nodePackage = node.getPackageName(); if (!loader.checkInstanceOf(context, nodeClass, nodePackage, referenceClassName)) { return false; } final CharSequence nodeText = node.getText(); if (TextUtils.equals(findText, nodeText)) { return true; } final CharSequence nodeDesc = node.getContentDescription(); if (TextUtils.equals(findText, nodeDesc)) { return true; } return false; }
From source file:com.android.utils.TreeDebug.java
/** * Gets a description of the properties of a node. *///from w w w. j a v a 2 s . co m private static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) { StringBuilder sb = new StringBuilder(); sb.append(node.getWindowId()); if (node.getClassName() != null) { appendSimpleName(sb, node.getClassName()); } else { sb.append("??"); } if (!node.isVisibleToUser()) { sb.append(":invisible"); } Rect rect = new Rect(); node.getBoundsInScreen(rect); sb.append(":"); sb.append("(").append(rect.left).append(", ").append(rect.top).append(" - ").append(rect.right).append(", ") .append(rect.bottom).append(")"); if (node.getText() != null) { sb.append(":"); sb.append(node.getText().toString().trim()); } if (node.getContentDescription() != null) { sb.append(":"); sb.append(node.getContentDescription().toString().trim()); } int actions = node.getActions(); if (actions != 0) { sb.append(":"); if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) { sb.append("F"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) { sb.append("A"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { sb.append("a"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) { sb.append("-"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_CLICK) != 0) { sb.append("C"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_LONG_CLICK) != 0) { sb.append("L"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) { sb.append("+"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_EXPAND) != 0) { sb.append("e"); } if ((actions & AccessibilityNodeInfoCompat.ACTION_COLLAPSE) != 0) { sb.append("c"); } } if (node.isCheckable()) { sb.append(":"); if (node.isChecked()) { sb.append("(X)"); } else { sb.append("( )"); } } if (node.isFocusable()) { sb.append(":focusable"); } if (node.isFocused()) { sb.append(":focused"); } if (node.isSelected()) { sb.append(":selected"); } if (node.isClickable()) { sb.append(":clickable"); } if (node.isLongClickable()) { sb.append(":longClickable"); } if (node.isAccessibilityFocused()) { sb.append(":accessibilityFocused"); } if (!node.isEnabled()) { sb.append(":disabled"); } if (node.getCollectionInfo() != null) { sb.append(":collection"); sb.append("#R"); sb.append(node.getCollectionInfo().getRowCount()); sb.append("C"); sb.append(node.getCollectionInfo().getColumnCount()); } if (node.getCollectionItemInfo() != null) { if (node.getCollectionItemInfo().isHeading()) { sb.append(":heading"); } else { sb.append(":item"); } sb.append("#r"); sb.append(node.getCollectionItemInfo().getRowIndex()); sb.append("c"); sb.append(node.getCollectionItemInfo().getColumnIndex()); } return sb.toString(); }
From source file:com.google.android.marvin.mytalkback.speechrules.RuleEditText.java
/** * Inverts the default priorities of text and content description. If the * field is a password, only returns the content description or "password". * * @param context/*from w ww .j a v a 2s .c o m*/ * @param node * @return A text description of the editable text area. */ private CharSequence getText(Context context, AccessibilityNodeInfoCompat node) { final CharSequence text = node.getText(); final boolean shouldSpeakPasswords = SecureCompatUtils.shouldSpeakPasswords(context); if (!TextUtils.isEmpty(text) && (!node.isPassword() || shouldSpeakPasswords)) { return text; } final CharSequence contentDescription = node.getContentDescription(); if (!TextUtils.isEmpty(contentDescription)) { return contentDescription; } if (node.isPassword() && !shouldSpeakPasswords) { return context.getString(R.string.value_password); } return ""; }