[Android] Accessibility: improve talkback for the subtitle downloader

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue May 24 10:46:51 2022 +0200| [f2af682045b64896043f0c221af9f4402d49c08d] | committer: Nicolas Pomepuy

Accessibility: improve talkback for the subtitle downloader

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

 application/resources/src/main/res/values/strings.xml          |  6 ++++++
 application/vlc-android/res/layout/language_spinner.xml        |  1 +
 application/vlc-android/res/layout/subtitle_download_item.xml  |  2 +-
 .../vlc-android/res/layout/subtitle_downloader_dialog.xml      |  2 ++
 .../src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt       | 10 ++++++++++
 .../videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt   |  3 +++
 .../src/org/videolan/vlc/gui/view/LanguageSelector.kt          |  1 +
 7 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 29f282f48..b860ca938 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1006,9 +1006,15 @@
     <string name="talkback_audio_tracks">Audio tracks</string>
     <string name="talkback_subtitle_tracks">Subtitle tracks</string>
     <string name="talkback_track" translatable="false">%s: %s. %s</string>
+    <string name="talkback_subtitle_dowload_item">Language: %s. %s. Name: %s</string>
     <string name="selected">Selected</string>
     <string name="talkback_increase_delay">Increase delay</string>
     <string name="talkback_decrease_delay">Decrease delay</string>
+    <string name="talkback_subtitle_history">Subtitle history</string>
+    <string name="talkback_language_selection">%s selected languages</string>
+    <string name="downloaded">Downloaded</string>
+    <string name="not_downloaded">Not downloaded</string>
+    <string name="downloading">Downloading</string>
 
 
 </resources>
diff --git a/application/vlc-android/res/layout/language_spinner.xml b/application/vlc-android/res/layout/language_spinner.xml
index 914eb28d0..0931825cf 100644
--- a/application/vlc-android/res/layout/language_spinner.xml
+++ b/application/vlc-android/res/layout/language_spinner.xml
@@ -47,6 +47,7 @@
             android:gravity="center"
             android:textColor="@color/white"
             android:textSize="10sp"
+            android:importantForAccessibility="no"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintDimensionRatio="1"
             app:layout_constraintEnd_toEndOf="parent"
diff --git a/application/vlc-android/res/layout/subtitle_download_item.xml b/application/vlc-android/res/layout/subtitle_download_item.xml
index f6470cf69..50bc08b91 100644
--- a/application/vlc-android/res/layout/subtitle_download_item.xml
+++ b/application/vlc-android/res/layout/subtitle_download_item.xml
@@ -65,7 +65,7 @@
                 android:layout_marginEnd="8dp"
                 android:focusable="true"
                 android:background="?attr/selectableItemBackgroundBorderless"
-                android:contentDescription="Download"
+                android:importantForAccessibility="no"
                 android:padding="4dp"
                 android:src="@{subtitleItem.state == State.Downloaded ? @drawable/ic_done : @drawable/ic_download }"
                 android:visibility="@{subtitleItem.state == State.Downloading ? View.GONE : View.VISIBLE}"
diff --git a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
index a5c7bc49a..a452c2b3d 100644
--- a/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/application/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -71,6 +71,7 @@
                     android:background="?attr/selectableItemBackgroundBorderless"
                     android:focusable="true"
                     android:padding="4dp"
+                    android:contentDescription="@string/search"
                     app:layout_constraintBottom_toBottomOf="@+id/movieName"
                     app:layout_constraintEnd_toStartOf="@+id/sub_download_history"
                     app:layout_constraintHorizontal_bias="0.5"
@@ -86,6 +87,7 @@
                     android:background="?attr/selectableItemBackgroundBorderless"
                     android:focusable="true"
                     android:padding="4dp"
+                    android:contentDescription="@string/talkback_subtitle_history"
                     android:selected="@{state == state.History}"
                     app:layout_constraintBottom_toBottomOf="@+id/movieName"
                     app:layout_constraintEnd_toStartOf="@+id/sub_download_next"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
index dbba03372..5f888e10d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
@@ -5,7 +5,9 @@ import android.view.ViewGroup
 import androidx.recyclerview.widget.RecyclerView
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.channels.SendChannel
+import org.videolan.vlc.R
 import org.videolan.vlc.databinding.SubtitleDownloadItemBinding
+import java.util.*
 
 internal class SubtitlesAdapter(private val eventActor: SendChannel<SubtitleEvent>) : RecyclerView.Adapter<SubtitlesAdapter.ViewHolder>() {
     private var dataset: List<SubtitleItem>? = null
@@ -50,6 +52,14 @@ internal class SubtitlesAdapter(private val eventActor: SendChannel<SubtitleEven
             binding.subtitleItem = subtitleItem
             binding.downloadSub.setOnClickListener { itemView.performClick() }
             binding.executePendingBindings()
+
+            val context = binding.root.context
+            val downloadString = context.getString(when(subtitleItem?.state) {
+                State.Downloaded ->R.string.downloaded
+                State.NotDownloaded ->R.string.not_downloaded
+                else -> R.string.downloading
+            })
+            itemView.contentDescription = context.getString(R.string.talkback_subtitle_dowload_item, Locale(subtitleItem?.subLanguageID ?: "").displayLanguage, downloadString, subtitleItem?.movieReleaseName ?: "")
         }
     }
 }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
index 74e007668..c4f97142c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
@@ -6,6 +6,7 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.view.accessibility.AccessibilityEvent
 import android.widget.FrameLayout
 import androidx.annotation.LayoutRes
 import androidx.lifecycle.lifecycleScope
@@ -14,6 +15,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
 import org.videolan.resources.AndroidDevices
 import org.videolan.tools.Settings
 import org.videolan.vlc.R
+import org.videolan.vlc.util.isTalkbackIsEnabled
 
 abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
 
@@ -67,6 +69,7 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
         initialFocusedView().isFocusableInTouchMode = true
 
         initialFocusedView().requestFocus()
+        if (requireActivity().isTalkbackIsEnabled()) initialFocusedView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
     }
 
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/LanguageSelector.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/LanguageSelector.kt
index 63bd77d9f..806079754 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/LanguageSelector.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/LanguageSelector.kt
@@ -80,6 +80,7 @@ class LanguageSelector: ConstraintLayout, DialogInterface.OnDismissListener, Dia
         selectedIndices.forEach {
             if (it >= 0 && it < selection.size) selection[it] = true
         }
+        contentDescription = context.getString(R.string.talkback_language_selection, selection.filter { it }.size.toString())
         updateBadge()
         listener?.onItemSelect(selectedIndices)
     }



More information about the Android mailing list