Search in sources :

Example 31 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project android_frameworks_base by AOSPA.

the class AccessibilityInteractionController method findAccessibilityNodeInfosByTextUiThread.

private void findAccessibilityNodeInfosByTextUiThread(Message message) {
    final int flags = message.arg1;
    SomeArgs args = (SomeArgs) message.obj;
    final String text = (String) args.arg1;
    final IAccessibilityInteractionConnectionCallback callback = (IAccessibilityInteractionConnectionCallback) args.arg2;
    final MagnificationSpec spec = (MagnificationSpec) args.arg3;
    final int accessibilityViewId = args.argi1;
    final int virtualDescendantId = args.argi2;
    final int interactionId = args.argi3;
    final Region interactiveRegion = (Region) args.arg4;
    args.recycle();
    List<AccessibilityNodeInfo> infos = null;
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) {
            root = findViewByAccessibilityId(accessibilityViewId);
        } else {
            root = mViewRootImpl.mView;
        }
        if (root != null && isShown(root)) {
            AccessibilityNodeProvider provider = root.getAccessibilityNodeProvider();
            if (provider != null) {
                if (virtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) {
                    infos = provider.findAccessibilityNodeInfosByText(text, virtualDescendantId);
                } else {
                    infos = provider.findAccessibilityNodeInfosByText(text, AccessibilityNodeProvider.HOST_VIEW_ID);
                }
            } else if (virtualDescendantId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) {
                ArrayList<View> foundViews = mTempArrayList;
                foundViews.clear();
                root.findViewsWithText(foundViews, text, View.FIND_VIEWS_WITH_TEXT | View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION | View.FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS);
                if (!foundViews.isEmpty()) {
                    infos = mTempAccessibilityNodeInfoList;
                    infos.clear();
                    final int viewCount = foundViews.size();
                    for (int i = 0; i < viewCount; i++) {
                        View foundView = foundViews.get(i);
                        if (isShown(foundView)) {
                            provider = foundView.getAccessibilityNodeProvider();
                            if (provider != null) {
                                List<AccessibilityNodeInfo> infosFromProvider = provider.findAccessibilityNodeInfosByText(text, AccessibilityNodeProvider.HOST_VIEW_ID);
                                if (infosFromProvider != null) {
                                    infos.addAll(infosFromProvider);
                                }
                            } else {
                                infos.add(foundView.createAccessibilityNodeInfo());
                            }
                        }
                    }
                }
            }
        }
    } finally {
        try {
            mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0;
            applyAppScaleAndMagnificationSpecIfNeeded(infos, spec);
            // system process and obtained from a pool when read from parcel.
            if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) {
                spec.recycle();
            }
            adjustIsVisibleToUserIfNeeded(infos, interactiveRegion);
            callback.setFindAccessibilityNodeInfosResult(infos, interactionId);
        } catch (RemoteException re) {
        /* ignore - the other side will time out */
        }
        // the system process and instantiated  when read from parcel.
        if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) {
            interactiveRegion.recycle();
        }
    }
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) ArrayList(java.util.ArrayList) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Point(android.graphics.Point) IAccessibilityInteractionConnectionCallback(android.view.accessibility.IAccessibilityInteractionConnectionCallback) SomeArgs(com.android.internal.os.SomeArgs) Region(android.graphics.Region) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RemoteException(android.os.RemoteException)

Example 32 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project android_frameworks_base by AOSPA.

the class ViewRootImpl method requestSendAccessibilityEvent.

@Override
public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) {
    if (mView == null || mStopped || mPausedForTransition) {
        return false;
    }
    // Intercept accessibility focus events fired by virtual nodes to keep
    // track of accessibility focus position in such nodes.
    final int eventType = event.getEventType();
    switch(eventType) {
        case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
            {
                final long sourceNodeId = event.getSourceNodeId();
                final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId(sourceNodeId);
                View source = mView.findViewByAccessibilityId(accessibilityViewId);
                if (source != null) {
                    AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider();
                    if (provider != null) {
                        final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId(sourceNodeId);
                        final AccessibilityNodeInfo node;
                        if (virtualNodeId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) {
                            node = provider.createAccessibilityNodeInfo(AccessibilityNodeProvider.HOST_VIEW_ID);
                        } else {
                            node = provider.createAccessibilityNodeInfo(virtualNodeId);
                        }
                        setAccessibilityFocus(source, node);
                    }
                }
            }
            break;
        case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
            {
                final long sourceNodeId = event.getSourceNodeId();
                final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId(sourceNodeId);
                View source = mView.findViewByAccessibilityId(accessibilityViewId);
                if (source != null) {
                    AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider();
                    if (provider != null) {
                        setAccessibilityFocus(null, null);
                    }
                }
            }
            break;
        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
            {
                handleWindowContentChangedEvent(event);
            }
            break;
    }
    mAccessibilityManager.sendAccessibilityEvent(event);
    return true;
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Point(android.graphics.Point)

Example 33 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project android_frameworks_base by AOSPA.

the class ViewRootImpl method handleWindowContentChangedEvent.

/**
     * Updates the focused virtual view, when necessary, in response to a
     * content changed event.
     * <p>
     * This is necessary to get updated bounds after a position change.
     *
     * @param event an accessibility event of type
     *              {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED}
     */
private void handleWindowContentChangedEvent(AccessibilityEvent event) {
    final View focusedHost = mAccessibilityFocusedHost;
    if (focusedHost == null || mAccessibilityFocusedVirtualView == null) {
        // No virtual view focused, nothing to do here.
        return;
    }
    final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider();
    if (provider == null) {
        // Error state: virtual view with no provider. Clear focus.
        mAccessibilityFocusedHost = null;
        mAccessibilityFocusedVirtualView = null;
        focusedHost.clearAccessibilityFocusNoCallbacks(0);
        return;
    }
    // We only care about change types that may affect the bounds of the
    // focused virtual view.
    final int changes = event.getContentChangeTypes();
    if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) {
        return;
    }
    final long eventSourceNodeId = event.getSourceNodeId();
    final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId);
    // Search up the tree for subtree containment.
    boolean hostInSubtree = false;
    View root = mAccessibilityFocusedHost;
    while (root != null && !hostInSubtree) {
        if (changedViewId == root.getAccessibilityViewId()) {
            hostInSubtree = true;
        } else {
            final ViewParent parent = root.getParent();
            if (parent instanceof View) {
                root = (View) parent;
            } else {
                root = null;
            }
        }
    }
    // We care only about changes in subtrees containing the host view.
    if (!hostInSubtree) {
        return;
    }
    final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId();
    int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId);
    if (focusedChildId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) {
        // TODO: Should we clear the focused virtual view?
        focusedChildId = AccessibilityNodeProvider.HOST_VIEW_ID;
    }
    // Refresh the node for the focused virtual view.
    final Rect oldBounds = mTempRect;
    mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds);
    mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId);
    if (mAccessibilityFocusedVirtualView == null) {
        // Error state: The node no longer exists. Clear focus.
        mAccessibilityFocusedHost = null;
        focusedHost.clearAccessibilityFocusNoCallbacks(0);
        // This will probably fail, but try to keep the provider's internal
        // state consistent by clearing focus.
        provider.performAction(focusedChildId, AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null);
        invalidateRectOnScreen(oldBounds);
    } else {
        // The node was refreshed, invalidate bounds if necessary.
        final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen();
        if (!oldBounds.equals(newBounds)) {
            oldBounds.union(newBounds);
            invalidateRectOnScreen(oldBounds);
        }
    }
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Point(android.graphics.Point)

Example 34 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project android_frameworks_base by AOSPA.

the class ViewRootImpl method setAccessibilityFocus.

void setAccessibilityFocus(View view, AccessibilityNodeInfo node) {
    // to clear the focus and invalidate the virtual view bounds.
    if (mAccessibilityFocusedVirtualView != null) {
        AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView;
        View focusHost = mAccessibilityFocusedHost;
        // Wipe the state of the current accessibility focus since
        // the call into the provider to clear accessibility focus
        // will fire an accessibility event which will end up calling
        // this method and we want to have clean state when this
        // invocation happens.
        mAccessibilityFocusedHost = null;
        mAccessibilityFocusedVirtualView = null;
        // Clear accessibility focus on the host after clearing state since
        // this method may be reentrant.
        focusHost.clearAccessibilityFocusNoCallbacks(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider();
        if (provider != null) {
            // Invalidate the area of the cleared accessibility focus.
            focusNode.getBoundsInParent(mTempRect);
            focusHost.invalidate(mTempRect);
            // Clear accessibility focus in the virtual node.
            final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId(focusNode.getSourceNodeId());
            provider.performAction(virtualNodeId, AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null);
        }
        focusNode.recycle();
    }
    if ((mAccessibilityFocusedHost != null) && (mAccessibilityFocusedHost != view)) {
        // Clear accessibility focus in the view.
        mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    // Set the new focus host and node.
    mAccessibilityFocusedHost = view;
    mAccessibilityFocusedVirtualView = node;
    if (mAttachInfo.mHardwareRenderer != null) {
        mAttachInfo.mHardwareRenderer.invalidateRoot();
    }
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Point(android.graphics.Point)

Example 35 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project android_frameworks_base by AOSPA.

the class ViewRootImpl method getAccessibilityFocusedRect.

private boolean getAccessibilityFocusedRect(Rect bounds) {
    final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext);
    if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) {
        return false;
    }
    final View host = mAccessibilityFocusedHost;
    if (host == null || host.mAttachInfo == null) {
        return false;
    }
    final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider();
    if (provider == null) {
        host.getBoundsOnScreen(bounds, true);
    } else if (mAccessibilityFocusedVirtualView != null) {
        mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds);
    } else {
        return false;
    }
    // Transform the rect into window-relative coordinates.
    final AttachInfo attachInfo = mAttachInfo;
    bounds.offset(0, attachInfo.mViewRootImpl.mScrollY);
    bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop);
    if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, attachInfo.mViewRootImpl.mHeight)) {
        // If no intersection, set bounds to empty.
        bounds.setEmpty();
    }
    return !bounds.isEmpty();
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AttachInfo(android.view.View.AttachInfo) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider)

Aggregations

AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)63 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)45 Point (android.graphics.Point)36 RemoteException (android.os.RemoteException)18 IAccessibilityInteractionConnectionCallback (android.view.accessibility.IAccessibilityInteractionConnectionCallback)18 SomeArgs (com.android.internal.os.SomeArgs)18 View (android.view.View)11 ViewRootImpl (android.view.ViewRootImpl)11 RemoteView (android.widget.RemoteViews.RemoteView)11 Paint (android.graphics.Paint)10 Region (android.graphics.Region)10 Rect (android.graphics.Rect)7 AccessibilityManager (android.view.accessibility.AccessibilityManager)7 Bundle (android.os.Bundle)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 AttachInfo (android.view.View.AttachInfo)5 LinkedList (java.util.LinkedList)5 Drawable (android.graphics.drawable.Drawable)2