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

Commit ac7730d9 authored by Bhavuk Jain's avatar Bhavuk Jain
Browse files

Added changes for a11y for the left and right shortcut buttons

This CL aims at making changes for making sure we get the right content
description for the left and right shortcut buttons on the wallpaper
picker screen.

Bug: b/280551132
Test: Tested by building and installing picker on local, and making sure
we get the right text announced. Video attached in bug.

Change-Id: Ic2c845fc75ad94ef187dc1ed484f2635ee00b9f4
parent 4abe2fba
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -20,7 +20,11 @@ package com.android.customization.picker.quickaffordance.ui.binder
import android.app.Dialog
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.widget.ImageView
import androidx.core.view.AccessibilityDelegateCompat
import androidx.core.view.ViewCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
@@ -62,6 +66,26 @@ object KeyguardQuickAffordancePickerBinder {
        slotTabView.layoutManager =
            LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, false)
        slotTabView.addItemDecoration(ItemSpacing(ItemSpacing.TAB_ITEM_SPACING_DP))

        // Setting a custom accessibility delegate so that the default content descriptions
        // for items in a list aren't announced (for left & right shortcuts). We populate
        // the content description for these shortcuts later on with the right (expected)
        // values.
        val slotTabViewDelegate: AccessibilityDelegateCompat =
            object : AccessibilityDelegateCompat() {
                override fun onRequestSendAccessibilityEvent(
                    host: ViewGroup,
                    child: View,
                    event: AccessibilityEvent
                ): Boolean {
                    if (event.eventType != AccessibilityEvent.TYPE_VIEW_FOCUSED) {
                        child.contentDescription = null
                    }
                    return super.onRequestSendAccessibilityEvent(host, child, event)
                }
            }

        ViewCompat.setAccessibilityDelegate(slotTabView, slotTabViewDelegate)
        val affordancesAdapter =
            OptionItemAdapter(
                layoutResourceId = R.layout.keyguard_quick_affordance,
+14 −1
Original line number Diff line number Diff line
@@ -158,7 +158,8 @@ private constructor(
                                        Icon.Loaded(
                                            drawable =
                                                getAffordanceIcon(affordanceModel.iconResourceId),
                                            contentDescription = null,
                                            contentDescription =
                                                Text.Loaded(getSlotContentDescription(slot.id)),
                                        ),
                                    text = Text.Loaded(affordanceModel.name),
                                    isSelected = MutableStateFlow(true) as StateFlow<Boolean>,
@@ -423,6 +424,18 @@ private constructor(
        )
    }

    private fun getSlotContentDescription(slotId: String): String {
        return applicationContext.getString(
            when (slotId) {
                KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START ->
                    R.string.keyguard_slot_name_bottom_start
                KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END ->
                    R.string.keyguard_slot_name_bottom_end
                else -> error("No accessibility label for slot with ID \"$slotId\"!")
            }
        )
    }

    private suspend fun getAffordanceIcon(@DrawableRes iconResourceId: Int): Drawable {
        return quickAffordanceInteractor.getAffordanceIcon(iconResourceId)
    }