Merge "docs: Modernized AccessibilityNodeProvider example" into qt-dev
am: e49cbb3a5d
Change-Id: I24a281dd7194ea5c731ecc02371734fe1fa315f8
This commit is contained in:
@@ -44,28 +44,126 @@ import java.util.List;
|
|||||||
* View itself. Similarly the returned instance is responsible for performing accessibility
|
* View itself. Similarly the returned instance is responsible for performing accessibility
|
||||||
* actions on any virtual view or the root view itself. For example:
|
* actions on any virtual view or the root view itself. For example:
|
||||||
* </p>
|
* </p>
|
||||||
* <pre>
|
* <div>
|
||||||
* getAccessibilityNodeProvider(
|
* <div class="ds-selector-tabs"><section><h3 id="kotlin">Kotlin</h3>
|
||||||
* if (mAccessibilityNodeProvider == null) {
|
* <pre class="prettyprint lang-kotlin">
|
||||||
* mAccessibilityNodeProvider = new AccessibilityNodeProvider() {
|
* // "view" is the View instance on which this class performs accessibility functions.
|
||||||
* public boolean performAction(int action, int virtualDescendantId) {
|
* class MyCalendarViewAccessibilityDelegate(
|
||||||
* // Implementation.
|
* private var view: MyCalendarView) : AccessibilityDelegate() {
|
||||||
|
* override fun getAccessibilityNodeProvider(host: View): AccessibilityNodeProvider {
|
||||||
|
* return object : AccessibilityNodeProvider() {
|
||||||
|
* override fun createAccessibilityNodeInfo(virtualViewId: Int):
|
||||||
|
* AccessibilityNodeInfo? {
|
||||||
|
* when (virtualViewId) {
|
||||||
|
* <var>host-view-id</var> -> {
|
||||||
|
* val node = AccessibilityNodeInfo.obtain(view)
|
||||||
|
* node.addChild(view, <var>child-view-id</var>)
|
||||||
|
* // Set other attributes like screenReaderFocusable
|
||||||
|
* // and contentDescription.
|
||||||
|
* return node
|
||||||
|
* }
|
||||||
|
* <var>child-view-id</var> -> {
|
||||||
|
* val node = AccessibilityNodeInfo
|
||||||
|
* .obtain(view, virtualViewId)
|
||||||
|
* node.setParent(view)
|
||||||
|
* node.addAction(ACTION_SCROLL_UP)
|
||||||
|
* node.addAction(ACTION_SCROLL_DOWN)
|
||||||
|
* // Set other attributes like focusable and visibleToUser.
|
||||||
|
* node.setBoundsInScreen(
|
||||||
|
* Rect(<var>coords-of-edges-relative-to-screen</var>))
|
||||||
|
* return node
|
||||||
|
* }
|
||||||
|
* else -> return null
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* override fun performAction(
|
||||||
|
* virtualViewId: Int,
|
||||||
|
* action: Int,
|
||||||
|
* arguments: Bundle
|
||||||
|
* ): Boolean {
|
||||||
|
* if (virtualViewId == <var>host-view-id</var>) {
|
||||||
|
* return view.performAccessibilityAction(action, arguments)
|
||||||
|
* }
|
||||||
|
* when (action) {
|
||||||
|
* ACTION_SCROLL_UP.id -> {
|
||||||
|
* // Implement logic in a separate method.
|
||||||
|
* navigateToPreviousMonth()
|
||||||
|
*
|
||||||
|
* return true
|
||||||
|
* }
|
||||||
|
* ACTION_SCROLL_DOWN.id ->
|
||||||
|
* // Implement logic in a separate method.
|
||||||
|
* navigateToNextMonth()
|
||||||
|
*
|
||||||
|
* return true
|
||||||
|
* else -> return false
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* </section><section><h3 id="java">Java</h3>
|
||||||
|
* <pre class="prettyprint lang-java">
|
||||||
|
* final class MyCalendarViewAccessibilityDelegate extends AccessibilityDelegate {
|
||||||
|
* // The View instance on which this class performs accessibility functions.
|
||||||
|
* private final MyCalendarView view;
|
||||||
|
*
|
||||||
|
* MyCalendarViewAccessibilityDelegate(MyCalendarView view) {
|
||||||
|
* this.view = view;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Override
|
||||||
|
* public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) {
|
||||||
|
* return new AccessibilityNodeProvider() {
|
||||||
|
* @Override
|
||||||
|
* @Nullable
|
||||||
|
* public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
|
||||||
|
* if (virtualViewId == <var>host-view-id</var>) {
|
||||||
|
* AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(view);
|
||||||
|
* node.addChild(view, <var>child-view-id</var>);
|
||||||
|
* // Set other attributes like screenReaderFocusable and contentDescription.
|
||||||
|
* return node;
|
||||||
|
* } else if (virtualViewId == <var>child-view-id</var>) {
|
||||||
|
* AccessibilityNodeInfo node =
|
||||||
|
* AccessibilityNodeInfo.obtain(view, virtualViewId);
|
||||||
|
* node.setParent(view);
|
||||||
|
* node.addAction(ACTION_SCROLL_UP);
|
||||||
|
* node.addAction(ACTION_SCROLL_DOWN);
|
||||||
|
* // Set other attributes like focusable and visibleToUser.
|
||||||
|
* node.setBoundsInScreen(
|
||||||
|
* new Rect(<var>coordinates-of-edges-relative-to-screen</var>));
|
||||||
|
* return node;
|
||||||
|
* } else {
|
||||||
|
* return null;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Override
|
||||||
|
* public boolean performAction(int virtualViewId, int action, Bundle arguments) {
|
||||||
|
* if (virtualViewId == <var>host-view-id</var>) {
|
||||||
|
* return view.performAccessibilityAction(action, arguments);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* if (action == ACTION_SCROLL_UP.getId()) {
|
||||||
|
* // Implement logic in a separate method.
|
||||||
|
* navigateToPreviousMonth();
|
||||||
|
*
|
||||||
|
* return true;
|
||||||
|
* } else if (action == ACTION_SCROLL_DOWN.getId()) {
|
||||||
|
* // Implement logic in a separate method.
|
||||||
|
* navigateToNextMonth();
|
||||||
|
*
|
||||||
|
* return true;
|
||||||
|
* } else {
|
||||||
* return false;
|
* return false;
|
||||||
* }
|
* }
|
||||||
*
|
* }
|
||||||
* public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text,
|
* };
|
||||||
* int virtualDescendantId) {
|
* }
|
||||||
* // Implementation.
|
* }
|
||||||
* return null;
|
* </pre></section></div></div>
|
||||||
* }
|
|
||||||
*
|
|
||||||
* public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualDescendantId) {
|
|
||||||
* // Implementation.
|
|
||||||
* return null;
|
|
||||||
* }
|
|
||||||
* });
|
|
||||||
* return mAccessibilityNodeProvider;
|
|
||||||
* </pre>
|
|
||||||
*/
|
*/
|
||||||
public abstract class AccessibilityNodeProvider {
|
public abstract class AccessibilityNodeProvider {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user