Bug 1390356: Do not focus tap-to-dismiss BottomSheetDialog view with Talkback. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 21 Aug 2017 14:09:28 -0700
changeset 650187 a6ee7a68e7f1ab8ec4099b4a0d0b02c808e83ff6
parent 650186 1d36a1f9add653d6bcec10b674007f19588ec4f7
child 650188 21b7312808389d8079c132bfa7dd79819463d82a
push id75295
push usermichael.l.comella@gmail.com
push dateTue, 22 Aug 2017 01:14:07 +0000
reviewerssebastian
bugs1390356
milestone57.0a1
Bug 1390356: Do not focus tap-to-dismiss BottomSheetDialog view with Talkback. r=sebastian MozReview-Commit-ID: CJ73kKDxctb
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
@@ -5,36 +5,39 @@
 package org.mozilla.gecko.activitystream.homepanel.menu;
 
 import android.app.Activity;
 import android.content.Context;
 import android.support.design.widget.BottomSheetBehavior;
 import android.support.design.widget.BottomSheetDialog;
 import android.support.design.widget.NavigationView;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.Window;
 import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 import org.mozilla.gecko.activitystream.homepanel.model.Item;
 import org.mozilla.gecko.activitystream.homepanel.stream.StreamOverridablePageIconLayout;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.URIUtils;
 
 import java.lang.ref.WeakReference;
 import java.net.URI;
 import java.net.URISyntaxException;
 
 /* package-private */ class BottomSheetContextMenu
         extends ActivityStreamContextMenu {
 
+    private static final String LOGTAG = "GeckoASBottomSheet";
 
     private final BottomSheetDialog bottomSheetDialog;
 
     private final NavigationView navigationView;
 
     private final View content;
     private final View activityView;
 
@@ -113,19 +116,48 @@ import java.net.URISyntaxException;
         // so we can remove that code then.
         if (activityView.getHeight() > activityView.getWidth()) {
             final int peekHeight = activityView.getHeight() - (activityView.getWidth() * 9 / 16);
 
             BottomSheetBehavior<View> bsBehaviour = BottomSheetBehavior.from((View) content.getParent());
             bsBehaviour.setPeekHeight(peekHeight);
         }
 
+        overrideBottomSheetDialogAccessibility();
         bottomSheetDialog.show();
     }
 
+    /**
+     * Overrides the default accessibility properties of the {@link BottomSheetDialog}.
+     * We do this because the dialog has undesirable behavior.
+     */
+    private void overrideBottomSheetDialogAccessibility() {
+        boolean isSuccess = true;
+        final Window window = bottomSheetDialog.getWindow();
+        if (window != null) {
+            // The dialog layout contains a view, R.id.touch_outside, that is placed outside the visible dialog and is used
+            // to dismiss the dialog when tapped. However, it gets focused in Talkback which is unintuitive to Talkback
+            // users (who are accustomed to using the back button for such use cases) so we hide it for a11y here.
+            //
+            // NB: this is fixed in later versions of the support library than the we're using, see most recent source:
+            // https://android.googlesource.com/platform/frameworks/support/+/461d9c4b4b51cd552fc890d7feb001c6bd2097ea/design/res/layout/design_bottom_sheet_dialog.xml
+            // I opted not to update to save time (we have an AS deadline) and to prevent possible regressions.
+            final View tapToDismissView = window.findViewById(android.support.design.R.id.touch_outside);
+            if (tapToDismissView != null) {
+                tapToDismissView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
+            } else {
+                isSuccess = false;
+            }
+        }
+
+        if (!isSuccess) {
+            Log.w(LOGTAG, "Unable to fully override Activity Stream bottom sheet accessibility behavior.");
+        }
+    }
+
     public void dismiss() {
         bottomSheetDialog.dismiss();
     }
 
     /** Updates the given TextView's text to the page domain. */
     private static class UpdatePageDomainAsyncTask extends URIUtils.GetFormattedDomainAsyncTask {
         private final WeakReference<TextView> pageDomainViewWeakReference;