Example usage for android.view.accessibility AccessibilityNodeInfo recycle

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

Introduction

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

Prototype

public void recycle() 

Source Link

Document

Return an instance back to be reused.

Usage

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

private boolean shouldIgnoreUpdateListEvent(AccessibilityEvent event) {
    // Don't speak during full-screen read.
    if (mFullScreenReadController.isActive()) {
        return true;
    }//from w ww .j  a v a2  s  . co  m

    final int fromIndex = event.getFromIndex() + 1;
    final int itemCount = event.getItemCount();
    if (itemCount <= 0 || fromIndex <= 0) {
        return true;
    }

    EventId eventId;
    try {
        eventId = new EventId(event);
    } catch (Exception e) {
        return true;
    }

    final Integer cachedFromIndex = mCachedFromValues.get(eventId);
    final Integer cachedItemCount = mCachedItemCounts.get(eventId);

    if ((cachedFromIndex != null) && (cachedFromIndex == fromIndex) && (cachedItemCount != null)
            && (cachedItemCount == itemCount)) {
        // The from index hasn't changed, which means the event is coming
        // from a re-layout or resize and should not be spoken.
        return true;
    }

    // The behavior of put() for an existing key is unspecified, so we can't
    // recycle the old or new key nodes.
    mCachedFromValues.put(eventId, fromIndex);
    mCachedItemCounts.put(eventId, itemCount);

    // Allow the list indices to be cached, but don't actually speak after auto-scroll.
    if (mAutoScrollNode != null) {
        AccessibilityNodeInfo source = event.getSource();
        if (source != null) {
            try {
                if (source.equals(mAutoScrollNode.getInfo())) {
                    mAutoScrollNode.recycle();
                    mAutoScrollNode = null;
                    return true;
                }
            } finally {
                source.recycle();
            }
        }
    }

    return false;
}

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

private AccessibilityNodeInfo getLastDescendantDfs(AccessibilityNodeInfo from) {
    AccessibilityNodeInfo lastChild = getLastChild(from);
    if (lastChild == null) {
        return null;
    }//  w  w  w  .  j  av a2 s.c  o  m
    while (true) {
        AccessibilityNodeInfo lastGrandChild = getLastChild(lastChild);
        if (lastGrandChild != null) {
            lastChild.recycle();
            lastChild = lastGrandChild;
        } else {
            break;
        }
    }
    return lastChild;
}

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

private boolean movePrevious() {
    if (mCurrentNode == null) {
        return false;
    }/*from   w  ww  .ja v  a2  s  . c o m*/
    AccessibilityNodeInfo target = null;
    int feedbackType = FeedbackManager.TYPE_NONE;
    AccessibilityNodeInfo prevSibling = getPreviousSibling(mCurrentNode);
    if (prevSibling != null) {
        target = getLastDescendantDfs(prevSibling);
        if (target != null) {
            feedbackType = FeedbackManager.TYPE_NAVIGATE_INTO_HIERARCHY;
            prevSibling.recycle();
            prevSibling = null;
        } else {
            target = prevSibling;
        }
    }
    if (target == null) {
        target = mCurrentNode.getParent();
        if (target != null) {
            feedbackType = FeedbackManager.TYPE_NAVIGATE_OUT_OF_HIERARCHY;
        }
    }
    return moveTo(target, feedbackType);
}

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

private boolean moveNext() {
    if (mCurrentNode == null) {
        return false;
    }// w w  w  .j a  v a2  s .  c  o m
    int feedbackType = FeedbackManager.TYPE_NONE;
    AccessibilityNodeInfo target = getFirstChild(mCurrentNode);
    if (target != null) {
        feedbackType = FeedbackManager.TYPE_NAVIGATE_INTO_HIERARCHY;
    } else {
        target = getNextSibling(mCurrentNode);
    }
    if (target == null) {
        AccessibilityNodeInfo ancestor = mCurrentNode.getParent();
        int cnt = 1;
        while (target == null && ancestor != null) {
            target = getNextSibling(ancestor);
            if (target == null) {
                AccessibilityNodeInfo temp = ancestor.getParent();
                ancestor.recycle();
                ancestor = temp;
                cnt += 1;
            } else {
                ancestor.recycle();
                ancestor = null;
            }
        }
        if (target != null) {
            feedbackType = FeedbackManager.TYPE_NAVIGATE_OUT_OF_HIERARCHY;
        }
    }
    return moveTo(target, feedbackType);
}

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

private AccessibilityNodeInfo getNextSibling(AccessibilityNodeInfo from) {
    AccessibilityNodeInfo parent = from.getParent();
    if (parent == null) {
        return null;
    }//from w  w  w  .  j  av  a 2 s .c  o m
    AccessibilityNodeInfo cur = null;
    try {
        int childCount = parent.getChildCount();
        for (int i = 0; i < childCount - 1; ++i) {
            cur = parent.getChild(i);
            if (cur == null) {
                return null;
            }
            if (cur.equals(from)) {
                return parent.getChild(i + 1);
            }
            if (cur != null) {
                cur.recycle();
                cur = null;
            }
        }
    } finally {
        parent.recycle();
        if (cur != null) {
            cur.recycle();
        }
    }
    return null;
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

private void findPgpNodeInfo(AccessibilityNodeInfo parent, ArrayList<AccessibilityNodeInfo> pgpNodes) {

    for (int i = 0; i < parent.getChildCount(); i++) {
        AccessibilityNodeInfo currentChild = parent.getChild(i);

        /*/*from   w  w  w .  j  a  v  a 2s  . c  o m*/
         WebView
         |- WebView
        |- View
        |- View
        |- View
         */
        if (WEB_VIEW_CLASS_NAME.equals(parent.getClassName())
                && VIEW_CLASS_NAME.equals(currentChild.getClassName())
                && !TextUtils.isEmpty(currentChild.getContentDescription())
                && currentChild.getContentDescription().toString().startsWith(BEGIN_PGP_MESSAGE)) {

            pgpNodes.add(currentChild);
        } else {
            // recursive traversal
            findPgpNodeInfo(currentChild, pgpNodes);

            currentChild.recycle();
        }
    }
}

From source file:com.android.talkback.formatter.TouchExplorationFormatter.java

/**
 * Resets cached scrollable state when touch exploration after window state
 * changes./*from  www.jav a 2  s .c o  m*/
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Reset cached scrollable state.
        mLastNodeWasScrollable = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Store window title in the map.
            List<CharSequence> titles = event.getText();
            if (titles.size() > 0) {
                AccessibilityNodeInfo node = event.getSource();
                if (node != null) {
                    int windowType = getWindowType(node);
                    if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION
                            || windowType == AccessibilityWindowInfo.TYPE_SYSTEM) {
                        mWindowTitlesMap.put(node.getWindowId(), titles.get(0));
                    }
                    node.recycle();
                }
            }
        }
        break;
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Copy key set not to modify original map.
            HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>();
            windowIdsToBeRemoved.addAll(mWindowTitlesMap.keySet());

            // Enumerate window ids to be removed.
            List<AccessibilityWindowInfo> windows = mService.getWindows();
            for (AccessibilityWindowInfo window : windows) {
                windowIdsToBeRemoved.remove(window.getId());
            }

            // Delete titles of non-existing window ids.
            for (Integer windowId : windowIdsToBeRemoved) {
                mWindowTitlesMap.remove(windowId);
            }
        }
        break;
    }
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

/**
 * ??/*from ww  w  . ja  va2  s . c o m*/
 *
 * @param event
 * @param className
 * @param sourceText
 */
private void processAlertDialogEvent(AccessibilityEvent event, String className, String sourceText) {
    Timber.d("");
    String eventText = event.getText().toString();

    if (eventText.contains(getString(R.string.str_accessibility_error))) {
        onInstallFail(event);
    } else if (!eventText.contains(getString(R.string.str_accessibility_uninstall))) {
        AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.btn_accessibility_ok));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
        }
    } else if (eventText.contains(getString(R.string.str_accessibility_replace))
            || eventText.contains(getString(R.string.str_accessibility_replace1))) {
        AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.btn_accessibility_ok));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
        }
    }
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

/**
 * /*from   www  .  j  ava2s .  co  m*/
 *
 * @param event Accessibility ?
 * @param nodeClassName ???
 * @param maybeValidate ??
 * @param isRetry ??
 */
private void onApplicationInstall(final AccessibilityEvent event, final String nodeClassName,
        final boolean maybeValidate, boolean isRetry) {
    Timber.d("");

    // ????
    handler.postDelayed(handleInstallTimeout, INSTALL_TIMEOUT);

    if (!maybeValidate || isValidPackageEvent(event, sInstallList)) {
        AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.btn_accessibility_install));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
            return;
        }
        nodeInfo = getAccessibilityNodeInfoByText(event, getString(R.string.btn_accessibility_allow_once));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            nodeInfo.recycle();
            return;
        }
        nodeInfo = getAccessibilityNodeInfoByText(event, getString(R.string.btn_accessibility_next));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            onApplicationInstall(event);
            nodeInfo.recycle();
        }
        nodeInfo = getAccessibilityNodeInfoByText(event,
                getString(R.string.str_accessibility_replace_continue));
        if (nodeInfo != null) {
            performClick(nodeInfo);
            onApplicationInstall(event);
            nodeInfo.recycle();
        }

        // ?????
        if (nodeInfo == null && !isRetry) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    onApplicationInstall(event, nodeClassName, maybeValidate, true);
                }
            }, INSTALL_RETRY_INTERVAL);
        }
    }

}

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

private AccessibilityNodeInfo getPreviousSibling(AccessibilityNodeInfo from) {
    AccessibilityNodeInfo ret = null;/*w w w . ja  va  2 s  .c o m*/
    AccessibilityNodeInfo parent = from.getParent();
    if (parent == null) {
        return null;
    }
    AccessibilityNodeInfo prev = null;
    AccessibilityNodeInfo cur = null;
    try {
        int childCount = parent.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            cur = parent.getChild(i);
            if (cur == null) {
                return null;
            }
            if (cur.equals(from)) {
                ret = prev;
                prev = null;
                return ret;
            }
            if (prev != null) {
                prev.recycle();
            }
            prev = cur;
            cur = null;
        }
    } finally {
        parent.recycle();
        if (prev != null) {
            prev.recycle();
        }
        if (cur != null) {
            cur.recycle();
        }
    }
    return ret;
}