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

Commit 2f27fae1 authored by Yinglei Wang's avatar Yinglei Wang
Browse files

CheckableRelativeLayout accessibility checked state updates

Send the new checked event. Updated to the new checked api.

Test: tested that the CheckableRelativeLayout sends out the new event.

Flag: android.view.accessibility.tri_state_checked

Bug: 380327448

Change-Id: I7020cc70e100f6bc732bf7ab4e55be76cea8e621
parent d5d59630
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.widget;

import static android.view.accessibility.Flags.triStateChecked;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
@@ -90,11 +92,17 @@ public class CheckableRelativeLayout extends RelativeLayout implements Checkable
            if (mCheckable != null) {
                mCheckable.setChecked(checked);
            }
            if (triStateChecked()) {
                notifyViewAccessibilityStateChangedIfNeeded(
                        AccessibilityEvent.CONTENT_CHANGE_TYPE_CHECKED);
            }
        }
        setStateDescriptionIfNeeded();
        if (!triStateChecked()) {
            notifyViewAccessibilityStateChangedIfNeeded(
                    AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
        }
    }

    private void setStateDescriptionIfNeeded() {
        if (mCheckableChild == null) {
@@ -122,6 +130,11 @@ public class CheckableRelativeLayout extends RelativeLayout implements Checkable
    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        if (triStateChecked()) {
            info.setChecked(mChecked ? AccessibilityNodeInfo.CHECKED_STATE_TRUE :
                    AccessibilityNodeInfo.CHECKED_STATE_FALSE);
        } else {
            info.setChecked(mChecked);
        }
    }
}