Announce in/out of list (flutter/engine#6918)
* Support in/out of list announcements on Android
This commit is contained in:
@@ -450,6 +450,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleV
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Predicate.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterMain.java
|
||||
|
||||
@@ -136,6 +136,7 @@ java_library("flutter_shell_java") {
|
||||
"io/flutter/plugin/platform/VirtualDisplayController.java",
|
||||
"io/flutter/util/PathUtils.java",
|
||||
"io/flutter/util/Preconditions.java",
|
||||
"io/flutter/util/Predicate.java",
|
||||
"io/flutter/view/AccessibilityBridge.java",
|
||||
"io/flutter/view/FlutterCallbackInformation.java",
|
||||
"io/flutter/view/FlutterMain.java",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package io.flutter.util;
|
||||
|
||||
// TODO(dnfield): remove this if/when we can use appcompat to support it.
|
||||
// java.util.function.Predicate isn't available until API24
|
||||
public interface Predicate<T> {
|
||||
public abstract boolean test(T t);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.accessibility.AccessibilityNodeProvider;
|
||||
import io.flutter.plugin.common.BasicMessageChannel;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import io.flutter.util.Predicate;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
@@ -125,6 +126,21 @@ class AccessibilityBridge
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldSetCollectionInfo(final SemanticsObject object) {
|
||||
// TalkBack expects a number of rows and/or columns greater than 0 to announce
|
||||
// in list and out of list. For an infinite or growing list, you have to
|
||||
// specify something > 0 to get "in list" announcements.
|
||||
// TalkBack will also only track one list at a time, so we only want to set this
|
||||
// for a list that contains the current a11y focused object - otherwise, if there
|
||||
// are two lists or nested lists, we may end up with announcements for only the last
|
||||
// one that is currently available in the semantics tree. However, we also want
|
||||
// to set it if we're exiting a list to a non-list, so that we can get the "out of list"
|
||||
// announcement when A11y focus moves out of a list and not into another list.
|
||||
return object.scrollChildren > 0
|
||||
&& (hasSemanticsObjectAncestor(mA11yFocusedObject, o -> o == object)
|
||||
|| !hasSemanticsObjectAncestor(mA11yFocusedObject, o -> o.hasFlag(Flag.HAS_IMPLICIT_SCROLLING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
|
||||
@@ -266,14 +282,35 @@ class AccessibilityBridge
|
||||
if (object.hasAction(Action.SCROLL_LEFT) || object.hasAction(Action.SCROLL_UP)
|
||||
|| object.hasAction(Action.SCROLL_RIGHT) || object.hasAction(Action.SCROLL_DOWN)) {
|
||||
result.setScrollable(true);
|
||||
|
||||
// This tells Android's a11y to send scroll events when reaching the end of
|
||||
// the visible viewport of a scrollable, unless the node itself does not
|
||||
// allow implicit scrolling - then we leave the className as view.View.
|
||||
//
|
||||
// We should prefer setCollectionInfo to the class names, as this way we get "In List"
|
||||
// and "Out of list" announcements. But we don't always know the counts, so we
|
||||
// can fallback to the generic scroll view class names.
|
||||
// TODO(dnfield): We should add semantics properties for rows and columns in 2 dimensional lists, e.g.
|
||||
// GridView. Right now, we're only supporting ListViews and only if they have scroll children.
|
||||
if (object.hasFlag(Flag.HAS_IMPLICIT_SCROLLING)) {
|
||||
if (object.hasAction(Action.SCROLL_LEFT) || object.hasAction(Action.SCROLL_RIGHT)) {
|
||||
result.setClassName("android.widget.HorizontalScrollView");
|
||||
if (shouldSetCollectionInfo(object)) {
|
||||
result.setCollectionInfo(AccessibilityNodeInfo.CollectionInfo.obtain(
|
||||
0, // rows
|
||||
object.scrollChildren, // columns
|
||||
false)); // hierarchical
|
||||
} else {
|
||||
result.setClassName("android.widget.HorizontalScrollView");
|
||||
}
|
||||
} else {
|
||||
result.setClassName("android.widget.ScrollView");
|
||||
if (shouldSetCollectionInfo(object)) {
|
||||
result.setCollectionInfo(AccessibilityNodeInfo.CollectionInfo.obtain(
|
||||
object.scrollChildren, // rows
|
||||
0, // columns
|
||||
false)); // hierarchical
|
||||
} else {
|
||||
result.setClassName("android.widget.ScrollView");
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO(ianh): Once we're on SDK v23+, call addAction to
|
||||
@@ -960,6 +997,11 @@ class AccessibilityBridge
|
||||
/// Value is derived from ACTION_TYPE_MASK in AccessibilityNodeInfo.java
|
||||
static int firstResourceId = 267386881;
|
||||
|
||||
|
||||
static boolean hasSemanticsObjectAncestor(SemanticsObject target, Predicate<SemanticsObject> tester) {
|
||||
return target != null && target.getAncestor(tester) != null;
|
||||
}
|
||||
|
||||
private class SemanticsObject {
|
||||
SemanticsObject() {}
|
||||
|
||||
@@ -1012,6 +1054,17 @@ class AccessibilityBridge
|
||||
private float[] globalTransform;
|
||||
private Rect globalRect;
|
||||
|
||||
SemanticsObject getAncestor(Predicate<SemanticsObject> tester) {
|
||||
SemanticsObject nextAncestor = parent;
|
||||
while (nextAncestor != null) {
|
||||
if (tester.test(nextAncestor)) {
|
||||
return nextAncestor;
|
||||
}
|
||||
nextAncestor = nextAncestor.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean hasAction(Action action) {
|
||||
return (actions & action.value) != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user