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

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent() . 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: DrawerLayout.java    From Dashchan with Apache License 2.0 7 votes vote down vote up
/**
 * 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());
}
 
Example 2
Source File: RadialTimePickerView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node) {
    node.setClassName(getClass().getName());
    node.addAction(AccessibilityAction.ACTION_CLICK);

    final int type = getTypeFromId(virtualViewId);
    final int value = getValueFromId(virtualViewId);
    final CharSequence description = getVirtualViewDescription(type, value);
    node.setContentDescription(description);

    getBoundsForVirtualView(virtualViewId, mTempRect);
    node.setBoundsInParent(mTempRect);

    final boolean selected = isVirtualViewSelected(type, value);
    node.setSelected(selected);

    final int nextId = getVirtualViewIdAfter(type, value);
    if (nextId != INVALID_ID) {
        node.setTraversalBefore(RadialTimePickerView.this, nextId);
    }
}
 
Example 3
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: NumberPicker.java    From NewXmPluginSDK 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(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;
}
 
Example 7
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@CalledByNative
private void setAccessibilityNodeInfoLocation(AccessibilityNodeInfo node,
        int absoluteLeft, int absoluteTop, int parentRelativeLeft, int parentRelativeTop,
        int width, int height, boolean isRootNode) {
    // First set the bounds in parent.
    Rect boundsInParent = new Rect(parentRelativeLeft, parentRelativeTop,
            parentRelativeLeft + width, parentRelativeTop + height);
    if (isRootNode) {
        // Offset of the web content relative to the View.
        boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
    }
    node.setBoundsInParent(boundsInParent);

    // Now set the absolute rect, which requires several transformations.
    Rect rect = new Rect(absoluteLeft, absoluteTop, absoluteLeft + width, absoluteTop + height);

    // Offset by the scroll position.
    rect.offset(-(int) mRenderCoordinates.getScrollX(),
                -(int) mRenderCoordinates.getScrollY());

    // Convert CSS (web) pixels to Android View pixels
    rect.left = (int) mRenderCoordinates.fromLocalCssToPix(rect.left);
    rect.top = (int) mRenderCoordinates.fromLocalCssToPix(rect.top);
    rect.bottom = (int) mRenderCoordinates.fromLocalCssToPix(rect.bottom);
    rect.right = (int) mRenderCoordinates.fromLocalCssToPix(rect.right);

    // Offset by the location of the web content within the view.
    rect.offset(0,
                (int) mRenderCoordinates.getContentOffsetYPix());

    // Finally offset by the location of the view within the screen.
    final int[] viewLocation = new int[2];
    mView.getLocationOnScreen(viewLocation);
    rect.offset(viewLocation[0], viewLocation[1]);

    node.setBoundsInScreen(rect);
}
 
Example 8
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@CalledByNative
private void setAccessibilityNodeInfoLocation(AccessibilityNodeInfo node,
        int absoluteLeft, int absoluteTop, int parentRelativeLeft, int parentRelativeTop,
        int width, int height, boolean isRootNode) {
    // First set the bounds in parent.
    Rect boundsInParent = new Rect(parentRelativeLeft, parentRelativeTop,
            parentRelativeLeft + width, parentRelativeTop + height);
    if (isRootNode) {
        // Offset of the web content relative to the View.
        boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
    }
    node.setBoundsInParent(boundsInParent);

    // Now set the absolute rect, which requires several transformations.
    Rect rect = new Rect(absoluteLeft, absoluteTop, absoluteLeft + width, absoluteTop + height);

    // Offset by the scroll position.
    rect.offset(-(int) mRenderCoordinates.getScrollX(),
                -(int) mRenderCoordinates.getScrollY());

    // Convert CSS (web) pixels to Android View pixels
    rect.left = (int) mRenderCoordinates.fromLocalCssToPix(rect.left);
    rect.top = (int) mRenderCoordinates.fromLocalCssToPix(rect.top);
    rect.bottom = (int) mRenderCoordinates.fromLocalCssToPix(rect.bottom);
    rect.right = (int) mRenderCoordinates.fromLocalCssToPix(rect.right);

    // Offset by the location of the web content within the view.
    rect.offset(0,
                (int) mRenderCoordinates.getContentOffsetYPix());

    // Finally offset by the location of the view within the screen.
    final int[] viewLocation = new int[2];
    mView.getLocationOnScreen(viewLocation);
    rect.offset(viewLocation[0], viewLocation[1]);

    node.setBoundsInScreen(rect);
}
 
Example 9
Source File: NumberPicker.java    From zen4android with MIT License 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(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);
    // TODO 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 10
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: TextPicker.java    From GifAssistant 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(getContext().getPackageName());
    info.setSource(TextPicker.this, virtualViewId);
    info.setParent(TextPicker.this);
    info.setText(text);
    info.setClickable(true);
    info.setLongClickable(true);
    info.setEnabled(TextPicker.this.isEnabled());
    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    // TODO 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 (TextPicker.this.isEnabled()) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
    }

    return info;
}
 
Example 12
Source File: NumberPicker.java    From ticdesign 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(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(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 13
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }

}
 
Example 14
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 15
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 16
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private void setAccessibilityNodeInfoLocation(AccessibilityNodeInfo node,
        final int virtualViewId,
        int absoluteLeft, int absoluteTop, int parentRelativeLeft, int parentRelativeTop,
        int width, int height, boolean isRootNode) {
    // First set the bounds in parent.
    Rect boundsInParent = new Rect(parentRelativeLeft, parentRelativeTop,
            parentRelativeLeft + width, parentRelativeTop + height);
    if (isRootNode) {
        // Offset of the web content relative to the View.
        boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
    }
    node.setBoundsInParent(boundsInParent);

    // Now set the absolute rect, which requires several transformations.
    Rect rect = new Rect(absoluteLeft, absoluteTop, absoluteLeft + width, absoluteTop + height);

    // Offset by the scroll position.
    rect.offset(-(int) mRenderCoordinates.getScrollX(),
                -(int) mRenderCoordinates.getScrollY());

    // Convert CSS (web) pixels to Android View pixels
    rect.left = (int) mRenderCoordinates.fromLocalCssToPix(rect.left);
    rect.top = (int) mRenderCoordinates.fromLocalCssToPix(rect.top);
    rect.bottom = (int) mRenderCoordinates.fromLocalCssToPix(rect.bottom);
    rect.right = (int) mRenderCoordinates.fromLocalCssToPix(rect.right);

    // Offset by the location of the web content within the view.
    rect.offset(0,
                (int) mRenderCoordinates.getContentOffsetYPix());

    // Finally offset by the location of the view within the screen.
    final int[] viewLocation = new int[2];
    mView.getLocationOnScreen(viewLocation);
    rect.offset(viewLocation[0], viewLocation[1]);

    // Clip the node's bounding rect to the viewport bounds.
    int viewportRectTop = viewLocation[1] + (int) mRenderCoordinates.getContentOffsetYPix();
    int viewportRectBottom = viewportRectTop + mContentViewCore.getViewportHeightPix();
    if (rect.top < viewportRectTop) rect.top = viewportRectTop;
    if (rect.bottom > viewportRectBottom) rect.bottom = viewportRectBottom;

    node.setBoundsInScreen(rect);

    // Work around a bug in the Android framework where if the object with accessibility
    // focus moves, the accessibility focus rect is not updated - both the visual highlight,
    // and the location on the screen that's clicked if you double-tap. To work around this,
    // when we know the object with accessibility focus moved, move focus away and then
    // move focus right back to it, which tricks Android into updating its bounds.
    if (virtualViewId == mAccessibilityFocusId && virtualViewId != mCurrentRootId) {
        if (mAccessibilityFocusRect == null) {
            mAccessibilityFocusRect = rect;
        } else if (!mAccessibilityFocusRect.equals(rect)) {
            mAccessibilityFocusRect = rect;
            moveAccessibilityFocusToIdAndRefocusIfNeeded(virtualViewId);
        }
    }
}
 
Example 17
Source File: NumberPicker.java    From android_9.0.0_r45 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(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;
}