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

Commit 1f222548 authored by Phil Weaver's avatar Phil Weaver
Browse files

Pass drawing order information to accessibility.

Bug: 22721935
Change-Id: I45a2be7c174c8b5a469b68a45dec0eb536825d92
parent 5d5127bf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -42762,6 +42762,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();
@@ -42824,6 +42825,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
@@ -45124,6 +45124,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();
@@ -45186,6 +45187,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
@@ -42778,6 +42778,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();
@@ -42840,6 +42841,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