From 9acc34c9ba9e1d608f8dfcb2499fd18d2de83daa Mon Sep 17 00:00:00 2001
From: Peter Serwylo <peter@serwylo.com>
Date: Mon, 19 Dec 2016 16:15:14 +1100
Subject: [PATCH] Tweak accessibility so that visually impaird people can use
 F-Droid well.

Things that are still not right:

 * BottomNavigationView doesn't read out the title of items when selected.
   Created this issue: https://code.google.com/p/android/issues/detail?id=230595&thanks=230595&ts=1482125499
 * TTS reader combines the app name and summary without a pause which is jarring.
 * Touching the background of the recycler view in the categories view reads all category names.
 * Likely other problems too.
---
 .../fdroid/fdroid/views/apps/CategoryTextWatcher.java  |  3 ++-
 .../fdroid/views/categories/CategoryController.java    |  1 +
 app/src/main/res/layout/app_card_featured.xml          |  6 ++++--
 app/src/main/res/layout/app_card_horizontal.xml        |  6 ++++--
 app/src/main/res/layout/app_card_large.xml             |  6 ++++--
 app/src/main/res/layout/app_card_list_item.xml         |  6 ++++--
 app/src/main/res/layout/app_list_item.xml              |  6 ++++--
 app/src/main/res/layout/fab_search.xml                 |  1 +
 app/src/main/res/menu/main_activity_screens.xml        | 10 +++++-----
 app/src/main/res/values/strings.xml                    |  8 +++++++-
 10 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/app/src/main/java/org/fdroid/fdroid/views/apps/CategoryTextWatcher.java b/app/src/main/java/org/fdroid/fdroid/views/apps/CategoryTextWatcher.java
index daad4a208..2d943cfae 100644
--- a/app/src/main/java/org/fdroid/fdroid/views/apps/CategoryTextWatcher.java
+++ b/app/src/main/java/org/fdroid/fdroid/views/apps/CategoryTextWatcher.java
@@ -139,7 +139,8 @@ public class CategoryTextWatcher implements TextWatcher {
             if (Build.VERSION.SDK_INT >= 21) {
                 // For accessibility reasons, make this more clear to screen readers that the
                 // span we just added semantically represents a category.
-                TtsSpan ttsSpan = new TtsSpan.TextBuilder(context.getString(R.string.category)).build();
+                CharSequence categoryName = textToSpannify.subSequence(0, colonIndex);
+                TtsSpan ttsSpan = new TtsSpan.TextBuilder(context.getString(R.string.tts_category_name, categoryName)).build();
                 textToSpannify.setSpan(ttsSpan, 0, 0, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             }
         }
diff --git a/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java b/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java
index 402239f0c..822236a23 100644
--- a/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java
+++ b/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java
@@ -121,6 +121,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
             int numAppsInCategory = cursor.getInt(0);
             viewAll.setVisibility(View.VISIBLE);
             viewAll.setText(activity.getResources().getQuantityString(R.plurals.button_view_all_apps_in_category, numAppsInCategory, numAppsInCategory));
+            viewAll.setContentDescription(activity.getResources().getQuantityString(R.plurals.tts_view_all_in_category, numAppsInCategory, numAppsInCategory, currentCategory));
         }
     }
 
diff --git a/app/src/main/res/layout/app_card_featured.xml b/app/src/main/res/layout/app_card_featured.xml
index e4b163856..1164db874 100644
--- a/app/src/main/res/layout/app_card_featured.xml
+++ b/app/src/main/res/layout/app_card_featured.xml
@@ -40,15 +40,17 @@
             android:layout_height="wrap_content"
             android:layout_margin="12dp">
 
+            <!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
+                 when it will inevitably read out the name of the app straight after. -->
             <ImageView
                 android:id="@+id/icon"
-                android:contentDescription="@string/app_icon"
                 android:layout_width="48dp"
                 android:layout_height="48dp"
                 tools:src="@drawable/ic_launcher"
                 android:scaleType="fitCenter"
                 app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent" />
+                app:layout_constraintTop_toTopOf="parent"
+                tools:ignore="ContentDescription" />
 
             <TextView
                 tools:text="F-Droid An application summary which takes up too much space and must ellipsize, perhaps after wrapping to a new line"
diff --git a/app/src/main/res/layout/app_card_horizontal.xml b/app/src/main/res/layout/app_card_horizontal.xml
index 9baf5f7f0..d1bfd0e92 100644
--- a/app/src/main/res/layout/app_card_horizontal.xml
+++ b/app/src/main/res/layout/app_card_horizontal.xml
@@ -10,15 +10,17 @@
         android:layout_height="wrap_content"
         android:layout_margin="8dp">
 
+        <!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
+             when it will inevitably read out the name of the app straight after. -->
         <ImageView
             android:id="@+id/icon"
-            android:contentDescription="@string/app_icon"
             android:layout_width="48dp"
             android:layout_height="48dp"
             tools:src="@drawable/ic_launcher"
             android:scaleType="fitCenter"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            app:layout_constraintTop_toTopOf="parent"
+            tools:ignore="ContentDescription" />
 
         <TextView
             tools:text="F-Droid An application summary which takes up too much space and must ellipsize"
diff --git a/app/src/main/res/layout/app_card_large.xml b/app/src/main/res/layout/app_card_large.xml
index df691a2ff..9c48664e8 100644
--- a/app/src/main/res/layout/app_card_large.xml
+++ b/app/src/main/res/layout/app_card_large.xml
@@ -10,9 +10,10 @@
         android:layout_height="match_parent"
         android:layout_margin="8dp">
 
+        <!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
+             when it will inevitably read out the name of the app straight after. -->
         <ImageView
             android:id="@+id/icon"
-            android:contentDescription="@string/app_icon"
             android:layout_width="96dip"
             android:layout_height="96dip"
             tools:src="@drawable/ic_launcher"
@@ -25,7 +26,8 @@
             android:layout_marginBottom="8dp"
             app:layout_constraintRight_toRightOf="parent"
             app:layout_constraintLeft_toLeftOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            app:layout_constraintTop_toTopOf="parent"
+            tools:ignore="ContentDescription" />
 
         <TextView
             tools:text="F-Droid An application summary which takes up too much space and must ellipsize"
diff --git a/app/src/main/res/layout/app_card_list_item.xml b/app/src/main/res/layout/app_card_list_item.xml
index 5373d6cd4..7c36310d2 100644
--- a/app/src/main/res/layout/app_card_list_item.xml
+++ b/app/src/main/res/layout/app_card_list_item.xml
@@ -10,15 +10,17 @@
         android:layout_height="match_parent"
         android:layout_margin="8dp">
 
+        <!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
+             when it will inevitably read out the name of the app straight after. -->
         <ImageView
             android:id="@+id/icon"
-            android:contentDescription="@string/app_icon"
             android:layout_width="48dp"
             android:layout_height="48dp"
             tools:src="@drawable/ic_launcher"
             android:scaleType="fitCenter"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            app:layout_constraintTop_toTopOf="parent"
+            tools:ignore="ContentDescription" />
 
         <TextView
             tools:text="F-Droid An application summary which takes up too much space and must ellipsize"
diff --git a/app/src/main/res/layout/app_list_item.xml b/app/src/main/res/layout/app_list_item.xml
index bfcaac064..9e487ca3d 100644
--- a/app/src/main/res/layout/app_list_item.xml
+++ b/app/src/main/res/layout/app_list_item.xml
@@ -6,18 +6,20 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <!-- Ignore ContentDescription because it is kind of meaningless to have TTS read out "App icon"
+         when it will inevitably read out the name of the app straight after. -->
     <ImageView
         android:id="@+id/icon"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
-        android:contentDescription="@string/app_icon"
         android:layout_width="48dp"
         android:layout_height="48dp"
         tools:src="@drawable/ic_launcher"
         android:scaleType="fitCenter"
         android:layout_marginStart="16dp"
         android:layout_marginLeft="16dp"
-        android:layout_marginTop="8dp" />
+        android:layout_marginTop="8dp"
+        tools:ignore="ContentDescription" />
 
     <TextView
         android:id="@+id/app_name"
diff --git a/app/src/main/res/layout/fab_search.xml b/app/src/main/res/layout/fab_search.xml
index 269ebdaf4..006bd38d4 100644
--- a/app/src/main/res/layout/fab_search.xml
+++ b/app/src/main/res/layout/fab_search.xml
@@ -3,6 +3,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/btn_search"
     android:src="@drawable/ic_search_white"
+    android:contentDescription="@string/menu_search"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom|end"
diff --git a/app/src/main/res/menu/main_activity_screens.xml b/app/src/main/res/menu/main_activity_screens.xml
index d2facc6ce..66e0feb76 100644
--- a/app/src/main/res/menu/main_activity_screens.xml
+++ b/app/src/main/res/menu/main_activity_screens.xml
@@ -4,26 +4,26 @@
     <item
         android:title="@string/main_menu__latest_apps"
         android:icon="@drawable/ic_overview"
-        app:showAsAction="ifRoom"
+        app:showAsAction="ifRoom|withText"
         android:id="@+id/whats_new" />
     <item
         android:title="@string/main_menu__categories"
         android:icon="@drawable/ic_category"
-        app:showAsAction="ifRoom"
+        app:showAsAction="ifRoom|withText"
         android:id="@+id/categories" />
     <item
         android:title="@string/main_menu__swap_nearby"
         android:icon="@drawable/ic_nearby"
-        app:showAsAction="ifRoom"
+        app:showAsAction="ifRoom|withText"
         android:id="@+id/nearby" />
     <item
         android:title="@string/main_menu__my_apps"
         android:icon="@drawable/ic_my_apps"
-        app:showAsAction="ifRoom"
+        app:showAsAction="ifRoom|withText"
         android:id="@+id/my_apps" />
     <item
         android:title="@string/menu_settings"
         android:icon="@drawable/ic_settings"
-        app:showAsAction="ifRoom"
+        app:showAsAction="ifRoom|withText"
         android:id="@+id/settings" />
 </menu>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bd5c70f67..5000f3f61 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -444,5 +444,11 @@
     <string name="notification_action_cancel">Cancel</string>
     <string name="notification_action_install">Install</string>
 
-    <string name="category">Category</string>
+    <!-- Used by the TTS engine when showing a category "Chip" in the search box -->
+    <string name="tts_category_name">Category %1$s</string>
+
+    <plurals name="tts_view_all_in_category">
+        <item quantity="one">View the single one app in the %2$s category</item>
+        <item quantity="other">View all %1$d apps from the %2$s category</item>
+    </plurals>
 </resources>