Bug 1315201: 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 651660 60f757b5f890d3e8fce71adad959123b51122a16
parent 651659 c901e82c9bda8ba9c29a6c41548ff4ca6f3db10f
child 651661 4c02c8b477d071ff8014c0b9ec6863a996bc2c82
push id75787
push usermichael.l.comella@gmail.com
push dateWed, 23 Aug 2017 22:00:44 +0000
reviewerssebastian
bugs1315201
milestone57.0a1
Bug 1315201: 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;