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

Commit f4bd91f0 authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Add a11y action for expand / collapse items in WidgetsFullSheet" into sc-dev

parents 129b001f fd68f757
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
        tools:src="@drawable/ic_corp"/>

    <LinearLayout
        android:id="@+id/app_container"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
+32 −1
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -94,6 +97,32 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
        mTitle = findViewById(R.id.app_title);
        mSubtitle = findViewById(R.id.app_subtitle);
        mExpandToggle = findViewById(R.id.toggle);
        findViewById(R.id.app_container).setAccessibilityDelegate(new AccessibilityDelegate() {

            @Override
            public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
                if (mIsExpanded) {
                    info.removeAction(AccessibilityNodeInfo.ACTION_EXPAND);
                    info.addAction(AccessibilityNodeInfo.ACTION_COLLAPSE);
                } else {
                    info.removeAction(AccessibilityNodeInfo.ACTION_COLLAPSE);
                    info.addAction(AccessibilityNodeInfo.ACTION_EXPAND);
                }
                super.onInitializeAccessibilityNodeInfo(host, info);
            }

            @Override
            public boolean performAccessibilityAction(View host, int action, Bundle args) {
                switch (action) {
                    case AccessibilityNodeInfo.ACTION_EXPAND:
                    case AccessibilityNodeInfo.ACTION_COLLAPSE:
                        callOnClick();
                        return true;
                    default:
                        return super.performAccessibilityAction(host, action, args);
                }
            }
        });
    }

    /**
@@ -106,7 +135,9 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
        // Use the entire touch area of this view to expand / collapse an app widgets section.
        setOnClickListener(view -> {
            setExpanded(!mIsExpanded);
            if (onExpandChangeListener != null) {
                onExpandChangeListener.onExpansionChange(mIsExpanded);
            }
        });
    }