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

Commit e5fd8ebc authored by Yinglei Wang's avatar Yinglei Wang
Browse files

PreviewPageFrame checked state updates

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

This widget is using getSelected() as the checked state. We can't send
the event in setSelected() because setSelected in called in
onBindViewHolder and the widget is not attached yet. So we send the
new event when the widget is clicked.

Test: tested on the print preview and checked the new event is sent
when clicked.
Flag: android.view.accessibility.tri_state_checked
Bug: 380327448

Change-Id: I1591425bf7d35ef361cae94ee394cb26b20014ff
parent 3fa794b6
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.printspooler.widget;

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

import android.content.Context;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
@@ -37,6 +39,20 @@ public final class PreviewPageFrame extends LinearLayout {
        return CompoundButton.class.getName();
    }

    @Override
    public boolean performClick() {
        final boolean result = super.performClick();
        // This widget is incorrectly using the notion of "selection"
        // to represent checked state. We can't send this event in
        // setSelected() because setSelected() is called when this widget
        // is not attached.
        if (triStateChecked()) {
            notifyViewAccessibilityStateChangedIfNeeded(
                    AccessibilityEvent.CONTENT_CHANGE_TYPE_CHECKED);
        }
        return result;
    }

    @Override
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        super.onInitializeAccessibilityEvent(event);
@@ -48,6 +64,11 @@ public final class PreviewPageFrame extends LinearLayout {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setSelected(false);
        info.setCheckable(true);
        if (triStateChecked()) {
            info.setChecked(isSelected() ? AccessibilityNodeInfo.CHECKED_STATE_TRUE :
                    AccessibilityNodeInfo.CHECKED_STATE_FALSE);
        } else {
            info.setChecked(isSelected());
        }
    }
}