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

Commit 9c3e0e68 authored by alanv's avatar alanv
Browse files

Fix accessibility actions in AbsListView.

Check adapter for position enabled state, check selection index.

Bug: 6508142
Change-Id: If25a133533a7316ef7eba8761522bd2ee4f6338d
parent 9cb660fa
Loading
Loading
Loading
Loading
+36 −16
Original line number Diff line number Diff line
@@ -2291,28 +2291,37 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            super.onInitializeAccessibilityNodeInfo(host, info);

            final int position = getPositionForView(host);
            final ListAdapter adapter = getAdapter();

            if (position == INVALID_POSITION) {
            if ((position == INVALID_POSITION) || (adapter == null)) {
                // Cannot perform actions on invalid items.
                info.setEnabled(false);
                return;
            }

            if (isClickable() && isEnabled()) {
            if (!isEnabled() || !adapter.isEnabled(position)) {
                // Cannot perform actions on invalid items.
                info.setEnabled(false);
                return;
            }

            if (position == getSelectedItemPosition()) {
                info.setSelected(true);
                info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION);
            } else {
                info.addAction(AccessibilityNodeInfo.ACTION_SELECT);
            }

            if (isClickable()) {
                info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
                info.setClickable(true);
            }

            if (isLongClickable() && isEnabled()) {
            if (isLongClickable()) {
                info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK);
                info.setLongClickable(true);
            }

            if (isEnabled()) {
                info.addAction(AccessibilityNodeInfo.ACTION_SELECT);
            }

            if (position == getSelectedItemPosition()) {
                info.setSelected(true);
            }
        }

        @Override
@@ -2322,22 +2331,33 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            }

            final int position = getPositionForView(host);
            final ListAdapter adapter = getAdapter();

            if (position == INVALID_POSITION) {
            if ((position == INVALID_POSITION) || (adapter == null)) {
                // Cannot perform actions on invalid items.
                return false;
            }

            if (!isEnabled()) {
            if (!isEnabled() || !adapter.isEnabled(position)) {
                // Cannot perform actions on disabled items.
                return false;
            }

            final long id = getItemIdAtPosition(position);

            switch (action) {
                case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: {
                    if (getSelectedItemPosition() == position) {
                        setSelection(INVALID_POSITION);
                        return true;
                    }
                } return false;
                case AccessibilityNodeInfo.ACTION_SELECT: {
                    if (getSelectedItemPosition() != position) {
                        setSelection(position);
                        return true;
                    }
                } return false;
                case AccessibilityNodeInfo.ACTION_CLICK: {
                    if (isClickable()) {
                        return performItemClick(host, position, id);