Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view.accessibility; |
| 18 | |
| 19 | import android.accessibilityservice.AccessibilityService; |
| 20 | import android.view.View; |
| 21 | |
| 22 | import java.util.List; |
| 23 | |
| 24 | /** |
| 25 | * This class is the contract a client should implement to enable support of a |
| 26 | * virtual view hierarchy rooted at a given view for accessibility purposes. A virtual |
| 27 | * view hierarchy is a tree of imaginary Views that is reported as a part of the view |
| 28 | * hierarchy when an {@link AccessibilityService} explores the window content. |
| 29 | * Since the virtual View tree does not exist this class is responsible for |
| 30 | * managing the {@link AccessibilityNodeInfo}s describing that tree to accessibility |
| 31 | * services. |
| 32 | * </p> |
| 33 | * <p> |
| 34 | * The main use case of these APIs is to enable a custom view that draws complex content, |
| 35 | * for example a monthly calendar grid, to be presented as a tree of logical nodes, |
| 36 | * for example month days each containing events, thus conveying its logical structure. |
| 37 | * <p> |
| 38 | * <p> |
| 39 | * A typical use case is to override {@link View#getAccessibilityNodeProvider()} of the |
| 40 | * View that is a root of a virtual View hierarchy to return an instance of this class. |
| 41 | * In such a case this instance is responsible for managing {@link AccessibilityNodeInfo}s |
| 42 | * describing the virtual sub-tree rooted at the View including the one representing the |
| 43 | * View itself. Similarly the returned instance is responsible for performing accessibility |
| 44 | * actions on any virtual view or the root view itself. For example: |
| 45 | * </p> |
| 46 | * <pre> |
| 47 | * getAccessibilityNodeProvider( |
| 48 | * if (mAccessibilityNodeProvider == null) { |
| 49 | * mAccessibilityNodeProvider = new AccessibilityNodeProvider() { |
| 50 | * public boolean performAccessibilityAction(int action, int virtualDescendantId) { |
| 51 | * // Implementation. |
| 52 | * return false; |
| 53 | * } |
| 54 | * |
| 55 | * public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text, int virtualDescendantId) { |
| 56 | * // Implementation. |
| 57 | * return null; |
| 58 | * } |
| 59 | * |
| 60 | * public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualDescendantId) { |
| 61 | * // Implementation. |
| 62 | * return null; |
| 63 | * } |
| 64 | * }); |
| 65 | * return mAccessibilityNodeProvider; |
| 66 | * </pre> |
| 67 | */ |
| 68 | public abstract class AccessibilityNodeProvider { |
| 69 | |
| 70 | /** |
| 71 | * Returns an {@link AccessibilityNodeInfo} representing a virtual view, |
| 72 | * i.e. a descendant of the host View, with the given <code>virtualViewId</code> |
| 73 | * or the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. |
| 74 | * <p> |
| 75 | * A virtual descendant is an imaginary View that is reported as a part of the view |
| 76 | * hierarchy for accessibility purposes. This enables custom views that draw complex |
| 77 | * content to report them selves as a tree of virtual views, thus conveying their |
| 78 | * logical structure. |
| 79 | * </p> |
| 80 | * <p> |
| 81 | * The implementer is responsible for obtaining an accessibility node info from the |
| 82 | * pool of reusable instances and setting the desired properties of the node info |
| 83 | * before returning it. |
| 84 | * </p> |
| 85 | * |
| 86 | * @param virtualViewId A client defined virtual view id. |
| 87 | * @return A populated {@link AccessibilityNodeInfo} for a virtual descendant or the |
| 88 | * host View. |
| 89 | * |
| 90 | * @see AccessibilityNodeInfo |
| 91 | */ |
| 92 | public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Performs an accessibility action on a virtual view, i.e. a descendant of the |
| 98 | * host View, with the given <code>virtualViewId</code> or the host View itself |
| 99 | * if <code>virtualViewId</code> equals to {@link View#NO_ID}. |
| 100 | * |
| 101 | * @param action The action to perform. |
| 102 | * @param virtualViewId A client defined virtual view id. |
| 103 | * @return True if the action was performed. |
| 104 | * |
| 105 | * @see #createAccessibilityNodeInfo(int) |
| 106 | * @see AccessibilityNodeInfo |
| 107 | */ |
| 108 | public boolean performAccessibilityAction(int action, int virtualViewId) { |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Finds {@link AccessibilityNodeInfo}s by text. The match is case insensitive |
| 114 | * containment. The search is relative to the virtual view, i.e. a descendant of the |
| 115 | * host View, with the given <code>virtualViewId</code> or the host View itself |
| 116 | * <code>virtualViewId</code> equals to {@link View#NO_ID}. |
| 117 | * |
| 118 | * @param virtualViewId A client defined virtual view id which defined |
| 119 | * the root of the tree in which to perform the search. |
| 120 | * @param text The searched text. |
| 121 | * @return A list of node info. |
| 122 | * |
| 123 | * @see #createAccessibilityNodeInfo(int) |
| 124 | * @see AccessibilityNodeInfo |
| 125 | */ |
| 126 | public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text, |
| 127 | int virtualViewId) { |
| 128 | return null; |
| 129 | } |
| 130 | } |