Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75fab6b8 authored by Phil Weaver's avatar Phil Weaver Committed by Android (Google) Code Review
Browse files

Merge "Pass drawing order information to accessibility."

parents 92b9747f 1f222548
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -42861,6 +42861,7 @@ package android.view.accessibility {
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionInfo getCollectionInfo();
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo getCollectionItemInfo();
    method public java.lang.CharSequence getContentDescription();
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public int getInputType();
@@ -42923,6 +42924,7 @@ package android.view.accessibility {
    method public void setContentInvalid(boolean);
    method public void setContextClickable(boolean);
    method public void setDismissable(boolean);
    method public void setDrawingOrder(int);
    method public void setEditable(boolean);
    method public void setEnabled(boolean);
    method public void setError(java.lang.CharSequence);
+2 −0
Original line number Diff line number Diff line
@@ -45288,6 +45288,7 @@ package android.view.accessibility {
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionInfo getCollectionInfo();
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo getCollectionItemInfo();
    method public java.lang.CharSequence getContentDescription();
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public int getInputType();
@@ -45350,6 +45351,7 @@ package android.view.accessibility {
    method public void setContentInvalid(boolean);
    method public void setContextClickable(boolean);
    method public void setDismissable(boolean);
    method public void setDrawingOrder(int);
    method public void setEditable(boolean);
    method public void setEnabled(boolean);
    method public void setError(java.lang.CharSequence);
+2 −0
Original line number Diff line number Diff line
@@ -42877,6 +42877,7 @@ package android.view.accessibility {
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionInfo getCollectionInfo();
    method public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo getCollectionItemInfo();
    method public java.lang.CharSequence getContentDescription();
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public int getInputType();
@@ -42939,6 +42940,7 @@ package android.view.accessibility {
    method public void setContentInvalid(boolean);
    method public void setContextClickable(boolean);
    method public void setDismissable(boolean);
    method public void setDrawingOrder(int);
    method public void setEditable(boolean);
    method public void setEnabled(boolean);
    method public void setError(java.lang.CharSequence);
+62 −0
Original line number Diff line number Diff line
@@ -6691,6 +6691,68 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        info.addAction(AccessibilityAction.ACTION_SHOW_ON_SCREEN);
        populateAccessibilityNodeInfoDrawingOrderInParent(info);
    }
    /**
     * Determine the order in which this view will be drawn relative to its siblings for a11y
     *
     * @param info The info whose drawing order should be populated
     */
    private void populateAccessibilityNodeInfoDrawingOrderInParent(AccessibilityNodeInfo info) {
        int drawingOrderInParent = 1;
        // Iterate up the hierarchy if parents are not important for a11y
        View viewAtDrawingLevel = this;
        final ViewParent parent = getParentForAccessibility();
        while (viewAtDrawingLevel != parent) {
            final ViewParent currentParent = viewAtDrawingLevel.getParent();
            if (!(currentParent instanceof ViewGroup)) {
                // Should only happen for the Decor
                drawingOrderInParent = 0;
                break;
            } else {
                final ViewGroup parentGroup = (ViewGroup) currentParent;
                final int childCount = parentGroup.getChildCount();
                if (childCount > 1) {
                    List<View> preorderedList = parentGroup.buildOrderedChildList();
                    if (preorderedList != null) {
                        final int childDrawIndex = preorderedList.indexOf(viewAtDrawingLevel);
                        for (int i = 0; i < childDrawIndex; i++) {
                            drawingOrderInParent += numViewsForAccessibility(preorderedList.get(i));
                        }
                    } else {
                        final int childIndex = parentGroup.indexOfChild(viewAtDrawingLevel);
                        final boolean customOrder = parentGroup.isChildrenDrawingOrderEnabled();
                        final int childDrawIndex = ((childIndex >= 0) && customOrder) ? parentGroup
                                .getChildDrawingOrder(childCount, childIndex) : childIndex;
                        final int numChildrenToIterate = customOrder ? childCount : childDrawIndex;
                        if (childDrawIndex != 0) {
                            for (int i = 0; i < numChildrenToIterate; i++) {
                                final int otherDrawIndex = (customOrder ?
                                        parentGroup.getChildDrawingOrder(childCount, i) : i);
                                if (otherDrawIndex < childDrawIndex) {
                                    drawingOrderInParent +=
                                            numViewsForAccessibility(parentGroup.getChildAt(i));
                                }
                            }
                        }
                    }
                }
            }
            viewAtDrawingLevel = (View) currentParent;
        }
        info.setDrawingOrder(drawingOrderInParent);
    }
    private static int numViewsForAccessibility(View view) {
        if (view != null) {
            if (view.includeForAccessibility()) {
                return 1;
            } else if (view instanceof ViewGroup) {
                return ((ViewGroup) view).getNumChildrenForAccessibility();
            }
        }
        return 0;
    }
    private View findLabelForView(View view, int labeledId) {
+20 −0
Original line number Diff line number Diff line
@@ -3082,6 +3082,26 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
    }

    /**
     * Counts the number of children of this View that will be sent to an accessibility service.
     *
     * @return The number of children an {@code AccessibilityNodeInfo} rooted at this View
     * would have.
     */
    int getNumChildrenForAccessibility() {
        int numChildrenForAccessibility = 0;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (child.includeForAccessibility()) {
                numChildrenForAccessibility++;
            } else if (child instanceof ViewGroup) {
                numChildrenForAccessibility += ((ViewGroup) child)
                        .getNumChildrenForAccessibility();
            }
        }
        return numChildrenForAccessibility;
    }

    /**
     * {@inheritDoc}
     *
Loading