Package org.robolectric.shadows
Class ShadowAccessibilityNodeInfo
java.lang.Object
org.robolectric.shadows.ShadowAccessibilityNodeInfo
@Implements(android.view.accessibility.AccessibilityNodeInfo.class)
public class ShadowAccessibilityNodeInfo
extends Object
Properties of
AccessibilityNodeInfo that are normally locked
may be changed using test APIs.
Calls to obtain() and recycle() are tracked to help spot bugs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classShadow class for android.view.accessibility.AccessibilityNodeInfo$SelectionPosition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(AccessibilityNodeInfo child) Add a child node to this one.protected voidprotected voidprotected voidaddLabeledBy(View label) Adds a node that labels this node.booleanEquality check based on reference equality of the Views from which these instances were created, or the equality of their assigned IDs.protected AccessibilityNodeInfogetChild(int index) protected intprotected AccessibilityNodeInfoprotected List<AccessibilityNodeInfo> Returns the list of nodes that label this node.protected AccessibilityNodeInfoprotected AccessibilityNodeInfoprotected Objectprotected CharSequencegetText()protected intprotected intprotected AccessibilityNodeInfoprotected AccessibilityNodeInfoprotected AccessibilityWindowInfoprotected intReturns the id of the window from which the info comes.protected static AccessibilityNodeInfoobtain()protected static AccessibilityNodeInfoobtain(AccessibilityNodeInfo info) protected static AccessibilityNodeInfoprotected static AccessibilityNodeInfoprotected booleanperformAction(int action) protected booleanperformAction(int action, Bundle arguments) protected voidrecycle()protected booleanrefresh()static voidvoidvoidvoidvoidConfigure the return result of an action if it is performedprotected voidsetQueryFromAppProcessEnabled(View view, boolean enabled) AfterAccessibilityNodeInfo.setQueryFromAppProcessEnabled(View, boolean)is called, we will have direct access to the realAccessibilityNodeInfohierarchy, so we want all future interactions with ANI to use the real object.voidsetRefreshReturnValue(boolean refreshReturnValue) protected voidsetSelection(Object selection) protected voidprotected voidprotected voidprotected voidsetTextSelection(int start, int end) voidSets the view whose node is visited after this one in accessibility traversal.protected voidsetTraversalAfter(View view, int virtualDescendantId) voidSets the view before whose node this one should be visited during traversal.protected voidsetTraversalBefore(View info, int virtualDescendantId)
-
Constructor Details
-
ShadowAccessibilityNodeInfo
public ShadowAccessibilityNodeInfo()
-
-
Method Details
-
obtain
-
obtain
-
obtain
-
obtain
-
resetObtainedInstances
-
recycle
-
getChildCount
-
getChild
-
getParent
-
refresh
-
setRefreshReturnValue
public void setRefreshReturnValue(boolean refreshReturnValue) -
setText
-
getText
-
getTextSelectionStart
-
getTextSelectionEnd
-
setTextSelection
-
setSelection
-
getSelection
-
getLabelFor
-
setLabelFor
-
getLabeledBy
-
setLabeledBy
-
addLabeledBy
Adds a node that labels this node.If
useRealAni()returns true, this method adds the given view that labels this node to the realAccessibilityNodeInfo. Otherwise, it adds the ANI node of the given view to `labeledByList`.If one wishes to use a real ANI node in a test, which is a recommended practice, below is a test snippet:
Activity activity = Robolectric.buildActivity(Activity.class).setup().get(); LinearLayout layout = new LinearLayout(activity); layout.setOrientation(LinearLayout.VERTICAL); TextView label1 = new TextView(activity); label1.setText("Label 1"); layout.addView(label1); TextView label2 = new TextView(activity); label2.setText("Label 2"); layout.addView(label2); activity.setContentView(layout); View view = activity.getWindow().getDecorView(); AccessibilityNodeInfo node = new AccessibilityNodeInfo(); node.setQueryFromAppProcessEnabled(view, true); node.addLabeledBy(label1); node.addLabeledBy(label2); List<AccessibilityNodeInfo> labeledByList = node.getLabeledByList();- See Also:
-
getLabeledByList
Returns the list of nodes that label this node.If
useRealAni()returns true, this method returns the list of nodes that label this node from the realAccessibilityNodeInfo. Otherwise, returns `labeledByList`.- See Also:
-
getTraversalAfter
-
setTraversalAfter
-
setTraversalAfter
Sets the view whose node is visited after this one in accessibility traversal.This may be useful for configuring traversal order in tests before the corresponding views have been inflated.
- Parameters:
info- The previous node.- See Also:
-
getTraversalBefore
-
setTraversalBefore
-
setTraversalBefore
Sets the view before whose node this one should be visited during traversal.This may be useful for configuring traversal order in tests before the corresponding views have been inflated.
- Parameters:
info- The view providing the preceding node.- See Also:
-
setSource
-
setSource
-
getWindow
-
getWindowId
Returns the id of the window from which the info comes. -
setAccessibilityWindowInfo
-
performAction
-
performAction
-
equals
Equality check based on reference equality of the Views from which these instances were created, or the equality of their assigned IDs. -
addChild
Add a child node to this one. Also initializes the parent field of the child.- Parameters:
child- The node to be added as a child.
-
addChild
-
addChild
-
getPerformedActions
- Returns:
- The list of arguments for the various calls to performAction. Unmodifiable.
-
getPerformedActionsWithArgs
- Returns:
- The list of arguments for the various calls to performAction. Unmodifiable.
-
setQueryFromAppProcessEnabled
@Filter(minSdk=34, order=AFTER) protected void setQueryFromAppProcessEnabled(View view, boolean enabled) AfterAccessibilityNodeInfo.setQueryFromAppProcessEnabled(View, boolean)is called, we will have direct access to the realAccessibilityNodeInfohierarchy, so we want all future interactions with ANI to use the real object. -
setOnPerformActionListener
public void setOnPerformActionListener(ShadowAccessibilityNodeInfo.OnPerformActionListener listener) Configure the return result of an action if it is performed- Parameters:
listener- The listener.
-