Example usage for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD

List of usage examples for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD.

Prototype

int ACTION_SCROLL_BACKWARD

To view the source code for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD.

Click Source Link

Document

Action to scroll the node content backward.

Usage

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

private boolean onPanLeftOverflowInternal(DisplayManager.Content content) {
    AccessibilityNodeInfoCompat currentNode = null;
    AccessibilityNodeInfoCompat firstNode = null;
    try {/*from   www  .  ja  v a  2s .co  m*/
        // If the currently focused node is a web view, we attempt
        // to delegate navigation to the web view first.
        currentNode = getFocusedNode(true);
        if (currentNode != null && WebInterfaceUtils.hasWebContent(currentNode)
                && WebInterfaceUtils.performNavigationAtGranularityAction(currentNode, DIRECTION_BACKWARD,
                        AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE)) {
            return true;
        }

        // Check if we need to scroll.
        if (autoScrollItem(currentNode, AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD)) {
            return true;
        }

        firstNode = AccessibilityNodeInfoUtils.refreshNode(content.getFirstNode());
        // If the content doesn't have a first node, fall back on the
        // currently focused node.
        if (firstNode == null || !firstNode.isVisibleToUser()) {
            AccessibilityNodeInfoUtils.recycleNodes(firstNode);
            firstNode = currentNode;
            currentNode = null;
        }
        if (firstNode == null) {
            return false;
        }
        AccessibilityNodeInfoCompat target = mFocusFinder.linear(firstNode, FocusFinder.SEARCH_BACKWARD);
        return moveFocus(firstNode, DIRECTION_BACKWARD);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(currentNode, firstNode);
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElement.java

ViewHierarchyElement(int id, @Nullable ViewHierarchyElement parent, AccessibilityNodeInfo fromInfo) {
    // Bookkeeping
    this.id = id;
    this.parentId = (parent != null) ? parent.getId() : null;

    // API 18+ properties
    this.resourceName = AT_18 ? fromInfo.getViewIdResourceName() : null;
    this.editable = AT_18 ? fromInfo.isEditable() : null;

    // API 16+ properties
    this.visibleToUser = AT_16 ? fromInfo.isVisibleToUser() : null;

    // Base properties
    this.className = fromInfo.getClassName();
    this.packageName = fromInfo.getPackageName();
    this.accessibilityClassName = fromInfo.getClassName();
    this.contentDescription = SpannableString.valueOf(fromInfo.getContentDescription());
    this.text = SpannableString.valueOf(fromInfo.getText());
    this.importantForAccessibility = true;
    this.clickable = fromInfo.isClickable();
    this.longClickable = fromInfo.isLongClickable();
    this.focusable = fromInfo.isFocusable();
    this.scrollable = fromInfo.isScrollable();
    this.canScrollForward = ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0);
    this.canScrollBackward = ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0);
    this.checkable = fromInfo.isCheckable();
    this.checked = fromInfo.isChecked();
    this.hasTouchDelegate = false; /* Touch delegates are not considered by AccessibilityServices */
    android.graphics.Rect tempRect = new android.graphics.Rect();
    fromInfo.getBoundsInScreen(tempRect);
    this.boundsInScreen = new Rect(tempRect);
    this.nonclippedHeight = null; /* AccessibilityServices cannot discover nonclipped dimensions */
    this.nonclippedWidth = null; /* AccessibilityServices cannot discover nonclipped dimensions */
    this.textSize = null;
    this.textColor = null;
    this.backgroundDrawableColor = null;
    this.typefaceStyle = null;
    this.enabled = fromInfo.isEnabled();
}

From source file:com.android.datetimepicker.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        /**/*w  w w .  j  av  a 2  s. com*/
         * Necessary for accessibility, to ensure we support "scrolling" forward and backward
         * in the circle.
         */
        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    });
}

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

private CharSequence formatNode(AccessibilityNodeInfo node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());// w w  w .ja va  2  s. c o m
    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }
    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }
    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText());
    }
    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription());
    }
    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfo.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
    }
    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }
    if (node.isFocusable()) {
        sb.append(":focusable");
    }
    if (node.isFocused()) {
        sb.append(":focused");
    }
    if (node.isSelected()) {
        sb.append(":selected");
    }
    if (node.isClickable()) {
        sb.append(":clickable");
    }
    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }
    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }
    if (!node.isEnabled()) {
        sb.append(":disabled");
    }
    return sb.toString();
}

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

/**
 * Moves accessibility focus to the first focusable node of the previous
 * 'line'./* w w w . ja v a2 s  .  c o  m*/
 */
private boolean linePreviousInternal(DisplayManager.Content content) {
    AccessibilityNodeInfoRef left = new AccessibilityNodeInfoRef();
    AccessibilityNodeInfoRef right = new AccessibilityNodeInfoRef();
    AccessibilityNodeInfoCompat target = null;
    AccessibilityNodeInfoCompat currentNode = getFocusedNode(true);
    try {
        if (currentNode != null && WebInterfaceUtils.hasWebContent(currentNode)
                && WebInterfaceUtils.performNavigationAtGranularityAction(currentNode, DIRECTION_BACKWARD,
                        AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE)) {
            return true;
        }

        // Check if we need to scroll.
        if (autoScrollItem(currentNode, AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD)) {
            return true;
        }

        AccessibilityNodeInfoRef firstNode = AccessibilityNodeInfoRef.unOwned(content.getFirstNode());
        // If the content doesn't have a first node, fall back on the
        // currently focused node.
        if (AccessibilityNodeInfoRef.isNull(firstNode)) {
            firstNode = AccessibilityNodeInfoRef.owned(currentNode);
            currentNode = null;
        }
        if (AccessibilityNodeInfoRef.isNull(firstNode)) {
            return false;
        }
        // Move backwards one step from the first node that is currently
        // displayed.
        target = mFocusFinder.linear(firstNode.get(), FocusFinder.SEARCH_BACKWARD);
        firstNode.recycle();
        if (target == null) {
            return false;
        }
        // Find what would be covered by the display if target
        // would have accessibility focus.
        mNodeBrailler.findDisplayExtentFromNode(target, left, right);
        // Find the first focusable nodes moving forward from left,
        // i fleft is not focusable itself.
        if (!AccessibilityNodeInfoUtils.shouldFocusNode(mAccessibilityService, left.get())) {
            left.reset(mFocusFinder.linear(left.get(), FocusFinder.SEARCH_FORWARD));
        }
        // If we didn't find a focusable node at the beginning of the
        // line we are trying to move to, just move to target as
        // a fallback.
        if (AccessibilityNodeInfoRef.isNull(left)) {
            left.reset(target);
            target = null;
        }
        return left.get().performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(target, currentNode);
        left.recycle();
        right.recycle();
    }
}

From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java

private int getScrollActionDirection(int scrollAction) {
    if (scrollAction == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        return MOVING_FORWARDS;
    }//from   w  ww. j a  v a  2 s  .co m

    if (scrollAction == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return MOVING_BACKWARDS;
    }

    return MOVING_UNDEFINED_DIRECTION;
}

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

private boolean navigateItem(int direction) {
    AccessibilityNodeInfoCompat currentNode = getFocusedNode(true);
    try {/* w w  w .  j a  va  2s. c om*/
        if (currentNode != null && WebInterfaceUtils.hasWebContent(currentNode)
                && WebInterfaceUtils.performNavigationByDOMObject(currentNode, direction)) {
            return true;
        }
        // Check if we need to scroll.
        int scrollDirection = (direction == DIRECTION_FORWARD) ? AccessibilityNodeInfo.ACTION_SCROLL_FORWARD
                : AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
        if (autoScrollItem(currentNode, scrollDirection)) {
            return true;
        }
        return moveFocus(currentNode, direction);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(currentNode);
    }
}

From source file:com.philliphsu.bottomsheetpickers.date.PagingDayPickerView.java

/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 *//*from w  w w  .j a v a 2 s . c o m*/
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD
            && action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // Figure out what month is showing.
    int firstVisiblePosition = getPagerPosition();
    int month = firstVisiblePosition % 12;
    int year = firstVisiblePosition / 12 + mController.getMinYear();
    CalendarDay day = new CalendarDay(year, month, 1);

    // Scroll either forward or backward one month.
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        View firstVisibleView = getChildAt(0);
        // If the view is fully visible, jump one month back. Otherwise, we'll just jump
        // to the first day of first visible month.
        if (firstVisibleView != null && firstVisibleView.getTop() >= -1) {
            // There's an off-by-one somewhere, so the top of the first visible item will
            // actually be -1 when it's at the exact top.
            day.month--;
            if (day.month == -1) {
                day.month = 11;
                day.year--;
            }
        }
    }

    // Go to that month.
    Utils.tryAccessibilityAnnounce(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    return true;
}

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

@Override
public boolean onMappedInputEvent(BrailleInputEvent event, DisplayManager.Content content) {
    switch (event.getCommand()) {
    case BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS:
        return itemPrevious();
    case BrailleInputEvent.CMD_NAV_ITEM_NEXT:
        return itemNext();
    case BrailleInputEvent.CMD_NAV_LINE_PREVIOUS:
        return linePrevious(content);
    case BrailleInputEvent.CMD_NAV_LINE_NEXT:
        return lineNext(content);
    case BrailleInputEvent.CMD_ACTIVATE_CURRENT:
        // Activate the current node, but don't fall back on the
        // root if focus is cleared.
        return mFeedbackManager.emitOnFailure(activateNode(getFocusedNode(false)),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_LONG_PRESS_CURRENT:
        // Long click the current node, but don't fall back on the
        // root if focus is cleared.
        return mFeedbackManager.emitOnFailure(longClickNode(getFocusedNode(false)),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_ROUTE: {
        AccessibilityNodeInfoCompat node = DisplaySpans.getAccessibilityNodeFromPosition(event.getArgument(),
                content.getText());//w  w w .  jav a  2  s . c om
        return mFeedbackManager.emitOnFailure(activateNode(node, event.getArgument()),
                FeedbackManager.TYPE_COMMAND_FAILED);
    }
    case BrailleInputEvent.CMD_LONG_PRESS_ROUTE: {
        AccessibilityNodeInfoCompat node = DisplaySpans.getAccessibilityNodeFromPosition(event.getArgument(),
                content.getText());
        return mFeedbackManager.emitOnFailure(longClickNode(node), FeedbackManager.TYPE_COMMAND_FAILED);
    }
    case BrailleInputEvent.CMD_SCROLL_FORWARD:
        return mFeedbackManager.emitOnFailure(attemptScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_SCROLL_BACKWARD:
        return mFeedbackManager.emitOnFailure(attemptScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_NAV_TOP:
        return mFeedbackManager.emitOnFailure(attemptNavigateTop(), FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_NAV_BOTTOM:
        return mFeedbackManager.emitOnFailure(attemptNavigateBottom(), FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_SECTION_NEXT:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_FORWARD, HTML_ELEMENT_MOVE_BY_SECTION),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_SECTION_PREVIOUS:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_BACKWARD, HTML_ELEMENT_MOVE_BY_SECTION),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_CONTROL_NEXT:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_FORWARD, HTML_ELEMENT_MOVE_BY_CONTROL),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_CONTROL_PREVIOUS:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_BACKWARD, HTML_ELEMENT_MOVE_BY_CONTROL),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_LIST_NEXT:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_FORWARD, HTML_ELEMENT_MOVE_BY_LIST),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_LIST_PREVIOUS:
        return mFeedbackManager.emitOnFailure(
                navigateHTMLElementAction(DIRECTION_BACKWARD, HTML_ELEMENT_MOVE_BY_LIST),
                FeedbackManager.TYPE_COMMAND_FAILED);
    case BrailleInputEvent.CMD_TOGGLE_INCREMENTAL_SEARCH:
        return handleIncrementalSearchAction();
    }
    return false;
}

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

/**
 * Listens to accessibility actions performed by the parent service.
 *
 * @param action The action performed.//  www  .ja  v  a  2 s.  c om
 */
public void onActionPerformed(int action) {
    switch (action) {
    case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
    case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
        setScrollActionImmediately(action);
        break;
    }
}