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

Commit d76b792f authored by Hai Zhang's avatar Hai Zhang
Browse files

Improve a11y of role UI.

Call setChecked() for RadioButton so that it reports the correct
checked state for a11y, and increse CheckBox touch target size.

Bug: 128713569
Test: manual
Change-Id: I4e24303d342be286af56ffe9026e493d35ba7319
parent 6ebb0d54
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -703,7 +703,7 @@
    <style name="RequestRoleViewCheckbox">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:minHeight">40dp</item>
        <item name="android:minHeight">?android:listPreferredItemHeightSmall</item>
        <item name="android:paddingStart">16dp</item>
        <item name="android:textAppearance">@style/android:TextAppearance.Material.Subhead</item>
    </style>
+22 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.packageinstaller.role.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Checkable;
import android.widget.LinearLayout;

@@ -71,6 +73,7 @@ public class CheckableLinearLayout extends LinearLayout implements Checkable {

        mChecked = checked;
        refreshDrawableState();
        updateChildrenChecked();
    }

    @Override
@@ -87,4 +90,23 @@ public class CheckableLinearLayout extends LinearLayout implements Checkable {
        }
        return state;
    }

    private void updateChildrenChecked() {
        updateChildrenChecked(this, mChecked);
    }

    // We call setChecked() on checkable children so that accessibility can get the correct state.
    private static void updateChildrenChecked(@NonNull ViewGroup viewGroup, boolean checked) {
        int count = viewGroup.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = viewGroup.getChildAt(i);
            if (child.isDuplicateParentStateEnabled()) {
                if (child instanceof Checkable) {
                    ((Checkable) child).setChecked(checked);
                } else if (child instanceof ViewGroup) {
                    updateChildrenChecked((ViewGroup) child, checked);
                }
            }
        }
    }
}