コード例 #1
0
  @Test
  public void lastDescentWithChildren_shouldReturnTrueAndSetItselfForLastChildren() {
    AccessibilityNodeInfo parentNode = AccessibilityNodeInfo.obtain();
    parentNode.setVisibleToUser(true);
    parentNode.setContentDescription("Parent");
    AccessibilityNodeInfo child1Node = AccessibilityNodeInfo.obtain();
    child1Node.setVisibleToUser(true);
    child1Node.setContentDescription("Child1");
    AccessibilityNodeInfo child2Node = AccessibilityNodeInfo.obtain();
    child2Node.setVisibleToUser(true);
    child2Node.setContentDescription("Child2");

    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(child1Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(child2Node);

    AccessibilityNodeInfoCompat parentCompat = new AccessibilityNodeInfoCompat(parentNode);

    AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(parentCompat);
    System.out.println("lastDescentWithChildren_shouldReturnTrueAndSetItselfForLastChildren");
    assertTrue(ref.lastDescendant());
    assertEquals(child2Node, ref.get().getInfo());
    parentNode.recycle();
    child1Node.recycle();
    child2Node.recycle();
    ref.recycle();
  }
コード例 #2
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);
  }
コード例 #3
0
  @Test
  public void parentWithSelfReferencedParent_shouldReturnFalse() {
    AccessibilityNodeInfo curNode = AccessibilityNodeInfo.obtain();
    curNode.setVisibleToUser(true);
    AccessibilityNodeInfo parentNode = AccessibilityNodeInfo.obtain();
    parentNode.setVisibleToUser(true);

    curNode.setContentDescription("Current");
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(curNode)).addChild(curNode);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(curNode)).setVisibleToUser(true);

    AccessibilityNodeInfoCompat currentCompat = new AccessibilityNodeInfoCompat(curNode);

    AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(currentCompat);
    assertFalse(ref.parent());
    parentNode.recycle();
    curNode.recycle();
    ref.recycle();
  }
コード例 #4
0
  @Test
  public void parentWithParents_shouldReturnTrueAndSetItselfForParent() {
    AccessibilityNodeInfo currentNode = AccessibilityNodeInfo.obtain();
    currentNode.setVisibleToUser(true);
    AccessibilityNodeInfo parentNode = AccessibilityNodeInfo.obtain();
    parentNode.setVisibleToUser(true);

    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(currentNode);

    AccessibilityNodeInfoCompat currentCompat = new AccessibilityNodeInfoCompat(currentNode);
    AccessibilityNodeInfoCompat parentCompat = new AccessibilityNodeInfoCompat(parentNode);

    AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(currentCompat);
    assertTrue(ref.parent());
    assertEquals(parentCompat, ref.get());
    parentNode.recycle();
    currentNode.recycle();
    ref.recycle();
  }
コード例 #5
0
 private static void sendBrailleText(
     final View view, final String text, final int selectionStart, final int selectionEnd) {
   AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(view, VIRTUAL_CURSOR_POSITION);
   WriteData data = WriteData.forInfo(info);
   data.setText(text);
   // Set either the focus blink or the current caret position/selection
   data.setSelectionStart(selectionStart);
   data.setSelectionEnd(selectionEnd);
   sSelfBrailleClient.write(data);
 }
コード例 #6
0
 @Test
 public void lastDescentWithoutChildren_shouldReturnFalseAndDoNotResetInnerNode() {
   AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
   node.setVisibleToUser(true);
   AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node);
   AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(compat);
   assertFalse(ref.lastDescendant());
   assertEquals(compat, ref.get());
   node.recycle();
   ref.recycle();
 }
コード例 #7
0
  @Test
  public void lastDescentWithLoop_shouldReturnFalse() {
    AccessibilityNodeInfo parentNode = AccessibilityNodeInfo.obtain();
    parentNode.setVisibleToUser(true);
    AccessibilityNodeInfo child1Node = AccessibilityNodeInfo.obtain();
    child1Node.setVisibleToUser(true);
    AccessibilityNodeInfo child2Node = AccessibilityNodeInfo.obtain();
    child2Node.setVisibleToUser(true);

    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(child1Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(child2Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(child2Node)).addChild(parentNode);

    AccessibilityNodeInfoCompat parentCompat = new AccessibilityNodeInfoCompat(parentNode);

    AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(parentCompat);
    assertFalse(ref.lastDescendant());
    parentNode.recycle();
    child1Node.recycle();
    child2Node.recycle();
    ref.recycle();
  }
コード例 #8
0
  @Test
  public void parentWithLoopedParents_shouldReturnFalse() {
    AccessibilityNodeInfo curNode = AccessibilityNodeInfo.obtain();
    curNode.setVisibleToUser(true);
    AccessibilityNodeInfo parentNode = AccessibilityNodeInfo.obtain();
    parentNode.setVisibleToUser(true);

    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).addChild(curNode);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(curNode)).addChild(parentNode);

    /* Set nodes to be invisible to force the the code to traverse the loop */
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parentNode)).setVisibleToUser(false);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(curNode)).setVisibleToUser(false);

    AccessibilityNodeInfoCompat currentCompat = new AccessibilityNodeInfoCompat(curNode);

    AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.obtain(currentCompat);
    assertFalse(ref.parent());
    parentNode.recycle();
    curNode.recycle();
    ref.recycle();
  }
コード例 #9
0
 public Object a(Object paramObject) {
   return AccessibilityNodeInfo.obtain((AccessibilityNodeInfo) paramObject);
 }
コード例 #10
0
  public static void sendAccessibilityEvent(final JSONObject message) {
    if (!sEnabled) return;

    final int eventType = message.optInt("eventType", -1);
    if (eventType < 0) {
      Log.e(LOGTAG, "No accessibility event type provided");
      return;
    }

    if (Versions.preJB) {
      // Before Jelly Bean we send events directly from here while spoofing the source by setting
      // the package and class name manually.
      ThreadUtils.postToBackgroundThread(
          new Runnable() {
            @Override
            public void run() {
              sendDirectAccessibilityEvent(eventType, message);
            }
          });
    } else {
      // In Jelly Bean we populate an AccessibilityNodeInfo with the minimal amount of data to have
      // it work with TalkBack.
      final LayerView view = GeckoAppShell.getLayerView();
      if (view == null) return;

      if (sVirtualCursorNode == null)
        sVirtualCursorNode = AccessibilityNodeInfo.obtain(view, VIRTUAL_CURSOR_POSITION);
      sVirtualCursorNode.setEnabled(message.optBoolean("enabled", true));
      sVirtualCursorNode.setClickable(message.optBoolean("clickable"));
      sVirtualCursorNode.setCheckable(message.optBoolean("checkable"));
      sVirtualCursorNode.setChecked(message.optBoolean("checked"));
      sVirtualCursorNode.setPassword(message.optBoolean("password"));

      final JSONArray textArray = message.optJSONArray("text");
      StringBuilder sb = new StringBuilder();
      if (textArray != null && textArray.length() > 0) {
        sb.append(textArray.optString(0));
        for (int i = 1; i < textArray.length(); i++) {
          sb.append(" ").append(textArray.optString(i));
        }
      }
      sVirtualCursorNode.setText(sb.toString());
      sVirtualCursorNode.setContentDescription(message.optString("description"));

      JSONObject bounds = message.optJSONObject("bounds");
      if (bounds != null) {
        Rect relativeBounds =
            new Rect(
                bounds.optInt("left"), bounds.optInt("top"),
                bounds.optInt("right"), bounds.optInt("bottom"));
        sVirtualCursorNode.setBoundsInParent(relativeBounds);
        int[] locationOnScreen = new int[2];
        view.getLocationOnScreen(locationOnScreen);
        Rect screenBounds = new Rect(relativeBounds);
        screenBounds.offset(locationOnScreen[0], locationOnScreen[1]);
        sVirtualCursorNode.setBoundsInScreen(screenBounds);
      }

      final JSONObject braille = message.optJSONObject("brailleOutput");
      if (braille != null) {
        sendBrailleText(
            view,
            braille.optString("text"),
            braille.optInt("selectionStart"),
            braille.optInt("selectionEnd"));
      }

      ThreadUtils.postToUiThread(
          new Runnable() {
            @Override
            public void run() {
              // If this is an accessibility focus, a lot of internal voodoo happens so we perform
              // an
              // accessibility focus action on the view, and it in turn sends the right events.
              switch (eventType) {
                case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
                  sEventMessage = message;
                  view.performAccessibilityAction(
                      AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                  break;
                case AccessibilityEvent.TYPE_ANNOUNCEMENT:
                case AccessibilityEvent.TYPE_VIEW_SCROLLED:
                  sEventMessage = null;
                  final AccessibilityEvent accEvent = AccessibilityEvent.obtain(eventType);
                  view.onInitializeAccessibilityEvent(accEvent);
                  populateEventFromJSON(accEvent, message);
                  view.getParent().requestSendAccessibilityEvent(view, accEvent);
                  break;
                default:
                  sEventMessage = message;
                  view.sendAccessibilityEvent(eventType);
                  break;
              }
            }
          });
    }
  }
コード例 #11
0
ファイル: F.java プロジェクト: KashaMalaga/MiFit-Java
 public static Object a(View view, int i) {
   return AccessibilityNodeInfo.obtain(view, i);
 }