Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat performAction

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat performAction

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat performAction.

Prototype

public boolean performAction(int action) 

Source Link

Document

Performs an action on the node.

Usage

From source file:com.android.utils.PerformActionUtils.java

public static boolean performAction(AccessibilityNodeInfoCompat node, int action) {
    if (node == null) {
        return false;
    }/*from  w w w .  ja  va  2 s.com*/

    logPerformAction(node, action);

    return node.performAction(action);
}

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.WebInterfaceUtils.java

/**
 * Sends an instruction to ChromeVox to navigate by DOM object in
 * the given direction within a node.//from  w  w  w.j  av a  2s .  co  m
 *
 * @param node The node containing web content with ChromeVox to which the
 *            message should be sent
 * @param direction {@link #DIRECTION_FORWARD} or
 *            {@link #DIRECTION_BACKWARD}
 * @return {@code true} if the action was performed, {@code false}
 *         otherwise.
 */
public static boolean performNavigationByDOMObject(AccessibilityNodeInfoCompat node, int direction) {
    final int action = (direction == DIRECTION_FORWARD) ? AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT
            : AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT;
    return node.performAction(action);
}

From source file:com.google.android.marvin.mytalkback.CursorController.java

/**
 * Attempts to navigate the node using HTML navigation.
 *
 * @param node/*from  ww  w .j av  a  2s  .  c  om*/
 * @param direction The direction to navigate, one of:
 *            <ul>
 *            <li>{@link #NAVIGATION_DIRECTION_NEXT}</li>
 *            <li>{@link #NAVIGATION_DIRECTION_PREVIOUS}</li>
 *            </ul>
 * @return {@code true} if navigation succeeded.
 */
private static boolean attemptHtmlNavigation(AccessibilityNodeInfoCompat node, int direction) {
    final int action = (direction == NAVIGATION_DIRECTION_NEXT)
            ? AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT
            : AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT;
    return node.performAction(action);
}

From source file:com.googlecode.eyesfree.brailleback.SearchNavigationModeTest.java

public void testDeleteKey() throws Exception {
    // Set initial focus.
    AccessibilityNodeInfoCompat initial = getNodeForId(R.id.button1);
    initial.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);

    mSearchNavMode.setInitialNodeToCurrent();
    mSearchNavMode.onActivate();//from  w  ww.java2  s.  co m

    AccessibilityNodeInfoCompat root = getNodeForId(R.id.top);
    assertNotNull(root);

    // Search and focus a result.
    mSearchNavMode.setQueryTextForTest("xy");
    sendInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT);
    assertFocusedNodeText("xyy", root);

    // Test delete.
    sendInputEvent(BrailleInputEvent.CMD_KEY_DEL);
    assertEquals("x", mSearchNavMode.getQueryTextForTest());
    assertFocusedNodeText("xyy", root);

    // Test a second delete.
    sendInputEvent(BrailleInputEvent.CMD_KEY_DEL);
    assertEquals("", mSearchNavMode.getQueryTextForTest());
    assertFocusedNodeText("xyy", root);

    // Test a third delete. Since the query is empty now, this should escape
    // and bring focus back to the initial node.
    sendInputEvent(BrailleInputEvent.CMD_KEY_DEL);
    assertFalse(mSearchActive);
    AccessibilityNodeInfoCompat focused = getFocusedNode(root);
    assertEquals(initial, focused);
}

From source file:com.googlecode.eyesfree.brailleback.SearchNavigationModeTest.java

public void testToggleOff() throws Exception {
    // Set initial focus.
    AccessibilityNodeInfoCompat initial = getNodeForId(R.id.button1);
    assertTrue(initial.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS));

    mSearchNavMode.setInitialNodeToCurrent();
    mSearchNavMode.onActivate();/*from   w  w w  .ja va 2s. c o m*/

    AccessibilityNodeInfoCompat root = getNodeForId(R.id.top);
    assertNotNull(root);

    // Search for a node.
    mSearchNavMode.setQueryTextForTest("xy");
    sendInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT);
    assertFocusedNodeText("xyy", root);

    // Test toggling off. Should reset focus back to the initial.
    sendInputEvent(BrailleInputEvent.CMD_TOGGLE_INCREMENTAL_SEARCH);
    assertFalse(mSearchActive);
    AccessibilityNodeInfoCompat focused = getFocusedNode(root);
    assertEquals(initial, focused);
}

From source file:com.googlecode.eyesfree.brailleback.FocusTracker.java

/**
 * Sets the accessibility focus to the node that currently has
 * input focus, if accessibility focus is not already set
 * in the currently focused window.//from  w ww.j a v  a  2  s .  co  m
 */
private void setFocusFromInput() {
    AccessibilityNodeInfoCompat root = AccessibilityServiceCompatUtils
            .getRootInActiveWindow(mAccessibilityService);
    if (root == null) {
        return;
    }
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    try {
        accessibilityFocused = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        if (accessibilityFocused != null) {
            return;
        }
        inputFocused = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (inputFocused == null
                || !AccessibilityNodeInfoUtils.shouldFocusNode(mAccessibilityService, inputFocused)) {
            return;
        }
        inputFocused.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, inputFocused, accessibilityFocused);
    }
}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

@MediumTest
public void testQuickRefocusSameNode_eventDropped() {
    final SeekBar seekBar = (SeekBar) getViewForId(R.id.seek_bar);
    final AccessibilityNodeInfoCompat seekBarNode = getNodeForView(seekBar);

    getService().getCursorController().setCursor(seekBarNode);
    waitForAccessibilityIdleSync();//w ww .  ja v  a2 s  . c o m

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(seekBarNode);

    seekBarNode.performAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    seekBarNode.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    waitForAccessibilityIdleSync();

    assertFalse(mMatched);
}

From source file:com.google.android.marvin.mytalkback.CursorController.java

/**
 * Sets the current cursor position./*  ww w.j  a va2 s .c  o m*/
 *
 * @param node The node to set as the cursor.
 * @return {@code true} if successful.
 */
public boolean setCursor(AccessibilityNodeInfoCompat node) {
    return node.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
}

From source file:com.google.android.marvin.mytalkback.CursorController.java

/**
 * Performs the specified action on the current cursor.
 *
 * @param action The action to perform on the current cursor.
 * @return {@code true} if successful.//from   w  ww.  j av  a  2  s.  c  om
 */
private boolean performAction(int action) {
    AccessibilityNodeInfoCompat current = null;

    try {
        current = getCursor();
        if (current == null) {
            return false;
        }

        return current.performAction(action);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(current);
    }
}

From source file:com.googlecode.eyesfree.brailleback.DefaultNavigationMode.java

private boolean moveFocus(AccessibilityNodeInfoCompat from, int direction) {
    int searchDirection = (direction == DIRECTION_BACKWARD) ? FocusFinder.SEARCH_BACKWARD
            : FocusFinder.SEARCH_FORWARD;
    AccessibilityNodeInfoCompat next = null;
    next = mFocusFinder.linear(from, searchDirection);
    try {// w w  w .  ja v  a  2 s  .  c o m
        if (next != null) {
            return next.performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        }
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(next);
    }
    return false;
}