Ejemplo n.º 1
0
  @Before
  public void setUp() {
    ShadowAccessibilityNodeInfo.resetObtainedInstances();
    mCompat1 = new SwitchAccessNodeCompat(AccessibilityNodeInfo.obtain());
    mShadowInfo1 =
        (ShadowAccessibilityNodeInfo)
            ShadowExtractor.extract((AccessibilityNodeInfo) mCompat1.getInfo());
    mCompat2 = new SwitchAccessNodeCompat(AccessibilityNodeInfo.obtain());
    mShadowInfo2 =
        (ShadowAccessibilityNodeInfo)
            ShadowExtractor.extract((AccessibilityNodeInfo) mCompat2.getInfo());
    mSharedPreferences.edit().clear().commit();
    MockitoAnnotations.initMocks(this);
    mCompat1.setBoundsInScreen(NODE_BOUNDS_1);
    mCompat2.setBoundsInScreen(NODE_BOUNDS_2);
    mActionNode1 =
        new AccessibilityNodeActionNode(
            mCompat1,
            new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
                AccessibilityNodeInfoCompat.ACTION_CLICK, "label1"));
    mActionNode2 =
        new AccessibilityNodeActionNode(
            mCompat2,
            new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
                AccessibilityNodeInfoCompat.ACTION_CLICK, "label2"));
    mSelectionNode = new OptionScanSelectionNode(mActionNode1, mActionNode2);

    when(mOverlayController.getContext()).thenReturn(mContext);
    mOptionManager = new OptionManager(mOverlayController);
  }
Ejemplo n.º 2
0
 @After
 public void tearDown() {
   if (mSelectionNode != null) {
     mSelectionNode.recycle();
   }
   mCompat1.recycle();
   mCompat2.recycle();
   try {
     assertFalse(ShadowAccessibilityNodeInfo.areThereUnrecycledNodes(true));
   } finally {
     ShadowAccessibilityNodeInfo.resetObtainedInstances();
   }
 }
Ejemplo n.º 3
0
 /**
  * Get the actions associated with the given compat node.
  *
  * @param compat The node whose actions should be obtained.
  * @return A list of {@code AccessibilityNodeActionNodes}, representing all the actions associated
  *     with the specified node. If no actions are associated with the node, an empty list is
  *     returned.
  */
 public static List<AccessibilityNodeActionNode> getCompatActionNodes(
     final SwitchAccessNodeCompat compat) {
   if (!compat.isVisibleToUser()) {
     return new ArrayList<>(0);
   }
   List<AccessibilityNodeActionNode> actionNodes = new ArrayList<>();
   List<AccessibilityNodeInfoCompat.AccessibilityActionCompat> actions = compat.getActionList();
   for (AccessibilityNodeInfoCompat.AccessibilityActionCompat action : actions) {
     if (SUPPORTED_ACTIONS.contains(action.getId())) {
       actionNodes.add(new AccessibilityNodeActionNode(compat, action));
     }
   }
   return actionNodes;
 }
Ejemplo n.º 4
0
 private static boolean nodeHasSupportedAction(SwitchAccessNodeCompat node) {
   List<AccessibilityNodeInfoCompat.AccessibilityActionCompat> actions = node.getActionList();
   for (AccessibilityNodeInfoCompat.AccessibilityActionCompat action : actions) {
     if (SUPPORTED_ACTIONS.contains(action.getId())) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 5
0
 /**
  * Obtain a list of nodes in the order TalkBack would traverse them
  *
  * @param root The root of the tree to traverse
  * @return The nodes in {@code root}'s subtree (including root) in the order TalkBack would
  *     traverse them.
  */
 public static LinkedList<SwitchAccessNodeCompat> getNodesInTalkBackOrder(
     SwitchAccessNodeCompat root) {
   LinkedList<SwitchAccessNodeCompat> outList = new LinkedList<>();
   OrderedTraversalController traversalController = new OrderedTraversalController();
   traversalController.initOrder(root);
   AccessibilityNodeInfoCompat node = traversalController.findFirst();
   while (node != null) {
     outList.add(new SwitchAccessNodeCompat(node.getInfo(), root.getWindowsAbove()));
     node = traversalController.findNext(node);
   }
   traversalController.recycle();
   return outList;
 }
Ejemplo n.º 6
0
 @Test
 public void testScrollWithOneOptionThatSucceeds_shouldScrollAndClearFocus() {
   mCompat1.setScrollable(true);
   mActionNode1.recycle();
   mActionNode1 =
       new AccessibilityNodeActionNode(
           mCompat1,
           new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
               AccessibilityNodeInfoCompat.ACTION_CLICK, "label1"));
   mSelectionNode = new OptionScanSelectionNode(mActionNode1, mActionNode2);
   mOptionManager.clearFocusIfNewTree(mSelectionNode);
   mOptionManager.selectOption(0);
   mOptionManager.performScrollAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
   List<Integer> info1Actions = mShadowInfo1.getPerformedActions();
   assertEquals(1, info1Actions.size());
   assertEquals(
       new Integer(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD), info1Actions.get(0));
   verify(mOverlayController, times(3)).clearOverlay();
 }