android.view.accessibility.AccessibilityNodeInfo#setVisibleToUser ( )源码实例Demo

下面列出了android.view.accessibility.AccessibilityNodeInfo#setVisibleToUser ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: input-samples   文件: AbstractCustomVirtualView.java
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;
}
 
源代码2 项目: android_9.0.0_r45   文件: NumberPicker.java
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
        int left, int top, int right, int bottom) {
    AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
    info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    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);
    return info;
}
 
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;
}
 
源代码4 项目: NewXmPluginSDK   文件: NumberPicker.java
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
        int left, int top, int right, int bottom) {
    AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
    info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    info.setVisibleToUser(getVisibility() == View.VISIBLE);
    info.setBoundsInParent(boundsInParent);
    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    info.setBoundsInScreen(boundsInScreen);
    return info;
}
 
源代码5 项目: Dashchan   文件: DrawerLayout.java
/**
 * This should really be in AccessibilityNodeInfoCompat, but there unfortunately
 * seem to be a few elements that are not easily cloneable using the underlying API.
 * Leave it private here as it's not general-purpose useful.
 */
private void copyNodeInfoNoChildren(AccessibilityNodeInfo dest, AccessibilityNodeInfo src) {
	final Rect rect = mTmpRect;

	src.getBoundsInParent(rect);
	dest.setBoundsInParent(rect);

	src.getBoundsInScreen(rect);
	dest.setBoundsInScreen(rect);

	dest.setVisibleToUser(src.isVisibleToUser());
	dest.setPackageName(src.getPackageName());
	dest.setClassName(src.getClassName());
	dest.setContentDescription(src.getContentDescription());

	dest.setEnabled(src.isEnabled());
	dest.setClickable(src.isClickable());
	dest.setFocusable(src.isFocusable());
	dest.setFocused(src.isFocused());
	dest.setAccessibilityFocused(src.isAccessibilityFocused());
	dest.setSelected(src.isSelected());
	dest.setLongClickable(src.isLongClickable());

	dest.addAction(src.getActions());
}
 
private void adjustIsVisibleToUserIfNeeded(AccessibilityNodeInfo info,
        Region interactiveRegion) {
    if (interactiveRegion == null || info == null) {
        return;
    }
    Rect boundsInScreen = mTempRect;
    info.getBoundsInScreen(boundsInScreen);
    if (interactiveRegion.quickReject(boundsInScreen)) {
        info.setVisibleToUser(false);
    }
}
 
源代码7 项目: android_9.0.0_r45   文件: NumberPicker.java
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;
}
 
源代码8 项目: android_9.0.0_r45   文件: SimpleMonthView.java
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node) {
    final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect);

    if (!hasBounds) {
        // The day is invalid, kill the node.
        mTempRect.setEmpty();
        node.setContentDescription("");
        node.setBoundsInParent(mTempRect);
        node.setVisibleToUser(false);
        return;
    }

    node.setText(getDayText(virtualViewId));
    node.setContentDescription(getDayDescription(virtualViewId));
    node.setBoundsInParent(mTempRect);

    final boolean isDayEnabled = isDayEnabled(virtualViewId);
    if (isDayEnabled) {
        node.addAction(AccessibilityAction.ACTION_CLICK);
    }

    node.setEnabled(isDayEnabled);

    if (virtualViewId == mActivatedDay) {
        // TODO: This should use activated once that's supported.
        node.setChecked(true);
    }

}
 
源代码9 项目: NewXmPluginSDK   文件: NumberPicker.java
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(getContext().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(getVisibility() == View.VISIBLE);
    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;
}
 
源代码10 项目: 365browser   文件: BrowserAccessibilityManager.java
private AccessibilityNodeInfo createNodeForHost(int rootId) {
    // Since we don't want the parent to be focusable, but we can't remove
    // actions from a node, copy over the necessary fields.
    final AccessibilityNodeInfo result = AccessibilityNodeInfo.obtain(mView);
    final AccessibilityNodeInfo source = AccessibilityNodeInfo.obtain(mView);
    mView.onInitializeAccessibilityNodeInfo(source);

    // Copy over parent and screen bounds.
    Rect rect = new Rect();
    source.getBoundsInParent(rect);
    result.setBoundsInParent(rect);
    source.getBoundsInScreen(rect);
    result.setBoundsInScreen(rect);

    // Set up the parent view, if applicable.
    final ViewParent parent = mView.getParentForAccessibility();
    if (parent instanceof View) {
        result.setParent((View) parent);
    }

    // Populate the minimum required fields.
    result.setVisibleToUser(source.isVisibleToUser());
    result.setEnabled(source.isEnabled());
    result.setPackageName(source.getPackageName());
    result.setClassName(source.getClassName());

    // Add the Chrome root node.
    if (isFrameInfoInitialized()) {
        result.addChild(mView, rootId);
    }

    return result;
}
 
源代码11 项目: 365browser   文件: BrowserAccessibilityManager.java
@CalledByNative
private void setAccessibilityNodeInfoBooleanAttributes(AccessibilityNodeInfo node,
        int virtualViewId,
        boolean checkable, boolean checked, boolean clickable,
        boolean enabled, boolean focusable, boolean focused, boolean password,
        boolean scrollable, boolean selected, boolean visibleToUser) {
    node.setCheckable(checkable);
    node.setChecked(checked);
    node.setClickable(clickable);
    node.setEnabled(enabled);
    node.setFocusable(focusable);
    node.setFocused(focused);
    node.setPassword(password);
    node.setScrollable(scrollable);
    node.setSelected(selected);
    node.setVisibleToUser(visibleToUser);

    node.setMovementGranularities(
            AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
            | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD
            | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);

    if (mAccessibilityFocusId == virtualViewId) {
        node.setAccessibilityFocused(true);
    } else {
        node.setAccessibilityFocused(false);
    }
}
 
源代码12 项目: Telegram-FOSS   文件: SimpleTextView.java
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setVisibleToUser(true);
    info.setClassName("android.widget.TextView");
    info.setText(text);
}
 
源代码13 项目: Telegram   文件: SimpleTextView.java
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setVisibleToUser(true);
    info.setClassName("android.widget.TextView");
    info.setText(text);
}
 
@CalledByNative
private void setAccessibilityNodeInfoBooleanAttributes(AccessibilityNodeInfo node,
        int virtualViewId, boolean checkable, boolean checked, boolean clickable,
        boolean enabled, boolean focusable, boolean focused, boolean password,
        boolean scrollable, boolean selected, boolean visibleToUser) {
    node.setCheckable(checkable);
    node.setChecked(checked);
    node.setClickable(clickable);
    node.setEnabled(enabled);
    node.setFocusable(focusable);
    node.setFocused(focused);
    node.setPassword(password);
    node.setScrollable(scrollable);
    node.setSelected(selected);
    node.setVisibleToUser(visibleToUser);

    if (focusable) {
        if (focused) {
            node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
        } else {
            node.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
        }
    }

    if (mAccessibilityFocusId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }

    if (clickable) {
        node.addAction(AccessibilityNodeInfo.ACTION_CLICK);
    }
}
 
@CalledByNative
private void setAccessibilityNodeInfoBooleanAttributes(AccessibilityNodeInfo node,
        int virtualViewId, boolean checkable, boolean checked, boolean clickable,
        boolean enabled, boolean focusable, boolean focused, boolean password,
        boolean scrollable, boolean selected, boolean visibleToUser) {
    node.setCheckable(checkable);
    node.setChecked(checked);
    node.setClickable(clickable);
    node.setEnabled(enabled);
    node.setFocusable(focusable);
    node.setFocused(focused);
    node.setPassword(password);
    node.setScrollable(scrollable);
    node.setSelected(selected);
    node.setVisibleToUser(visibleToUser);

    if (focusable) {
        if (focused) {
            node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
        } else {
            node.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
        }
    }

    if (mAccessibilityFocusId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }

    if (clickable) {
        node.addAction(AccessibilityNodeInfo.ACTION_CLICK);
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: NumberPicker.java
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
        int right, int bottom) {
    AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
    info.setClassName(NumberPicker.class.getName());
    info.setPackageName(mContext.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);

    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;
}
 
源代码17 项目: NewXmPluginSDK   文件: NumberPicker.java
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;
}
 
源代码18 项目: MultiSlider   文件: MultiSlider.java
@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;
}