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; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 21 | import android.view.View; |
| 22 | |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
| 26 | * This class is the contract a client should implement to enable support of a |
| 27 | * virtual view hierarchy rooted at a given view for accessibility purposes. A virtual |
| 28 | * view hierarchy is a tree of imaginary Views that is reported as a part of the view |
| 29 | * hierarchy when an {@link AccessibilityService} explores the window content. |
| 30 | * Since the virtual View tree does not exist this class is responsible for |
| 31 | * managing the {@link AccessibilityNodeInfo}s describing that tree to accessibility |
| 32 | * services. |
| 33 | * </p> |
| 34 | * <p> |
| 35 | * The main use case of these APIs is to enable a custom view that draws complex content, |
| 36 | * for example a monthly calendar grid, to be presented as a tree of logical nodes, |
| 37 | * for example month days each containing events, thus conveying its logical structure. |
| 38 | * <p> |
| 39 | * <p> |
| 40 | * A typical use case is to override {@link View#getAccessibilityNodeProvider()} of the |
| 41 | * View that is a root of a virtual View hierarchy to return an instance of this class. |
| 42 | * In such a case this instance is responsible for managing {@link AccessibilityNodeInfo}s |
| 43 | * describing the virtual sub-tree rooted at the View including the one representing the |
| 44 | * View itself. Similarly the returned instance is responsible for performing accessibility |
| 45 | * actions on any virtual view or the root view itself. For example: |
| 46 | * </p> |
| 47 | * <pre> |
| 48 | * getAccessibilityNodeProvider( |
| 49 | * if (mAccessibilityNodeProvider == null) { |
| 50 | * mAccessibilityNodeProvider = new AccessibilityNodeProvider() { |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 51 | * public boolean performAction(int action, int virtualDescendantId) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 52 | * // Implementation. |
| 53 | * return false; |
| 54 | * } |
| 55 | * |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 56 | * public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text, |
| 57 | * int virtualDescendantId) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 58 | * // Implementation. |
| 59 | * return null; |
| 60 | * } |
| 61 | * |
| 62 | * public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualDescendantId) { |
| 63 | * // Implementation. |
| 64 | * return null; |
| 65 | * } |
| 66 | * }); |
| 67 | * return mAccessibilityNodeProvider; |
| 68 | * </pre> |
| 69 | */ |
| 70 | public abstract class AccessibilityNodeProvider { |
| 71 | |
| 72 | /** |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 73 | * The virtual id for the hosting View. |
| 74 | */ |
| 75 | public static final int HOST_VIEW_ID = -1; |
| 76 | |
| 77 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 78 | * Returns an {@link AccessibilityNodeInfo} representing a virtual view, |
Cindy Kuang | 12d3747 | 2017-08-09 10:08:15 -0700 | [diff] [blame] | 79 | * such as a descendant of the host View, with the given <code>virtualViewId</code> |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 80 | * or the host View itself if <code>virtualViewId</code> equals to {@link #HOST_VIEW_ID}. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 81 | * <p> |
| 82 | * A virtual descendant is an imaginary View that is reported as a part of the view |
| 83 | * hierarchy for accessibility purposes. This enables custom views that draw complex |
| 84 | * content to report them selves as a tree of virtual views, thus conveying their |
| 85 | * logical structure. |
| 86 | * </p> |
| 87 | * <p> |
| 88 | * The implementer is responsible for obtaining an accessibility node info from the |
| 89 | * pool of reusable instances and setting the desired properties of the node info |
| 90 | * before returning it. |
| 91 | * </p> |
| 92 | * |
| 93 | * @param virtualViewId A client defined virtual view id. |
| 94 | * @return A populated {@link AccessibilityNodeInfo} for a virtual descendant or the |
| 95 | * host View. |
| 96 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 97 | * @see View#createAccessibilityNodeInfo() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 98 | * @see AccessibilityNodeInfo |
| 99 | */ |
| 100 | public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { |
| 101 | return null; |
| 102 | } |
| 103 | |
| 104 | /** |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 105 | * Adds extra data to an {@link AccessibilityNodeInfo} based on an explicit request for the |
| 106 | * additional data. |
| 107 | * <p> |
| 108 | * This method only needs to be implemented if a virtual view offers to provide additional |
| 109 | * data. |
| 110 | * </p> |
| 111 | * |
| 112 | * @param virtualViewId The virtual view id used to create the node |
| 113 | * @param info The info to which to add the extra data |
| 114 | * @param extraDataKey A key specifying the type of extra data to add to the info. The |
| 115 | * extra data should be added to the {@link Bundle} returned by |
| 116 | * the info's {@link AccessibilityNodeInfo#getExtras} method. |
| 117 | * @param arguments A {@link Bundle} holding any arguments relevant for this request. |
| 118 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 119 | * @see AccessibilityNodeInfo#setAvailableExtraData(List) |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 120 | */ |
| 121 | public void addExtraDataToAccessibilityNodeInfo( |
| 122 | int virtualViewId, AccessibilityNodeInfo info, String extraDataKey, Bundle arguments) { |
| 123 | } |
| 124 | |
| 125 | /** |
Cindy Kuang | 12d3747 | 2017-08-09 10:08:15 -0700 | [diff] [blame] | 126 | * Performs an accessibility action on a virtual view, such as a descendant of the |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 127 | * host View, with the given <code>virtualViewId</code> or the host View itself |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 128 | * if <code>virtualViewId</code> equals to {@link #HOST_VIEW_ID}. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 129 | * |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 130 | * @param virtualViewId A client defined virtual view id. |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 131 | * @param action The action to perform. |
| 132 | * @param arguments Optional action arguments. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 133 | * @return True if the action was performed. |
| 134 | * |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 135 | * @see View#performAccessibilityAction(int, Bundle) |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 136 | * @see #createAccessibilityNodeInfo(int) |
| 137 | * @see AccessibilityNodeInfo |
| 138 | */ |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 139 | public boolean performAction(int virtualViewId, int action, Bundle arguments) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 140 | return false; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Finds {@link AccessibilityNodeInfo}s by text. The match is case insensitive |
| 145 | * containment. The search is relative to the virtual view, i.e. a descendant of the |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 146 | * host View, with the given <code>virtualViewId</code> or the host View itself |
| 147 | * <code>virtualViewId</code> equals to {@link #HOST_VIEW_ID}. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 148 | * |
| 149 | * @param virtualViewId A client defined virtual view id which defined |
| 150 | * the root of the tree in which to perform the search. |
| 151 | * @param text The searched text. |
| 152 | * @return A list of node info. |
| 153 | * |
| 154 | * @see #createAccessibilityNodeInfo(int) |
| 155 | * @see AccessibilityNodeInfo |
| 156 | */ |
| 157 | public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text, |
| 158 | int virtualViewId) { |
| 159 | return null; |
| 160 | } |
Alan Viverette | 2e1e081 | 2013-09-30 13:45:55 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
Cindy Kuang | 12d3747 | 2017-08-09 10:08:15 -0700 | [diff] [blame] | 163 | * Find the virtual view, such as a descendant of the host View, that has the |
Alan Viverette | 2e1e081 | 2013-09-30 13:45:55 -0700 | [diff] [blame] | 164 | * specified focus type. |
| 165 | * |
| 166 | * @param focus The focus to find. One of |
| 167 | * {@link AccessibilityNodeInfo#FOCUS_INPUT} or |
| 168 | * {@link AccessibilityNodeInfo#FOCUS_ACCESSIBILITY}. |
| 169 | * @return The node info of the focused view or null. |
| 170 | * @see AccessibilityNodeInfo#FOCUS_INPUT |
| 171 | * @see AccessibilityNodeInfo#FOCUS_ACCESSIBILITY |
| 172 | */ |
| 173 | public AccessibilityNodeInfo findFocus(int focus) { |
| 174 | return null; |
| 175 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 176 | } |