Search in sources :

Example 36 with AccessibilityNodeInfo

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

the class AccessibilityInteractionController method applyAppScaleAndMagnificationSpecIfNeeded.

private void applyAppScaleAndMagnificationSpecIfNeeded(List<AccessibilityNodeInfo> infos, MagnificationSpec spec) {
    if (infos == null) {
        return;
    }
    final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale;
    if (shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) {
        final int infoCount = infos.size();
        for (int i = 0; i < infoCount; i++) {
            AccessibilityNodeInfo info = infos.get(i);
            applyAppScaleAndMagnificationSpecIfNeeded(info, spec);
        }
    }
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Point(android.graphics.Point)

Example 37 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by ResurrectionRemix.

the class TextView method onInitializeAccessibilityNodeInfoInternal.

/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfoInternal(info);
    final boolean isPassword = hasPasswordTransformationMethod();
    info.setPassword(isPassword);
    info.setText(getTextForAccessibility());
    if (mBufferType == BufferType.EDITABLE) {
        info.setEditable(true);
        if (isEnabled()) {
            info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT);
        }
    }
    if (mEditor != null) {
        info.setInputType(mEditor.mInputType);
        if (mEditor.mError != null) {
            info.setContentInvalid(true);
            info.setError(mEditor.mError);
        }
    }
    if (!TextUtils.isEmpty(mText)) {
        info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
        info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
        info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
        info.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION);
    }
    if (isFocused()) {
        if (canCopy()) {
            info.addAction(AccessibilityNodeInfo.ACTION_COPY);
        }
        if (canPaste()) {
            info.addAction(AccessibilityNodeInfo.ACTION_PASTE);
        }
        if (canCut()) {
            info.addAction(AccessibilityNodeInfo.ACTION_CUT);
        }
        if (canShare()) {
            info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACCESSIBILITY_ACTION_SHARE, getResources().getString(com.android.internal.R.string.share)));
        }
        if (canProcessText()) {
            // also implies mEditor is not null.
            mEditor.mProcessTextIntentActionsHandler.onInitializeAccessibilityNodeInfo(info);
        }
    }
    // Check for known input filter types.
    final int numFilters = mFilters.length;
    for (int i = 0; i < numFilters; i++) {
        final InputFilter filter = mFilters[i];
        if (filter instanceof InputFilter.LengthFilter) {
            info.setMaxTextLength(((InputFilter.LengthFilter) filter).getMax());
        }
    }
    if (!isSingleLine()) {
        info.setMultiLine(true);
    }
}
Also used : InputFilter(android.text.InputFilter) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 38 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by ResurrectionRemix.

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 39 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by ResurrectionRemix.

the class ListView method layoutChildren.

@Override
protected void layoutChildren() {
    final boolean blockLayoutRequests = mBlockLayoutRequests;
    if (blockLayoutRequests) {
        return;
    }
    mBlockLayoutRequests = true;
    try {
        super.layoutChildren();
        invalidate();
        if (mAdapter == null) {
            resetList();
            invokeOnItemScrollListener();
            return;
        }
        final int childrenTop = mListPadding.top;
        final int childrenBottom = mBottom - mTop - mListPadding.bottom;
        final int childCount = getChildCount();
        int index = 0;
        int delta = 0;
        View sel;
        View oldSel = null;
        View oldFirst = null;
        View newSel = null;
        // Remember stuff we will need down below
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                index = mNextSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    newSel = getChildAt(index);
                }
                break;
            case LAYOUT_FORCE_TOP:
            case LAYOUT_FORCE_BOTTOM:
            case LAYOUT_SPECIFIC:
            case LAYOUT_SYNC:
                break;
            case LAYOUT_MOVE_SELECTION:
            default:
                // Remember the previously selected view
                index = mSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    oldSel = getChildAt(index);
                }
                // Remember the previous first child
                oldFirst = getChildAt(0);
                if (mNextSelectedPosition >= 0) {
                    delta = mNextSelectedPosition - mSelectedPosition;
                }
                // Caution: newSel might be null
                newSel = getChildAt(index + delta);
        }
        boolean dataChanged = mDataChanged;
        if (dataChanged) {
            handleDataChanged();
        }
        // and calling it a day
        if (mItemCount == 0) {
            resetList();
            invokeOnItemScrollListener();
            return;
        } else if (mItemCount != mAdapter.getCount()) {
            throw new IllegalStateException("The content of the adapter has changed but " + "ListView did not receive a notification. Make sure the content of " + "your adapter is not modified from a background thread, but only from " + "the UI thread. Make sure your adapter calls notifyDataSetChanged() " + "when its content changes. [in ListView(" + getId() + ", " + getClass() + ") with Adapter(" + mAdapter.getClass() + ")]");
        }
        setSelectedPositionInt(mNextSelectedPosition);
        AccessibilityNodeInfo accessibilityFocusLayoutRestoreNode = null;
        View accessibilityFocusLayoutRestoreView = null;
        int accessibilityFocusPosition = INVALID_POSITION;
        // Remember which child, if any, had accessibility focus. This must
        // occur before recycling any views, since that will clear
        // accessibility focus.
        final ViewRootImpl viewRootImpl = getViewRootImpl();
        if (viewRootImpl != null) {
            final View focusHost = viewRootImpl.getAccessibilityFocusedHost();
            if (focusHost != null) {
                final View focusChild = getAccessibilityFocusedChild(focusHost);
                if (focusChild != null) {
                    if (!dataChanged || isDirectChildHeaderOrFooter(focusChild) || focusChild.hasTransientState() || mAdapterHasStableIds) {
                        // The views won't be changing, so try to maintain
                        // focus on the current host and virtual view.
                        accessibilityFocusLayoutRestoreView = focusHost;
                        accessibilityFocusLayoutRestoreNode = viewRootImpl.getAccessibilityFocusedVirtualView();
                    }
                    // If all else fails, maintain focus at the same
                    // position.
                    accessibilityFocusPosition = getPositionForView(focusChild);
                }
            }
        }
        View focusLayoutRestoreDirectChild = null;
        View focusLayoutRestoreView = null;
        // Take focus back to us temporarily to avoid the eventual call to
        // clear focus when removing the focused child below from messing
        // things up when ViewAncestor assigns focus back to someone else.
        final View focusedChild = getFocusedChild();
        if (focusedChild != null) {
            // header or footer.
            if (!dataChanged || isDirectChildHeaderOrFooter(focusedChild) || focusedChild.hasTransientState() || mAdapterHasStableIds) {
                focusLayoutRestoreDirectChild = focusedChild;
                // Remember the specific view that had focus.
                focusLayoutRestoreView = findFocus();
                if (focusLayoutRestoreView != null) {
                    // Tell it we are going to mess with it.
                    focusLayoutRestoreView.dispatchStartTemporaryDetach();
                }
            }
            requestFocus();
        }
        // Pull all children into the RecycleBin.
        // These views will be reused if possible
        final int firstPosition = mFirstPosition;
        final RecycleBin recycleBin = mRecycler;
        if (dataChanged) {
            for (int i = 0; i < childCount; i++) {
                recycleBin.addScrapView(getChildAt(i), firstPosition + i);
            }
        } else {
            recycleBin.fillActiveViews(childCount, firstPosition);
        }
        // Clear out old views
        detachAllViewsFromParent();
        recycleBin.removeSkippedScrap();
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                if (newSel != null) {
                    sel = fillFromSelection(newSel.getTop(), childrenTop, childrenBottom);
                } else {
                    sel = fillFromMiddle(childrenTop, childrenBottom);
                }
                break;
            case LAYOUT_SYNC:
                sel = fillSpecific(mSyncPosition, mSpecificTop);
                break;
            case LAYOUT_FORCE_BOTTOM:
                sel = fillUp(mItemCount - 1, childrenBottom);
                adjustViewsUpOrDown();
                break;
            case LAYOUT_FORCE_TOP:
                mFirstPosition = 0;
                sel = fillFromTop(childrenTop);
                adjustViewsUpOrDown();
                break;
            case LAYOUT_SPECIFIC:
                final int selectedPosition = reconcileSelectedPosition();
                sel = fillSpecific(selectedPosition, mSpecificTop);
                /**
                 * When ListView is resized, FocusSelector requests an async selection for the
                 * previously focused item to make sure it is still visible. If the item is not
                 * selectable, it won't regain focus so instead we call FocusSelector
                 * to directly request focus on the view after it is visible.
                 */
                if (sel == null && mFocusSelector != null) {
                    final Runnable focusRunnable = mFocusSelector.setupFocusIfValid(selectedPosition);
                    if (focusRunnable != null) {
                        post(focusRunnable);
                    }
                }
                break;
            case LAYOUT_MOVE_SELECTION:
                sel = moveSelection(oldSel, newSel, delta, childrenTop, childrenBottom);
                break;
            default:
                if (childCount == 0) {
                    if (!mStackFromBottom) {
                        final int position = lookForSelectablePosition(0, true);
                        setSelectedPositionInt(position);
                        sel = fillFromTop(childrenTop);
                    } else {
                        final int position = lookForSelectablePosition(mItemCount - 1, false);
                        setSelectedPositionInt(position);
                        sel = fillUp(mItemCount - 1, childrenBottom);
                    }
                } else {
                    if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
                        sel = fillSpecific(mSelectedPosition, oldSel == null ? childrenTop : oldSel.getTop());
                    } else if (mFirstPosition < mItemCount) {
                        sel = fillSpecific(mFirstPosition, oldFirst == null ? childrenTop : oldFirst.getTop());
                    } else {
                        sel = fillSpecific(0, childrenTop);
                    }
                }
                break;
        }
        // Flush any cached views that did not get reused above
        recycleBin.scrapActiveViews();
        // remove any header/footer that has been temp detached and not re-attached
        removeUnusedFixedViews(mHeaderViewInfos);
        removeUnusedFixedViews(mFooterViewInfos);
        if (sel != null) {
            // focusable.
            if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
                final boolean focusWasTaken = (sel == focusLayoutRestoreDirectChild && focusLayoutRestoreView != null && focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
                if (!focusWasTaken) {
                    // Selected item didn't take focus, but we still want to
                    // make sure something else outside of the selected view
                    // has focus.
                    final View focused = getFocusedChild();
                    if (focused != null) {
                        focused.clearFocus();
                    }
                    positionSelector(INVALID_POSITION, sel);
                } else {
                    sel.setSelected(false);
                    mSelectorRect.setEmpty();
                }
            } else {
                positionSelector(INVALID_POSITION, sel);
            }
            mSelectedTop = sel.getTop();
        } else {
            final boolean inTouchMode = mTouchMode == TOUCH_MODE_TAP || mTouchMode == TOUCH_MODE_DONE_WAITING;
            if (inTouchMode) {
                // If the user's finger is down, select the motion position.
                final View child = getChildAt(mMotionPosition - mFirstPosition);
                if (child != null) {
                    positionSelector(mMotionPosition, child);
                }
            } else if (mSelectorPosition != INVALID_POSITION) {
                // If we had previously positioned the selector somewhere,
                // put it back there. It might not match up with the data,
                // but it's transitioning out so it's not a big deal.
                final View child = getChildAt(mSelectorPosition - mFirstPosition);
                if (child != null) {
                    positionSelector(mSelectorPosition, child);
                }
            } else {
                // Otherwise, clear selection.
                mSelectedTop = 0;
                mSelectorRect.setEmpty();
            }
            // restore focus (i.e. something focusable in touch mode).
            if (hasFocus() && focusLayoutRestoreView != null) {
                focusLayoutRestoreView.requestFocus();
            }
        }
        // Attempt to restore accessibility focus, if necessary.
        if (viewRootImpl != null) {
            final View newAccessibilityFocusedView = viewRootImpl.getAccessibilityFocusedHost();
            if (newAccessibilityFocusedView == null) {
                if (accessibilityFocusLayoutRestoreView != null && accessibilityFocusLayoutRestoreView.isAttachedToWindow()) {
                    final AccessibilityNodeProvider provider = accessibilityFocusLayoutRestoreView.getAccessibilityNodeProvider();
                    if (accessibilityFocusLayoutRestoreNode != null && provider != null) {
                        final int virtualViewId = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityFocusLayoutRestoreNode.getSourceNodeId());
                        provider.performAction(virtualViewId, AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                    } else {
                        accessibilityFocusLayoutRestoreView.requestAccessibilityFocus();
                    }
                } else if (accessibilityFocusPosition != INVALID_POSITION) {
                    // Bound the position within the visible children.
                    final int position = MathUtils.constrain(accessibilityFocusPosition - mFirstPosition, 0, getChildCount() - 1);
                    final View restoreView = getChildAt(position);
                    if (restoreView != null) {
                        restoreView.requestAccessibilityFocus();
                    }
                }
            }
        }
        // our view hierarchy.
        if (focusLayoutRestoreView != null && focusLayoutRestoreView.getWindowToken() != null) {
            focusLayoutRestoreView.dispatchFinishTemporaryDetach();
        }
        mLayoutMode = LAYOUT_NORMAL;
        mDataChanged = false;
        if (mPositionScrollAfterLayout != null) {
            post(mPositionScrollAfterLayout);
            mPositionScrollAfterLayout = null;
        }
        mNeedSync = false;
        setNextSelectedPositionInt(mSelectedPosition);
        updateScrollIndicators();
        if (mItemCount > 0) {
            checkSelectionChanged();
        }
        invokeOnItemScrollListener();
    } finally {
        if (mFocusSelector != null) {
            mFocusSelector.onLayoutComplete();
        }
        if (!blockLayoutRequests) {
            mBlockLayoutRequests = false;
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) RemoteView(android.widget.RemoteViews.RemoteView) View(android.view.View) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider) Paint(android.graphics.Paint)

Example 40 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by ResurrectionRemix.

the class ExploreByTouchHelper method createNodeForHost.

/**
     * Constructs and returns an {@link AccessibilityNodeInfo} for the
     * host view populated with its virtual descendants.
     *
     * @return An {@link AccessibilityNodeInfo} for the parent node.
     */
private AccessibilityNodeInfo createNodeForHost() {
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(mView);
    mView.onInitializeAccessibilityNodeInfo(node);
    final int realNodeCount = node.getChildCount();
    // Allow the client to populate the host node.
    onPopulateNodeForHost(node);
    // Add the virtual descendants.
    if (mTempArray == null) {
        mTempArray = new IntArray();
    } else {
        mTempArray.clear();
    }
    final IntArray virtualViewIds = mTempArray;
    getVisibleVirtualViews(virtualViewIds);
    if (realNodeCount > 0 && virtualViewIds.size() > 0) {
        throw new RuntimeException("Views cannot have both real and virtual children");
    }
    final int N = virtualViewIds.size();
    for (int i = 0; i < N; i++) {
        node.addChild(mView, virtualViewIds.get(i));
    }
    return node;
}
Also used : IntArray(android.util.IntArray) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Aggregations

AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)310 Point (android.graphics.Point)84 Rect (android.graphics.Rect)84 AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)45 RemoteException (android.os.RemoteException)30 IAccessibilityInteractionConnectionCallback (android.view.accessibility.IAccessibilityInteractionConnectionCallback)30 SomeArgs (com.android.internal.os.SomeArgs)30 Region (android.graphics.Region)25 Paint (android.graphics.Paint)19 View (android.view.View)12 ViewRootImpl (android.view.ViewRootImpl)11 RemoteView (android.widget.RemoteViews.RemoteView)11 Display (android.view.Display)10 File (java.io.File)10 LinkedList (java.util.LinkedList)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 UiAutomation (android.app.UiAutomation)5 InputFilter (android.text.InputFilter)5 TextPaint (android.text.TextPaint)5