Search in sources :

Example 16 with AccessibilityNodeProvider

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

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();
        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) {
        // Clear accessibility focus in the view.
        mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks();
    }
    // Set the new focus host and node.
    mAccessibilityFocusedHost = view;
    mAccessibilityFocusedVirtualView = node;
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 17 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project platform_frameworks_base by android.

the class View method createAccessibilityNodeInfoInternal.

/**
     * @see #createAccessibilityNodeInfo()
     *
     * @hide
     */
public AccessibilityNodeInfo createAccessibilityNodeInfoInternal() {
    AccessibilityNodeProvider provider = getAccessibilityNodeProvider();
    if (provider != null) {
        return provider.createAccessibilityNodeInfo(AccessibilityNodeProvider.HOST_VIEW_ID);
    } else {
        AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this);
        onInitializeAccessibilityNodeInfo(info);
        return info;
    }
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider)

Example 18 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project platform_frameworks_base by android.

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 19 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project platform_frameworks_base by android.

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)

Example 20 with AccessibilityNodeProvider

use of android.view.accessibility.AccessibilityNodeProvider in project platform_frameworks_base by android.

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)

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