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

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

Introduction

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

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:Main.java

private static AccessibilityNodeInfoCompat refreshFromChild(AccessibilityNodeInfoCompat node) {
    if (node.getChildCount() > 0) {
        AccessibilityNodeInfoCompat firstChild = node.getChild(0);
        if (firstChild != null) {
            AccessibilityNodeInfoCompat parent = firstChild.getParent();
            firstChild.recycle();/*from w w  w.  j  ava2 s  .  co m*/
            if (node.equals(parent)) {
                return parent;
            } else {
                recycleNodes(parent);
            }
        }
    }
    return null;
}

From source file:Main.java

private static AccessibilityNodeInfoCompat refreshFromParent(AccessibilityNodeInfoCompat node) {
    AccessibilityNodeInfoCompat parent = node.getParent();
    if (parent != null) {
        try {/* www  .  ja v a  2s  . co  m*/
            int childCount = parent.getChildCount();
            for (int i = 0; i < childCount; ++i) {
                AccessibilityNodeInfoCompat child = parent.getChild(i);
                if (node.equals(child)) {
                    return child;
                }
                recycleNodes(child);
            }
        } finally {
            parent.recycle();
        }
    }
    return null;
}

From source file:com.android.screenspeak.controller.TextCursorControllerApp.java

private void processTextSelectionChange(AccessibilityEvent event) {
    AccessibilityNodeInfo node = event.getSource();
    if (node == null) {
        clear();//from www .j a va 2  s  .  c  o  m
        return;
    }

    AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node);
    if (compat.equals(mNode)) {
        mPreviousCursorPosition = mCurrentCursorPosition;
        mCurrentCursorPosition = event.getToIndex();
    } else {
        clear();
        mNode = compat;
        mCurrentCursorPosition = event.getToIndex();
    }
}

From source file:com.android.screenspeak.formatter.CheckableClickedFormatter.java

private boolean findClickedCheckableNode(AccessibilityNodeInfoCompat source) {
    if (source == null)
        return false;

    if (source.equals(mClickedNode)) {
        boolean ret = findCheckableNode(source);
        if (mClickedNode != null) {
            mClickedNode.recycle();/*from  w  ww  .  j a v  a  2 s  . c  om*/
            mClickedNode = null;
        }

        mClickedTime = -1;
        return ret;
    }

    int children = source.getChildCount();
    for (int i = 0; i < children; i++) {
        AccessibilityNodeInfoCompat node = source.getChild(i);
        if (findClickedCheckableNode(node)) {
            if (!sCachedCheckableNode.equals(node)) {
                node.recycle();
            }
            return true;
        }

        if (node != null) {
            node.recycle();
        }
    }

    return false;
}

From source file:com.android.utils.traversal.OrderedTraversalController.java

/**
 * This method is called before moving subtree. It checks if parent of that node was moved
 * on its place because it has before property to that node. In that case parent node should
 * be moved with movingTree node.// w w w  . ja v  a  2s .  co m
 * @return top node that should be moved with movingTree node.
 */
private WorkingTree getParentsThatAreMovedBeforeOrSameNode(WorkingTree movingTree) {
    WorkingTree parent = movingTree.getParent();
    if (parent == null) {
        return movingTree;
    }

    AccessibilityNodeInfoCompat parentNode = parent.getNode();
    AccessibilityNodeInfoCompat parentNodeBefore = getTraversalBefore(parentNode);
    if (parentNodeBefore == null) {
        return movingTree;
    }

    if (parentNodeBefore.equals(movingTree.getNode())) {
        return getParentsThatAreMovedBeforeOrSameNode(parent);
    }

    return movingTree;
}

From source file:com.google.android.marvin.mytalkback.formatter.TouchExplorationFormatter.java

/**
 * Computes a focused node based on the device's supported APIs and the
 * event type./*from  w w w.  j a v a 2 s  . c  o m*/
 *
 * @param eventType The event type.
 * @param sourceNode The source node.
 * @return The focused node, or {@code null} to drop the event.
 */
private AccessibilityNodeInfoCompat getFocusedNode(int eventType, AccessibilityNodeInfoCompat sourceNode) {
    if (sourceNode == null) {
        return null;
    }

    // On Jelly Bean, use the source node of accessibility focus events and
    // discard all other event types.
    if (SUPPORTS_A11Y_FOCUS) {
        if (eventType != AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
            return null;
        }

        return AccessibilityNodeInfoCompat.obtain(sourceNode);
    }

    // On previous versions, simulate accessibility focus by computing a
    // focused node for hover enter events and discard all other events.
    if (eventType != AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER) {
        return null;
    }

    final AccessibilityNodeInfoCompat focusedNode = AccessibilityNodeInfoUtils.findFocusFromHover(mContext,
            sourceNode);

    // If the focused node already has accessibility focus, abort.
    if ((focusedNode != null) && focusedNode.equals(mLastFocusedNode)) {
        AccessibilityNodeInfoUtils.recycleNodes(focusedNode);
        return null;
    }

    // Cache the current focus target for later comparison.
    if (mLastFocusedNode != null) {
        mLastFocusedNode.recycle();
    }

    if (focusedNode != null) {
        mLastFocusedNode = AccessibilityNodeInfoCompat.obtain(focusedNode);
    } else {
        // TODO(alanv): Calling AccessibilityNodeInfoCompat.obtain(null)
        // should return null. Is there a bug in the support library?
        mLastFocusedNode = null;
    }

    // Since API <16 doesn't support accessibility focus, we need to fake it
    // by keeping track of the most recently explored view.
    // TODO(alanv): Add global support for keeping track of fake A11y focus.
    ProgressBarFormatter.updateRecentlyExplored(focusedNode);

    return focusedNode;
}

From source file:com.google.android.marvin.mytalkback.speechrules.NodeSpeechRuleProcessor.java

private void appendDescriptionForTree(AccessibilityNodeInfoCompat announcedNode, SpannableStringBuilder builder,
        AccessibilityEvent event, AccessibilityNodeInfoCompat source) {
    if (announcedNode == null) {
        return;/*from   w  w w .j a va 2 s.c om*/
    }

    // Append the full description for the root node.
    final AccessibilityEvent nodeEvent = (announcedNode.equals(source)) ? event : null;
    final CharSequence nodeDesc = getDescriptionForNode(announcedNode, nodeEvent);
    if (!TextUtils.isEmpty(nodeDesc)) {
        StringBuilderUtils.appendWithSeparator(builder, nodeDesc);

        appendMetadataToBuilder(announcedNode, builder);

        // Setting a content description overrides subtree descriptions.
        final CharSequence announcedDescription = announcedNode.getContentDescription();
        if (!TextUtils.isEmpty(announcedDescription)) {
            return;
        }
    }

    // Recursively append descriptions for visible and non-focusable child nodes.
    final TreeSet<AccessibilityNodeInfoCompat> children = getSortedChildren(announcedNode);
    for (AccessibilityNodeInfoCompat child : children) {
        if (AccessibilityNodeInfoUtils.isVisibleOrLegacy(child)
                && !AccessibilityNodeInfoUtils.isAccessibilityFocusable(mContext, child)) {
            appendDescriptionForTree(child, builder, event, source);
        }
    }

    AccessibilityNodeInfoUtils.recycleNodes(children);
}

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

private AccessibilityNodeInfoCompat findInputFocus() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        List<AccessibilityWindowInfo> awis = mService.getWindows();
        for (AccessibilityWindowInfo awi : awis) {
            if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD)
                continue;
            AccessibilityNodeInfo info = awi.getRoot();
            if (info == null)
                continue;
            AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(awi.getRoot());
            AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
            if (focus != null) {
                if (!root.equals(focus))
                    root.recycle();/*from w  w w  .  j av  a 2 s . c om*/
                return focus;
            } else {
                root.recycle();
            }
        }
        return null;
    } else {
        AccessibilityNodeInfo info = mService.getRootInActiveWindow();
        if (info == null)
            return null;
        AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(info);
        AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (focus != null && !focus.equals(root))
            root.recycle();
        return focus;
    }
}

From source file:com.google.android.marvin.mytalkback.formatter.ProgressBarFormatter.java

private boolean shouldDropEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final AccessibilityNodeInfoCompat source = record.getSource();

    // Don't drop if we're on pre-ICS or the event was generated (e.g.
    // missing a node).
    if (source == null) {
        return false;
    }/*  w w  w .j a  v a  2s .c  o  m*/

    // Don't drop if the node is currently focused or accessibility focused.
    if (source.isFocused() || source.isAccessibilityFocused()) {
        return false;
    }

    // Don't drop if the node was recently explored.
    if (source.equals(sRecentlyExplored)) {
        return false;
    }

    return true;
}

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

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();

    if ((eventType == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER)
            || (eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START)) {
        mIsTouchExploring = true;/*from   ww  w. j ava 2s  .c  o m*/
    }

    if (eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END) {
        mIsTouchExploring = false;
        cacheEnteredNode(null);
        cancelLongHover();
        return;
    }

    if (!mIsTouchExploring
            || ((eventType != TRIGGER_ACTION) && (eventType != AccessibilityEvent.TYPE_VIEW_HOVER_EXIT))) {
        return;
    }

    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final AccessibilityNodeInfoCompat source = record.getSource();

    if (source == null) {
        return;
    }

    if (eventType == TRIGGER_ACTION) {
        cacheEnteredNode(source);
        postLongHoverRunnable(event);
    } else if (eventType == AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT) {
        if (source.equals(mWaitingForExit)) {
            cancelLongHover();
        }
    }

    source.recycle();
}