The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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; |
| 18 | |
| 19 | import android.graphics.Rect; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 20 | import android.view.accessibility.AccessibilityEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Defines the responsibilities for a class that will be a parent of a View. |
| 24 | * This is the API that a view sees when it wants to interact with its parent. |
| 25 | * |
| 26 | */ |
| 27 | public interface ViewParent { |
| 28 | /** |
| 29 | * Called when something has changed which has invalidated the layout of a |
| 30 | * child of this view parent. This will schedule a layout pass of the view |
| 31 | * tree. |
| 32 | */ |
| 33 | public void requestLayout(); |
| 34 | |
| 35 | /** |
| 36 | * Indicates whether layout was requested on this view parent. |
| 37 | * |
| 38 | * @return true if layout was requested, false otherwise |
| 39 | */ |
| 40 | public boolean isLayoutRequested(); |
| 41 | |
| 42 | /** |
| 43 | * Called when a child wants the view hierarchy to gather and report |
| 44 | * transparent regions to the window compositor. Views that "punch" holes in |
| 45 | * the view hierarchy, such as SurfaceView can use this API to improve |
| 46 | * performance of the system. When no such a view is present in the |
| 47 | * hierarchy, this optimization in unnecessary and might slightly reduce the |
| 48 | * view hierarchy performance. |
| 49 | * |
| 50 | * @param child the view requesting the transparent region computation |
| 51 | * |
| 52 | */ |
| 53 | public void requestTransparentRegion(View child); |
| 54 | |
| 55 | /** |
| 56 | * All or part of a child is dirty and needs to be redrawn. |
| 57 | * |
| 58 | * @param child The child which is dirty |
| 59 | * @param r The area within the child that is invalid |
| 60 | */ |
| 61 | public void invalidateChild(View child, Rect r); |
| 62 | |
| 63 | /** |
| 64 | * All or part of a child is dirty and needs to be redrawn. |
| 65 | * |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 66 | * <p>The location array is an array of two int values which respectively |
| 67 | * define the left and the top position of the dirty child.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | * |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 69 | * <p>This method must return the parent of this ViewParent if the specified |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | * rectangle must be invalidated in the parent. If the specified rectangle |
| 71 | * does not require invalidation in the parent or if the parent does not |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 72 | * exist, this method must return null.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | * |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 74 | * <p>When this method returns a non-null value, the location array must |
| 75 | * have been updated with the left and top coordinates of this ViewParent.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | * |
| 77 | * @param location An array of 2 ints containing the left and top |
| 78 | * coordinates of the child to invalidate |
| 79 | * @param r The area within the child that is invalid |
| 80 | * |
| 81 | * @return the parent of this ViewParent or null |
| 82 | */ |
| 83 | public ViewParent invalidateChildInParent(int[] location, Rect r); |
| 84 | |
| 85 | /** |
| 86 | * Returns the parent if it exists, or null. |
| 87 | * |
| 88 | * @return a ViewParent or null if this ViewParent does not have a parent |
| 89 | */ |
| 90 | public ViewParent getParent(); |
| 91 | |
| 92 | /** |
| 93 | * Called when a child of this parent wants focus |
| 94 | * |
| 95 | * @param child The child of this ViewParent that wants focus. This view |
| 96 | * will contain the focused view. It is not necessarily the view that |
| 97 | * actually has focus. |
| 98 | * @param focused The view that is a descendant of child that actually has |
| 99 | * focus |
| 100 | */ |
| 101 | public void requestChildFocus(View child, View focused); |
| 102 | |
| 103 | /** |
| 104 | * Tell view hierarchy that the global view attributes need to be |
| 105 | * re-evaluated. |
| 106 | * |
| 107 | * @param child View whose attributes have changed. |
| 108 | */ |
| 109 | public void recomputeViewAttributes(View child); |
| 110 | |
| 111 | /** |
| 112 | * Called when a child of this parent is giving up focus |
| 113 | * |
| 114 | * @param child The view that is giving up focus |
| 115 | */ |
| 116 | public void clearChildFocus(View child); |
| 117 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 118 | /** |
| 119 | * Compute the visible part of a rectangular region defined in terms of a child view's |
| 120 | * coordinates. |
| 121 | * |
| 122 | * <p>Returns the clipped visible part of the rectangle <code>r</code>, defined in the |
| 123 | * <code>child</code>'s local coordinate system. <code>r</code> is modified by this method to |
| 124 | * contain the result, expressed in the global (root) coordinate system.</p> |
| 125 | * |
| 126 | * <p>The resulting rectangle is always axis aligned. If a rotation is applied to a node in the |
| 127 | * View hierarchy, the result is the axis-aligned bounding box of the visible rectangle.</p> |
| 128 | * |
| 129 | * @param child A child View, whose rectangular visible region we want to compute |
| 130 | * @param r The input rectangle, defined in the child coordinate system. Will be overwritten to |
| 131 | * contain the resulting visible rectangle, expressed in global (root) coordinates |
| 132 | * @param offset The input coordinates of a point, defined in the child coordinate system. |
| 133 | * As with the <code>r</code> parameter, this will be overwritten to contain the global (root) |
| 134 | * coordinates of that point. |
| 135 | * A <code>null</code> value is valid (in case you are not interested in this result) |
| 136 | * @return true if the resulting rectangle is not empty, false otherwise |
| 137 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset); |
| 139 | |
| 140 | /** |
| 141 | * Find the nearest view in the specified direction that wants to take focus |
| 142 | * |
| 143 | * @param v The view that currently has focus |
| 144 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 145 | */ |
| 146 | public View focusSearch(View v, int direction); |
| 147 | |
| 148 | /** |
Chet Haase | 0187a5d | 2013-04-23 06:55:04 -0700 | [diff] [blame] | 149 | * Change the z order of the child so it's on top of all other children. |
| 150 | * This ordering change may affect layout, if this container |
| 151 | * uses an order-dependent layout scheme (e.g., LinearLayout). This |
| 152 | * method should be followed by calls to {@link #requestLayout()} and |
| 153 | * {@link View#invalidate()} on this parent. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | * |
Chet Haase | 0187a5d | 2013-04-23 06:55:04 -0700 | [diff] [blame] | 155 | * @param child The child to bring to the top of the z order |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | */ |
| 157 | public void bringChildToFront(View child); |
| 158 | |
| 159 | /** |
| 160 | * Tells the parent that a new focusable view has become available. This is |
| 161 | * to handle transitions from the case where there are no focusable views to |
| 162 | * the case where the first focusable view appears. |
| 163 | * |
| 164 | * @param v The view that has become newly focusable |
| 165 | */ |
| 166 | public void focusableViewAvailable(View v); |
| 167 | |
| 168 | /** |
| 169 | * Bring up a context menu for the specified view or its ancestors. |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 170 | * |
| 171 | * <p>In most cases, a subclass does not need to override this. However, if |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | * the subclass is added directly to the window manager (for example, |
| 173 | * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 174 | * then it should override this and show the context menu.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | * |
| 176 | * @param originalView The source view where the context menu was first invoked |
| 177 | * @return true if a context menu was displayed |
| 178 | */ |
| 179 | public boolean showContextMenuForChild(View originalView); |
| 180 | |
| 181 | /** |
| 182 | * Have the parent populate the specified context menu if it has anything to |
| 183 | * add (and then recurse on its parent). |
| 184 | * |
| 185 | * @param menu The menu to populate |
| 186 | */ |
| 187 | public void createContextMenu(ContextMenu menu); |
| 188 | |
| 189 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 190 | * Start an action mode for the specified view. |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 191 | * |
| 192 | * <p>In most cases, a subclass does not need to override this. However, if the |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 193 | * subclass is added directly to the window manager (for example, |
| 194 | * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 195 | * then it should override this and start the action mode.</p> |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 196 | * |
| 197 | * @param originalView The source view where the action mode was first invoked |
| 198 | * @param callback The callback that will handle lifecycle events for the action mode |
| 199 | * @return The new action mode if it was started, null otherwise |
| 200 | */ |
| 201 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback); |
| 202 | |
| 203 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | * This method is called on the parent when a child's drawable state |
| 205 | * has changed. |
| 206 | * |
| 207 | * @param child The child whose drawable state has changed. |
| 208 | */ |
| 209 | public void childDrawableStateChanged(View child); |
| 210 | |
| 211 | /** |
| 212 | * Called when a child does not want this parent and its ancestors to |
| 213 | * intercept touch events with |
| 214 | * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}. |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 215 | * |
| 216 | * <p>This parent should pass this call onto its parents. This parent must obey |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * this request for the duration of the touch (that is, only clear the flag |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 218 | * after this parent has received an up or a cancel.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | * |
| 220 | * @param disallowIntercept True if the child does not want the parent to |
| 221 | * intercept touch events. |
| 222 | */ |
| 223 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept); |
| 224 | |
| 225 | /** |
| 226 | * Called when a child of this group wants a particular rectangle to be |
| 227 | * positioned onto the screen. {@link ViewGroup}s overriding this can trust |
| 228 | * that: |
| 229 | * <ul> |
| 230 | * <li>child will be a direct child of this group</li> |
| 231 | * <li>rectangle will be in the child's coordinates</li> |
| 232 | * </ul> |
| 233 | * |
| 234 | * <p>{@link ViewGroup}s overriding this should uphold the contract:</p> |
| 235 | * <ul> |
| 236 | * <li>nothing will change if the rectangle is already visible</li> |
| 237 | * <li>the view port will be scrolled only just enough to make the |
| 238 | * rectangle visible</li> |
| 239 | * <ul> |
| 240 | * |
| 241 | * @param child The direct child making the request. |
| 242 | * @param rectangle The rectangle in the child's coordinates the child |
| 243 | * wishes to be on the screen. |
| 244 | * @param immediate True to forbid animated or delayed scrolling, |
| 245 | * false otherwise |
| 246 | * @return Whether the group scrolled to handle the operation |
| 247 | */ |
| 248 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, |
| 249 | boolean immediate); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * Called by a child to request from its parent to send an {@link AccessibilityEvent}. |
| 253 | * The child has already populated a record for itself in the event and is delegating |
| 254 | * to its parent to send the event. The parent can optionally add a record for itself. |
| 255 | * <p> |
| 256 | * Note: An accessibility event is fired by an individual view which populates the |
| 257 | * event with a record for its state and requests from its parent to perform |
| 258 | * the sending. The parent can optionally add a record for itself before |
| 259 | * dispatching the request to its parent. A parent can also choose not to |
| 260 | * respect the request for sending the event. The accessibility event is sent |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 261 | * by the topmost view in the view tree.</p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 262 | * |
| 263 | * @param child The child which requests sending the event. |
| 264 | * @param event The event to be sent. |
| 265 | * @return True if the event was sent. |
| 266 | */ |
| 267 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event); |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * Called when a child view now has or no longer is tracking transient state. |
| 271 | * |
| 272 | * @param child Child view whose state has changed |
| 273 | * @param hasTransientState true if this child has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 274 | */ |
| 275 | public void childHasTransientStateChanged(View child, boolean hasTransientState); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * Ask that a new dispatch of {@link View#fitSystemWindows(Rect) |
| 279 | * View.fitSystemWindows(Rect)} be performed. |
| 280 | */ |
| 281 | public void requestFitSystemWindows(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * Gets the parent of a given View for accessibility. Since some Views are not |
| 285 | * exposed to the accessibility layer the parent for accessibility is not |
| 286 | * necessarily the direct parent of the View, rather it is a predecessor. |
| 287 | * |
| 288 | * @return The parent or <code>null</code> if no such is found. |
| 289 | */ |
| 290 | public ViewParent getParentForAccessibility(); |
| 291 | |
| 292 | /** |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 293 | * A child notifies its parent that the accessibility state of a subtree rooted |
| 294 | * at a given node changed. That is the structure of the subtree is different. |
| 295 | * |
Adam Powell | 504a10f | 2013-07-11 15:25:59 -0700 | [diff] [blame] | 296 | * @param root The root of the changed subtree. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 297 | */ |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 298 | public void childAccessibilityStateChanged(View root); |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Tells if this view parent can resolve the layout direction. |
| 302 | * See {@link View#setLayoutDirection(int)} |
| 303 | * |
| 304 | * @return True if this view parent can resolve the layout direction. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 305 | */ |
| 306 | public boolean canResolveLayoutDirection(); |
| 307 | |
| 308 | /** |
| 309 | * Tells if this view parent layout direction is resolved. |
| 310 | * See {@link View#setLayoutDirection(int)} |
| 311 | * |
| 312 | * @return True if this view parent layout direction is resolved. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 313 | */ |
| 314 | public boolean isLayoutDirectionResolved(); |
| 315 | |
| 316 | /** |
| 317 | * Return this view parent layout direction. See {@link View#getLayoutDirection()} |
| 318 | * |
| 319 | * @return {@link View#LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
| 320 | * {@link View#LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 321 | */ |
| 322 | public int getLayoutDirection(); |
| 323 | |
| 324 | /** |
| 325 | * Tells if this view parent can resolve the text direction. |
| 326 | * See {@link View#setTextDirection(int)} |
| 327 | * |
| 328 | * @return True if this view parent can resolve the text direction. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 329 | */ |
| 330 | public boolean canResolveTextDirection(); |
| 331 | |
| 332 | /** |
| 333 | * Tells if this view parent text direction is resolved. |
| 334 | * See {@link View#setTextDirection(int)} |
| 335 | * |
| 336 | * @return True if this view parent text direction is resolved. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 337 | */ |
| 338 | public boolean isTextDirectionResolved(); |
| 339 | |
| 340 | /** |
| 341 | * Return this view parent text direction. See {@link View#getTextDirection()} |
| 342 | * |
| 343 | * @return the resolved text direction. Returns one of: |
| 344 | * |
| 345 | * {@link View#TEXT_DIRECTION_FIRST_STRONG} |
| 346 | * {@link View#TEXT_DIRECTION_ANY_RTL}, |
| 347 | * {@link View#TEXT_DIRECTION_LTR}, |
| 348 | * {@link View#TEXT_DIRECTION_RTL}, |
| 349 | * {@link View#TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 350 | */ |
| 351 | public int getTextDirection(); |
| 352 | |
| 353 | /** |
| 354 | * Tells if this view parent can resolve the text alignment. |
| 355 | * See {@link View#setTextAlignment(int)} |
| 356 | * |
| 357 | * @return True if this view parent can resolve the text alignment. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 358 | */ |
| 359 | public boolean canResolveTextAlignment(); |
| 360 | |
| 361 | /** |
| 362 | * Tells if this view parent text alignment is resolved. |
| 363 | * See {@link View#setTextAlignment(int)} |
| 364 | * |
| 365 | * @return True if this view parent text alignment is resolved. |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 366 | */ |
| 367 | public boolean isTextAlignmentResolved(); |
| 368 | |
| 369 | /** |
| 370 | * Return this view parent text alignment. See {@link android.view.View#getTextAlignment()} |
| 371 | * |
| 372 | * @return the resolved text alignment. Returns one of: |
| 373 | * |
| 374 | * {@link View#TEXT_ALIGNMENT_GRAVITY}, |
| 375 | * {@link View#TEXT_ALIGNMENT_CENTER}, |
| 376 | * {@link View#TEXT_ALIGNMENT_TEXT_START}, |
| 377 | * {@link View#TEXT_ALIGNMENT_TEXT_END}, |
| 378 | * {@link View#TEXT_ALIGNMENT_VIEW_START}, |
| 379 | * {@link View#TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 380 | */ |
| 381 | public int getTextAlignment(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | } |