Java Code Examples for android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#recycle()
The following examples show how to use
android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#recycle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawerLayout.java From adt-leanback-support with Apache License 2.0 | 6 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { if (CAN_HIDE_DESCENDANTS) { super.onInitializeAccessibilityNodeInfo(host, info); } else { // Obtain a node for the host, then manually generate the list // of children to only include non-obscured views. final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } copyNodeInfoNoChildren(info, superNode); superNode.recycle(); addChildrenForAccessibility(info, (ViewGroup) host); } info.setClassName(DrawerLayout.class.getName()); }
Example 2
Source File: KlyphDrawerLayout.java From Klyph with MIT License | 6 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } copyNodeInfoNoChildren(info, superNode); superNode.recycle(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (!filter(child)) { info.addChild(child); } } }
Example 3
Source File: AccessibilityNodeInfoUtils.java From brailleback with Apache License 2.0 | 6 votes |
private static AccessibilityNodeInfoCompat refreshFromChild( AccessibilityNodeInfoCompat node) { if (node.getChildCount() > 0) { AccessibilityNodeInfoCompat firstChild = node.getChild(0); if (firstChild != null) { AccessibilityNodeInfoCompat parent = firstChild.getParent(); firstChild.recycle(); if (node.equals(parent)) { return parent; } else { recycleNodes(parent); } } } return null; }
Example 4
Source File: DrawerLayout.java From guideshow with MIT License | 6 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } copyNodeInfoNoChildren(info, superNode); superNode.recycle(); addChildrenForAccessibility(info, (ViewGroup) host); }
Example 5
Source File: H.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfoCompat accessibilitynodeinfocompat) { AccessibilityNodeInfoCompat accessibilitynodeinfocompat1 = AccessibilityNodeInfoCompat.obtain(accessibilitynodeinfocompat); super.onInitializeAccessibilityNodeInfo(view, accessibilitynodeinfocompat1); a(accessibilitynodeinfocompat, accessibilitynodeinfocompat1); accessibilitynodeinfocompat1.recycle(); accessibilitynodeinfocompat.setClassName(android/support/v4/widget/SlidingPaneLayout.getName()); accessibilitynodeinfocompat.setSource(view); android.view.ViewParent viewparent = ViewCompat.getParentForAccessibility(view); if (viewparent instanceof View) { accessibilitynodeinfocompat.setParent((View)viewparent); } int i = b.getChildCount(); for (int j = 0; j < i; j++) { View view1 = b.getChildAt(j); if (!a(view1) && view1.getVisibility() == 0) { ViewCompat.setImportantForAccessibility(view1, 1); accessibilitynodeinfocompat.addChild(view1); } } }
Example 6
Source File: DrawerLayout.java From android-recipes-app with Apache License 2.0 | 6 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); info.setClassName(DrawerLayout.class.getName()); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } copyNodeInfoNoChildren(info, superNode); superNode.recycle(); addChildrenForAccessibility(info, (ViewGroup) host); }
Example 7
Source File: TreeDebug.java From brailleback with Apache License 2.0 | 5 votes |
/** * Logs the tree using the input node as the root. */ public static void logNodeTree(AccessibilityNodeInfoCompat node) { if (node == null) { return; } HashSet<AccessibilityNodeInfoCompat> seen = new HashSet<AccessibilityNodeInfoCompat>(); logNodeTree(AccessibilityNodeInfoCompat.obtain(node), "", seen); for (AccessibilityNodeInfoCompat n : seen) { n.recycle(); } }
Example 8
Source File: SwipeBackLayout.java From AndroidProjects with MIT License | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); copyNodeInfoNoChildren(info, superNode); superNode.recycle(); info.setClassName(SwipeBackLayout.class.getName()); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } // This is a best-approximation of addChildrenForAccessibility() // that accounts for filtering. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (!filter(child) && (child.getVisibility() == View.VISIBLE)) { // Force importance to "yes" since we can't read the value. ViewCompat.setImportantForAccessibility( child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); info.addChild(child); } } }
Example 9
Source File: WebInterfaceUtils.java From brailleback with Apache License 2.0 | 5 votes |
/** * Determines whether or not the given node contains native web content (and not ChromeVox). * * @param node The node to evaluate * @return {@code true} if the node contains native web content, {@code false} otherwise */ public static boolean hasNativeWebContent(AccessibilityNodeInfoCompat node) { if (node == null) { return false; } if (!supportsWebActions(node)) { return false; } // ChromeVox does not have sub elements, so if the parent element also has web content // this cannot be ChromeVox. AccessibilityNodeInfoCompat parent = node.getParent(); if (supportsWebActions(parent)) { if (parent != null) { parent.recycle(); } return true; } if (parent != null) { parent.recycle(); } // ChromeVox never has child elements return node.getChildCount() > 0; }
Example 10
Source File: DisplaySpans.java From brailleback with Apache License 2.0 | 5 votes |
/** * Recycles objects owned by the spannable. In particular, any * accessibility nodes that have been associated with {@code spannable} * are recycled and removed. */ public static void recycleSpans(CharSequence chars) { if (!(chars instanceof Spannable)) { return; } Spannable spannable = (Spannable) chars; AccessibilityNodeInfoCompat[] nodes = spannable.getSpans( 0, spannable.length(), AccessibilityNodeInfoCompat.class); for (AccessibilityNodeInfoCompat node : nodes) { node.recycle(); spannable.removeSpan(node); } }
Example 11
Source File: SlidingPaneLayout.java From adt-leanback-support with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); copyNodeInfoNoChildren(info, superNode); superNode.recycle(); info.setClassName(SlidingPaneLayout.class.getName()); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } // This is a best-approximation of addChildrenForAccessibility() // that accounts for filtering. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (!filter(child) && (child.getVisibility() == View.VISIBLE)) { // Force importance to "yes" since we can't read the value. ViewCompat.setImportantForAccessibility( child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); info.addChild(child); } } }
Example 12
Source File: SlidingPaneLayout.java From android-recipes-app with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); copyNodeInfoNoChildren(info, superNode); superNode.recycle(); info.setClassName(SlidingPaneLayout.class.getName()); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } // This is a best-approximation of addChildrenForAccessibility() // that accounts for filtering. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (!filter(child) && (child.getVisibility() == View.VISIBLE)) { // Force importance to "yes" since we can't read the value. ViewCompat.setImportantForAccessibility( child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); info.addChild(child); } } }
Example 13
Source File: TranslucentDrawerLayout.java From 920-text-editor-v2 with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { if (CAN_HIDE_DESCENDANTS) { super.onInitializeAccessibilityNodeInfo(host, info); } else { // Obtain a node for the host, then manually generate the list // of children to only include non-obscured views. final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } copyNodeInfoNoChildren(info, superNode); superNode.recycle(); addChildrenForAccessibility(info, (ViewGroup) host); } info.setClassName(DrawerLayout.class.getName()); // This view reports itself as focusable so that it can intercept // the back button, but we should prevent this view from reporting // itself as focusable to accessibility services. info.setFocusable(false); info.setFocused(false); info.removeAction(AccessibilityActionCompat.ACTION_FOCUS); info.removeAction(AccessibilityActionCompat.ACTION_CLEAR_FOCUS); }
Example 14
Source File: SearchNavigationMode.java From brailleback with Apache License 2.0 | 5 votes |
/** * Syncs accessibility focus back to the node focused when search mode * first activated. */ private void syncBackToInitial() { AccessibilityNodeInfoCompat focused = FocusFinder.getFocusedNode( mAccessibilityService, false); if (focused == null) { return; } try { mInitialNode.reset(AccessibilityNodeInfoUtils.refreshNode( mInitialNode.get())); if (!AccessibilityNodeInfoRef.isNull(mInitialNode)) { if (mInitialNode.get().isAccessibilityFocused()) { return; } mFeedbackManager.emitOnFailure( mInitialNode.get().performAction( AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS), FeedbackManager.TYPE_COMMAND_FAILED); } else { mFeedbackManager.emitOnFailure( focused.performAction(AccessibilityNodeInfoCompat. ACTION_CLEAR_ACCESSIBILITY_FOCUS), FeedbackManager.TYPE_COMMAND_FAILED); } } finally { focused.recycle(); } }
Example 15
Source File: SlidingPaneLayout.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); super.onInitializeAccessibilityNodeInfo(host, superNode); copyNodeInfoNoChildren(info, superNode); superNode.recycle(); info.setClassName(SlidingPaneLayout.class.getName()); info.setSource(host); final ViewParent parent = ViewCompat.getParentForAccessibility(host); if (parent instanceof View) { info.setParent((View) parent); } // This is a best-approximation of addChildrenForAccessibility() // that accounts for filtering. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (!filter(child) && (child.getVisibility() == View.VISIBLE)) { // Force importance to "yes" since we can't read the value. ViewCompat.setImportantForAccessibility( child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); info.addChild(child); } } }
Example 16
Source File: FocusFinder.java From brailleback with Apache License 2.0 | 5 votes |
private static AccessibilityNodeInfoCompat findFirstFocusableDescendantInternal( AccessibilityNodeInfoCompat root, Context context, HashSet<AccessibilityNodeInfoCompat> seenNodes) { for (int i = 0, end = root.getChildCount(); i < end; ++i) { AccessibilityNodeInfoCompat child = root.getChild(i); if (child == null) { continue; } if (AccessibilityNodeInfoUtils.shouldFocusNode( context, child)) { return child; } if (!seenNodes.add(child)) { LogUtils.log(FocusFinder.class, Log.ERROR, "Cycle in node tree"); child.recycle(); return null; } AccessibilityNodeInfoCompat n = findFirstFocusableDescendantInternal( child, context, seenNodes); if (n != null) { return n; } } return null; }
Example 17
Source File: AccessibilityUtil.java From stetho with MIT License | 5 votes |
/** * Determines if the supplied {@link View} and {@link AccessibilityNodeInfoCompat} has any * children which are not independently accessibility focusable and also have a spoken * description. * <p> * NOTE: Accessibility services will include these children's descriptions in the closest * focusable ancestor. * * @param view The {@link View} to evaluate * @param node The {@link AccessibilityNodeInfoCompat} to evaluate * @return {@code true} if it has any non-actionable speaking descendants within its subtree */ public static boolean hasNonActionableSpeakingDescendants( @Nullable AccessibilityNodeInfoCompat node, @Nullable View view) { if (node == null || view == null || !(view instanceof ViewGroup)) { return false; } ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { View childView = viewGroup.getChildAt(i); if (childView == null) { continue; } AccessibilityNodeInfoCompat childNode = AccessibilityNodeInfoCompat.obtain(); try { ViewCompat.onInitializeAccessibilityNodeInfo(childView, childNode); if (isAccessibilityFocusable(childNode, childView)) { continue; } if (isSpeakingNode(childNode, childView)) { return true; } } finally { childNode.recycle(); } } return false; }
Example 18
Source File: AccessibilityNodeInfoWrapper.java From stetho with MIT License | 4 votes |
@Nullable public static CharSequence getDescription(View view) { AccessibilityNodeInfoCompat node = createNodeInfoFromView(view); try { 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; } 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(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; } finally { node.recycle(); } }
Example 19
Source File: AccessibilityNodeInfoWrapper.java From stetho with MIT License | 4 votes |
public static boolean getIgnored(View view) { int important = ViewCompat.getImportantForAccessibility(view); if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO || important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) { return true; } // Go all the way up the tree to make sure no parent has hidden its descendants ViewParent parent = view.getParent(); while (parent instanceof View) { if (ViewCompat.getImportantForAccessibility((View) parent) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) { return true; } parent = parent.getParent(); } AccessibilityNodeInfoCompat node = createNodeInfoFromView(view); try { if (!node.isVisibleToUser()) { return true; } if (AccessibilityUtil.isAccessibilityFocusable(node, view)) { if (node.getChildCount() <= 0) { // Leaves that are accessibility focusable are never ignored, even if they don't have a // speakable description return false; } else if (AccessibilityUtil.isSpeakingNode(node, view)) { // Node is focusable and has something to speak return false; } // Node is focusable and has nothing to speak return true; } // If this node has no focusable ancestors, but it still has text, // then it should receive focus from navigation and be read aloud. if (!AccessibilityUtil.hasFocusableAncestor(node, view) && AccessibilityUtil.hasText(node)) { return false; } return true; } finally { node.recycle(); } }
Example 20
Source File: AccessibilityNodeInfoWrapper.java From stetho with MIT License | 4 votes |
@Nullable public static String getActions(View view) { AccessibilityNodeInfoCompat node = createNodeInfoFromView(view); try { final StringBuilder actionLabels = new StringBuilder(); final String separator = ", "; for (AccessibilityActionCompat action : node.getActionList()) { if (actionLabels.length() > 0) { actionLabels.append(separator); } switch (action.getId()) { case AccessibilityNodeInfoCompat.ACTION_FOCUS: actionLabels.append("focus"); break; case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS: actionLabels.append("clear-focus"); break; case AccessibilityNodeInfoCompat.ACTION_SELECT: actionLabels.append("select"); break; case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION: actionLabels.append("clear-selection"); break; case AccessibilityNodeInfoCompat.ACTION_CLICK: actionLabels.append("click"); break; case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK: actionLabels.append("long-click"); break; case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS: actionLabels.append("accessibility-focus"); break; case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS: actionLabels.append("clear-accessibility-focus"); break; case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: actionLabels.append("next-at-movement-granularity"); break; case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: actionLabels.append("previous-at-movement-granularity"); break; case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT: actionLabels.append("next-html-element"); break; case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT: actionLabels.append("previous-html-element"); break; case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: actionLabels.append("scroll-forward"); break; case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: actionLabels.append("scroll-backward"); break; case AccessibilityNodeInfoCompat.ACTION_CUT: actionLabels.append("cut"); break; case AccessibilityNodeInfoCompat.ACTION_COPY: actionLabels.append("copy"); break; case AccessibilityNodeInfoCompat.ACTION_PASTE: actionLabels.append("paste"); break; case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION: actionLabels.append("set-selection"); break; default: CharSequence label = action.getLabel(); if (label != null) { actionLabels.append(label); } else { actionLabels.append("unknown"); } break; } } return actionLabels.length() > 0 ? actionLabels.toString() : null; } finally { node.recycle(); } }