Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#obtain()

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#obtain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @see AccessibilityNodeProvider#createAccessibilityNodeInfo(int)
 */
protected AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0 || !mFrameInfoInitialized) {
        return null;
    }

    int rootId = nativeGetRootId(mNativeObj);
    if (virtualViewId == View.NO_ID) {
        virtualViewId = rootId;
    }
    if (mAccessibilityFocusId == View.NO_ID) {
        mAccessibilityFocusId = rootId;
    }

    final AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(mView);
    info.setPackageName(mContentViewCore.getContext().getPackageName());
    info.setSource(mView, virtualViewId);

    if (nativePopulateAccessibilityNodeInfo(mNativeObj, info, virtualViewId)) {
        return info;
    } else {
        return null;
    }
}
 
Example 2
Source File: AbstractCustomVirtualView.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
protected AccessibilityNodeInfo provideAccessibilityNodeInfo(View parent, Context context) {
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
    node.setSource(parent, id);
    node.setPackageName(context.getPackageName());
    node.setClassName(getClassName());
    node.setEditable(editable);
    node.setViewIdResourceName(idEntry);
    node.setVisibleToUser(true);
    final Rect absBounds = line.getAbsCoordinates();
    if (absBounds != null) {
        node.setBoundsInScreen(absBounds);
    }
    if (TextUtils.getTrimmedLength(text) > 0) {
        // TODO: Must checked trimmed length because input fields use 8 empty spaces to
        // set width
        node.setText(text);
    }
    return node;
}
 
Example 3
Source File: CustomVirtualViewCompatMode.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
private AccessibilityNodeInfo onProvideAutofillCompatModeAccessibilityNodeInfo() {
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();

    final String packageName = getContext().getPackageName();
    node.setPackageName(packageName);
    node.setClassName(getClass().getName());

    final int childrenSize = mVirtualViews.size();
    for (int i = 0; i < childrenSize; i++) {
        final Item item = mVirtualViews.valueAt(i);
        if (DEBUG) {
            Log.d(TAG, "Adding new A11Y child with id " + item.id + ": " + item);
        }
        node.addChild(this, item.id);
    }
    return node;
}
 
Example 4
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @see AccessibilityNodeProvider#createAccessibilityNodeInfo(int)
 */
protected AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0 || !mFrameInfoInitialized) {
        return null;
    }

    int rootId = nativeGetRootId(mNativeObj);
    if (virtualViewId == View.NO_ID) {
        virtualViewId = rootId;
    }
    if (mAccessibilityFocusId == View.NO_ID) {
        mAccessibilityFocusId = rootId;
    }

    final AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(mView);
    info.setPackageName(mContentViewCore.getContext().getPackageName());
    info.setSource(mView, virtualViewId);

    if (nativePopulateAccessibilityNodeInfo(mNativeObj, info, virtualViewId)) {
        return info;
    } else {
        return null;
    }
}
 
Example 5
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
        String text, int left, int top, int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(Button.class.getName());
    info.setPackageName(mContext.getPackageName());
    info.setSource(NumberPicker.this, virtualViewId);
    info.setParent(NumberPicker.this);
    info.setText(text);
    info.setClickable(true);
    info.setLongClickable(true);
    info.setEnabled(NumberPicker.this.isEnabled());
    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    info.setVisibleToUser(isVisibleToUser(boundsInParent));
    info.setBoundsInParent(boundsInParent);
    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    info.setBoundsInScreen(boundsInScreen);

    if (mAccessibilityFocusedView != virtualViewId) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == virtualViewId) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    if (NumberPicker.this.isEnabled()) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
    }

    return info;
}
 
Example 6
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
private void checkFocusedNode_PreLollipop(AccessibilityNodeInfo node) {
    //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) return;
    //need to keep that anyway if we want to find focus in WebViews
    synchronized (mSEMAPHORE_FocusedNode_PreLollipop) {

        if (node.isFocused()) {
            mFocusedNode_PreLollipop_INTRANSACTION = AccessibilityNodeInfo.obtain(node);
        }
    }
}
 
Example 7
Source File: WriteData.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns a new {@link WriteData} instance for the given {@code view}.
 */
public static WriteData forView(View view) {
    AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(view);
    WriteData writeData = new WriteData();
    writeData.mAccessibilityNodeInfo = node;
    return writeData;
}
 
Example 8
Source File: CustomLabelManager.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Label} and persists it to the label database, and
 * refreshes the label cache.
 * <p>
 * NOTE: This method will not attempt to recycle {@code node}.
 *
 * @param node The node to label
 * @param userLabel The label provided for the node by the user
 */
public void addLabel(AccessibilityNodeInfo node, String userLabel) {
    if (node == null) {
        throw new IllegalArgumentException("Attempted to add a label for a null node.");
    }

    final AccessibilityNodeInfo internalNodeCopy = AccessibilityNodeInfo.obtain(node);
    addLabel(internalNodeCopy.getViewIdResourceName(), userLabel);
    internalNodeCopy.recycle();
}
 
Example 9
Source File: TextPicker.java    From GifAssistant with Apache License 2.0 4 votes vote down vote up
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
                                                                         int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(TextPicker.class.getName());
    info.setPackageName(getContext().getPackageName());
    info.setSource(TextPicker.this);

    if (hasVirtualDecrementButton()) {
        info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
    }
    info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (hasVirtualIncrementButton()) {
        info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
    }

    info.setParent((View) getParentForAccessibility());
    info.setEnabled(TextPicker.this.isEnabled());
    info.setScrollable(true);

    /** TODO: Figure out compat implementation for this
     final float applicationScale =
     getContext().getResources().getCompatibilityInfo().applicationScale;

     Rect boundsInParent = mTempRect;
     boundsInParent.set(left, top, right, bottom);
     boundsInParent.scale(applicationScale);
     info.setBoundsInParent(boundsInParent);

     info.setVisibleToUser(isVisibleToUser());

     Rect boundsInScreen = boundsInParent;
     int[] locationOnScreen = mTempArray;
     getLocationOnScreen(locationOnScreen);
     boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
     boundsInScreen.scale(applicationScale);
     info.setBoundsInScreen(boundsInScreen);
     */

    if (mAccessibilityFocusedView != View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    if (TextPicker.this.isEnabled()) {
        if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        }
        if (getWrapSelectorWheel() || getValue() > getMinValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    }

    return info;
}
 
Example 10
Source File: MultiSlider.java    From MultiSlider with Apache License 2.0 4 votes vote down vote up
@Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int thumbId) {
    AccessibilityNodeInfo info = null;
    if (thumbId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree. Note that the
        // host View has an AccessibilityNodeProvider which means that this
        // provider is responsible for creating the node info for that root.
        info = AccessibilityNodeInfo.obtain(MultiSlider.this);
        onInitializeAccessibilityNodeInfo(info);
        // Add the virtual children of the root View.
        final int childCount = mThumbs.size();
        for (int i = 0; i < childCount; i++) {
            info.addChild(MultiSlider.this, i);
        }
        if (mThumbs.size() == 1) {
            info.setScrollable(true);
            if (Build.VERSION.SDK_INT >= 21) {
                info.addAction(ACTION_SET_PROGRESS);
                info.addAction(ACTION_SCROLL_BACKWARD);
                info.addAction(ACTION_SCROLL_FORWARD);
            } else {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }

        }

    } else {
        // Find the view that corresponds to the given id.
        Thumb thumb = mThumbs.get(thumbId);
        if (thumb == null) {
            return null;
        }
        // Obtain and initialize an AccessibilityNodeInfo with
        // information about the virtual view.
        info = AccessibilityNodeInfo.obtain(MultiSlider.this, thumbId);
        info.setClassName(thumb.getClass().getName());
        info.setParent(MultiSlider.this);
        info.setSource(MultiSlider.this, thumbId);
        info.setContentDescription("Multi-Slider thumb no:" + thumbId);

        if (Build.VERSION.SDK_INT >= 21) {
            info.addAction(ACTION_SET_PROGRESS);
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(ACTION_SCROLL_BACKWARD);
            }
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(ACTION_SCROLL_FORWARD);
            }

        } else {
            if (thumb.getPossibleMin() > thumb.value) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (thumb.getPossibleMax() > thumb.value) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }


        if (thumb.getThumb() != null) {
            int[] loc = new int[2];
            getLocationOnScreen(loc);
            Rect rect = thumb.getThumb().copyBounds();
            rect.top += loc[1];
            rect.left += loc[0];
            rect.right += loc[0];
            rect.bottom += loc[1];
            info.setBoundsInScreen(rect);
            //TODO somehow this resuls in [0,0][0,0]. wonder check why
            //info.setBoundsInParent(rect);

        }

        info.setText(thumb.tag + ": " + thumb.value);
        info.setEnabled(thumb.isEnabled());
        if (Build.VERSION.SDK_INT >= 24) {
            info.setImportantForAccessibility(true);
        }
        info.setVisibleToUser(true);
        info.setScrollable(true);
    }
    return info;
}
 
Example 11
Source File: AccessibilityNodeInfoCompatJellyBean.java    From guideshow with MIT License 4 votes vote down vote up
public static Object obtain(View root, int virtualDescendantId) {
    return AccessibilityNodeInfo.obtain(root, virtualDescendantId);
}
 
Example 12
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 4 votes vote down vote up
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
        int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(NumberPicker.class.getName());
    info.setPackageName(getContext().getPackageName());
    info.setSource(NumberPicker.this);

    if (hasVirtualDecrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
    }
    info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (hasVirtualIncrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
    }

    info.setParent((View) getParentForAccessibility());
    info.setEnabled(NumberPicker.this.isEnabled());
    info.setScrollable(true);

    Rect boundsInParent = mTempRect;

    boundsInParent.set(left, top, right, bottom);
    info.setBoundsInParent(boundsInParent);

    info.setVisibleToUser(getVisibility() == View.VISIBLE);

    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    info.setBoundsInScreen(boundsInScreen);

    if (mAccessibilityFocusedView != View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    if (NumberPicker.this.isEnabled()) {
        if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        }
        if (getWrapSelectorWheel() || getValue() > getMinValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    }

    return info;
}
 
Example 13
Source File: AccessibilityNodeInfoCompatIcs.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static Object obtain(Object info) {
    return AccessibilityNodeInfo.obtain((AccessibilityNodeInfo) info);
}
 
Example 14
Source File: AccessibilityNodeInfoCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static Object obtain(Object info) {
    return AccessibilityNodeInfo.obtain((AccessibilityNodeInfo) info);
}
 
Example 15
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/** Safely obtains a copy of node. Caller must recycle returned node info. */
public static AccessibilityNodeInfo obtain(AccessibilityNodeInfo node) {
  return (node == null) ? null : AccessibilityNodeInfo.obtain(node);
}
 
Example 16
Source File: NumberPicker.java    From zen4android with MIT License 4 votes vote down vote up
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
        int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(NumberPicker.class.getName());
    info.setPackageName(getContext().getPackageName());
    info.setSource(NumberPicker.this);

    if (hasVirtualDecrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
    }
    info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (hasVirtualIncrementButton()) {
        info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
    }

    info.setParent((View) getParentForAccessibility());
    info.setEnabled(NumberPicker.this.isEnabled());
    info.setScrollable(true);

    /** TODO: Figure out compat implementation for this
    final float applicationScale =
            getContext().getResources().getCompatibilityInfo().applicationScale;

    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    boundsInParent.scale(applicationScale);
    info.setBoundsInParent(boundsInParent);

    info.setVisibleToUser(isVisibleToUser());

    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    boundsInScreen.scale(applicationScale);
    info.setBoundsInScreen(boundsInScreen);
     */

    if (mAccessibilityFocusedView != View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == View.NO_ID) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    if (NumberPicker.this.isEnabled()) {
        if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        }
        if (getWrapSelectorWheel() || getValue() > getMinValue()) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    }

    return info;
}
 
Example 17
Source File: AccessibilityNodeInfoCompatJellyBean.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static Object obtain(View root, int virtualDescendantId) {
    return AccessibilityNodeInfo.obtain(root, virtualDescendantId);
}
 
Example 18
Source File: AccessibilityNodeInfoCompatIcs.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static Object obtain() {
    return AccessibilityNodeInfo.obtain();
}
 
Example 19
Source File: AccessibilityNodeInfoCompatIcs.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static Object obtain(View source) {
    return AccessibilityNodeInfo.obtain(source);
}
 
Example 20
Source File: AccessibilityNodeInfoCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static Object obtain() {
    return AccessibilityNodeInfo.obtain();
}