[Android] Accessibility: improve talkback for the audio list

Nicolas Pomepuy git at videolan.org
Fri Jun 3 11:30:21 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri May 20 08:28:02 2022 +0200| [1f1b75b7660e1b49264bef9c51dac3a7d43d811f] | committer: Nicolas Pomepuy

Accessibility: improve talkback for the audio list

> https://code.videolan.org/videolan/vlc-android/commit/1f1b75b7660e1b49264bef9c51dac3a7d43d811f
---

 .../resources/src/main/res/values/strings.xml      |  3 ++-
 .../res/layout/audio_browser_card_item.xml         |  2 ++
 .../vlc-android/res/layout/audio_browser_item.xml  |  2 ++
 .../org/videolan/vlc/gui/helpers/TalkbackUtil.kt   | 25 ++++++++++++++--------
 .../org/videolan/vlc/util/AccessibilityHelper.kt   | 11 +++++-----
 5 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 1b63d83d7..6ecabe7c7 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -978,7 +978,7 @@
 
     <!--    accessibility-->
     <string name="talkback_media_content_description">%s - title: %s - duration: %s</string>
-    <string name="talkback_genre">Genre</string>
+    <string name="talkback_genre">Genre: %s</string>
     <string name="talkback_history_item">History item</string>
     <string name="talkback_playlist">Playlist</string>
     <string name="talkback_folder">Folder: %s</string>
@@ -988,6 +988,7 @@
     <string name="talkback_artist">Artist: %s</string>
     <string name="talkback_release_date">Released in %s</string>
     <string name="talkback_video">Video: %s</string>
+    <string name="talkback_audio_track">Audio track: %s</string>
     <string name="talkback_video_group">Video group: %s</string>
     <string name="talkback_hours">hours</string>
     <string name="talkback_minutes">minutes</string>
diff --git a/application/vlc-android/res/layout/audio_browser_card_item.xml b/application/vlc-android/res/layout/audio_browser_card_item.xml
index a46fc092d..58d70d38a 100644
--- a/application/vlc-android/res/layout/audio_browser_card_item.xml
+++ b/application/vlc-android/res/layout/audio_browser_card_item.xml
@@ -70,6 +70,7 @@
             android:background="?attr/video_list_background"
             android:clickable="true"
             android:focusable="true"
+            vlc:mediaContentDescription="@{item}"
             android:foreground="?android:attr/selectableItemBackground"
             android:longClickable="true"
             android:minHeight="@dimen/audio_browser_item_size"
@@ -130,6 +131,7 @@
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:background="@color/transparent"
+                        android:contentDescription="@string/play_all"
                         android:onClick="@{holder::onMainActionClick}"
                         vlc:layout_constraintBottom_toBottomOf="parent"
                         vlc:layout_constraintEnd_toEndOf="parent"
diff --git a/application/vlc-android/res/layout/audio_browser_item.xml b/application/vlc-android/res/layout/audio_browser_item.xml
index 57c60f66b..8011bd7dc 100644
--- a/application/vlc-android/res/layout/audio_browser_item.xml
+++ b/application/vlc-android/res/layout/audio_browser_item.xml
@@ -58,6 +58,7 @@
             android:clickable="true"
             android:focusable="true"
             android:background="?attr/video_list_background"
+            vlc:mediaContentDescription="@{item}"
             selected="@{selected}"
             android:longClickable="true"
             android:foreground="?attr/selectableItemBackground"
@@ -88,6 +89,7 @@
                 android:layout_marginStart="16dp"
                 android:layout_marginTop="8dp"
                 android:layout_marginBottom="8dp"
+                android:importantForAccessibility="no"
                 android:onClick="@{holder::onImageClick}"
                 android:scaleType="centerCrop"
                 android:src="@{cover}"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/TalkbackUtil.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/TalkbackUtil.kt
index 62eb57c07..db61a759d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/TalkbackUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/TalkbackUtil.kt
@@ -25,23 +25,30 @@
 package org.videolan.vlc.gui.helpers
 
 import android.content.Context
-import org.videolan.medialibrary.interfaces.media.Folder
-import org.videolan.medialibrary.interfaces.media.MediaWrapper
-import org.videolan.medialibrary.interfaces.media.VideoGroup
+import org.videolan.medialibrary.interfaces.media.*
 import org.videolan.vlc.R
 
 object TalkbackUtil {
 
-    fun getArtist(context: Context, artist: String) = context.getString(R.string.talkback_artist, artist)
     fun getDuration(context: Context, duration: String) = context.getString(R.string.talkback_duration, duration)
     fun getAlbumTitle(context: Context, album: String) = context.getString(R.string.talkback_album, album)
     fun getReleaseDate(context: Context, date: String) = context.getString(R.string.talkback_release_date, date)
-    fun getVideo(context: Context, video: MediaWrapper) =
-            context.getString(R.string.talkback_video).talkbackAppend(getDuration(context, millisToString(context, video.length)))
+    fun getVideo(context: Context, video: MediaWrapper) = context.getString(R.string.talkback_video)
+            .talkbackAppend(getDuration(context, millisToString(context, video.length)))
+    fun getAudioTrack(context: Context, audio: MediaWrapper) = context.getString(R.string.talkback_audio_track, audio.title)
+            .talkbackAppend(getDuration(context, millisToString(context, audio.length)))
+            .talkbackAppend(context.getString(R.string.talkback_album, audio.album))
+            .talkbackAppend(context.getString(R.string.talkback_artist, audio.artist))
+    fun getVideoGroup(context: Context, video: VideoGroup) = context.getString(R.string.talkback_video_group, video.title)
+            .talkbackAppend(context.resources.getQuantityString(R.plurals.videos_quantity, video.mediaCount(), video.mediaCount()))
+    fun getGenre(context: Context, genre: Genre) = context.getString(R.string.talkback_genre, genre.title)
+            .talkbackAppend(context.resources.getQuantityString(R.plurals.track_quantity, genre.tracksCount, genre.tracksCount))
+    fun getArtist(context: Context, artist: Artist) = context.getString(R.string.talkback_artist, artist.title)
+            .talkbackAppend(context.resources.getQuantityString(R.plurals.albums_quantity, artist.albumsCount, artist.albumsCount))
+    fun getAlbum(context: Context, album: Album) = context.getString(R.string.talkback_album, album.title)
+            .talkbackAppend(context.getString(R.string.talkback_artist, album.albumArtist))
+            .talkbackAppend(context.resources.getQuantityString(R.plurals.track_quantity, album.tracksCount, album.tracksCount))
 
-    fun getVideoGroup(context: Context, video: VideoGroup) =
-            context.getString(R.string.talkback_video_group, video.title)
-                    .talkbackAppend(context.resources.getQuantityString(R.plurals.videos_quantity, video.mediaCount(), video.mediaCount()))
 
     fun getFolder(context: Context, folder: Folder): String {
         val mediaCount = folder.mediaCount(Folder.TYPE_FOLDER_VIDEO)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/AccessibilityHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/AccessibilityHelper.kt
index 73e648d6b..c721dbe7c 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/AccessibilityHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/AccessibilityHelper.kt
@@ -42,16 +42,17 @@ fun Activity.isTalkbackIsEnabled() = (getSystemService(ACCESSIBILITY_SERVICE) as
 fun mediaDescription(v: View, media: MediaLibraryItem) {
     v.contentDescription = when (media) {
         is VideoGroup -> TalkbackUtil.getVideoGroup(v.context, media)
-        is Album -> v.context.getString(R.string.talkback_album)
-        is Artist -> v.context.getString(R.string.talkback_artist)
+        is Album -> TalkbackUtil.getAlbum(v.context, media)
+        is Artist -> TalkbackUtil.getArtist(v.context, media)
         is Folder -> TalkbackUtil.getFolder(v.context, media)
-        is Genre -> v.context.getString(R.string.talkback_genre)
+        is Genre -> TalkbackUtil.getGenre(v.context, media)
         is HistoryItem -> v.context.getString(R.string.talkback_history_item)
         is Playlist -> v.context.getString(R.string.talkback_playlist)
         is MediaWrapper -> when (media.type) {
             MediaWrapper.TYPE_VIDEO -> TalkbackUtil.getVideo(v.context, media)
-            else -> v.context.getString(R.string.audio)
+            MediaWrapper.TYPE_AUDIO -> TalkbackUtil.getAudioTrack(v.context, media)
+            else -> throw NotImplementedError("")
         }
-        else -> throw IllegalStateException("Unknown item type")
+        else -> throw NotImplementedError("Unknown item type")
     }
 }



More information about the Android mailing list