summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorBhavuk Jain <bhavukj@google.com>2023-10-09 16:48:24 +0000
committerBhavuk Jain <bhavukj@google.com>2023-10-12 19:49:21 +0000
commitac7730d982b6d1a61dbc3cff50acc7a5051d2465 (patch)
treeda54423b1768eb0080566e5a0e6b29940a2def37 /src/com
parent4abe2fbaa85dfd646c53eb5ff3bffa36eb6c1bc5 (diff)
downloadThemePicker-ac7730d982b6d1a61dbc3cff50acc7a5051d2465.tar.gz
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
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt24
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt15
2 files changed, 38 insertions, 1 deletions
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
index 091f484e..3ac52ad5 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
@@ -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,
diff --git a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 809d20e6..d67ad1da 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -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)
}