From 7b2ace89e4d149755e9958c76bed1db7f71db828 Mon Sep 17 00:00:00 2001 From: ismaeldivita Date: Sun, 19 Apr 2020 18:03:44 +0100 Subject: [PATCH 1/2] Improve accessibility for menu items --- .../chipnavigation/view/HorizontalMenuItemView.kt | 4 ++++ .../ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt index 1b4f0e3..d665a06 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt @@ -36,6 +36,10 @@ internal class HorizontalMenuItemView @JvmOverloads constructor( override fun bind(item: MenuItem) { id = item.id + + importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES + contentDescription = item.title + isEnabled = item.enabled item.menuStyle.textAppearance?.let(title::setTextAppearance) title.text = item.title diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt index 7569b73..9ade24e 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt @@ -49,6 +49,9 @@ internal class VerticalMenuItemView @JvmOverloads constructor( isEnabled = item.enabled radius = item.menuStyle.radius + importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES + contentDescription = item.title + item.menuStyle.textAppearance?.let(title::setTextAppearance) title.text = item.title title.setColorStateListAnimator( From 52073cf89c598905fe37b705bfc60273ea31ffc7 Mon Sep 17 00:00:00 2001 From: ismaeldivita Date: Sun, 19 Apr 2020 18:11:45 +0100 Subject: [PATCH 2/2] Add contentDescription to menu item --- .../main/java/com/ismaeldivita/chipnavigation/model/MenuItem.kt | 1 + .../java/com/ismaeldivita/chipnavigation/model/MenuParser.kt | 1 + .../ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt | 2 +- .../ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt | 2 +- chip-navigation-bar/src/main/res/values/attrs.xml | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuItem.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuItem.kt index e801dc2..dea077d 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuItem.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuItem.kt @@ -8,6 +8,7 @@ import androidx.annotation.DrawableRes internal class MenuItem( val id: Int, val title: CharSequence, + val contentDescription: CharSequence?, @DrawableRes val icon: Int, val enabled: Boolean, val tintMode: PorterDuff.Mode?, diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuParser.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuParser.kt index d15128a..5dee915 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuParser.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/model/MenuParser.kt @@ -74,6 +74,7 @@ internal class MenuParser(private val context: Context) { val item = MenuItem( id = sAttr.getResourceId(R.styleable.ChipMenuItem_android_id, 0), title = sAttr.getText(R.styleable.ChipMenuItem_android_title), + contentDescription = sAttr.getText(R.styleable.ChipMenuItem_android_contentDescription), icon = sAttr.getResourceId(R.styleable.ChipMenuItem_android_icon, 0), enabled = sAttr.getBoolean(R.styleable.ChipMenuItem_android_enabled, true), iconColor = readIconActiveColor(sAttr), diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt index d665a06..04ad30a 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/HorizontalMenuItemView.kt @@ -38,7 +38,7 @@ internal class HorizontalMenuItemView @JvmOverloads constructor( id = item.id importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES - contentDescription = item.title + contentDescription = item.contentDescription ?: item.title isEnabled = item.enabled item.menuStyle.textAppearance?.let(title::setTextAppearance) diff --git a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt index 9ade24e..42465cd 100644 --- a/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt +++ b/chip-navigation-bar/src/main/java/com/ismaeldivita/chipnavigation/view/VerticalMenuItemView.kt @@ -50,7 +50,7 @@ internal class VerticalMenuItemView @JvmOverloads constructor( radius = item.menuStyle.radius importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES - contentDescription = item.title + contentDescription = item.contentDescription ?: item.title item.menuStyle.textAppearance?.let(title::setTextAppearance) title.text = item.title diff --git a/chip-navigation-bar/src/main/res/values/attrs.xml b/chip-navigation-bar/src/main/res/values/attrs.xml index a39ebab..a95231f 100644 --- a/chip-navigation-bar/src/main/res/values/attrs.xml +++ b/chip-navigation-bar/src/main/res/values/attrs.xml @@ -25,6 +25,7 @@ +