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.annotation.NonNull;
20 import android.graphics.Rect;
21 import android.graphics.Region;
22 import android.os.Bundle;
23 import android.view.accessibility.AccessibilityEvent;
24 
25 /**
26  * Defines the responsibilities for a class that will be a parent of a View.
27  * This is the API that a view sees when it wants to interact with its parent.
28  *
29  */
30 public interface ViewParent {
31     /**
32      * Called when something has changed which has invalidated the layout of a
33      * child of this view parent. This will schedule a layout pass of the view
34      * tree.
35      */
requestLayout()36     public void requestLayout();
37 
38     /**
39      * Indicates whether layout was requested on this view parent.
40      *
41      * @return true if layout was requested, false otherwise
42      */
isLayoutRequested()43     public boolean isLayoutRequested();
44 
45     /**
46      * Called when a child wants the view hierarchy to gather and report
47      * transparent regions to the window compositor. Views that "punch" holes in
48      * the view hierarchy, such as SurfaceView can use this API to improve
49      * performance of the system. When no such a view is present in the
50      * hierarchy, this optimization in unnecessary and might slightly reduce the
51      * view hierarchy performance.
52      *
53      * @param child the view requesting the transparent region computation
54      *
55      */
requestTransparentRegion(View child)56     public void requestTransparentRegion(View child);
57 
58 
59     /**
60      * The target View has been invalidated, or has had a drawing property changed that
61      * requires the hierarchy to re-render.
62      *
63      * This method is called by the View hierarchy to signal ancestors that a View either needs to
64      * re-record its drawing commands, or drawing properties have changed. This is how Views
65      * schedule a drawing traversal.
66      *
67      * This signal is generally only dispatched for attached Views, since only they need to draw.
68      *
69      * @param child Direct child of this ViewParent containing target
70      * @param target The view that needs to redraw
71      */
onDescendantInvalidated(@onNull View child, @NonNull View target)72     default void onDescendantInvalidated(@NonNull View child, @NonNull View target) {
73         if (getParent() != null) {
74             // Note: should pass 'this' as default, but can't since we may not be a View
75             getParent().onDescendantInvalidated(child, target);
76         }
77     }
78 
79     /**
80      * All or part of a child is dirty and needs to be redrawn.
81      *
82      * @param child The child which is dirty
83      * @param r The area within the child that is invalid
84      *
85      * @deprecated Use {@link #onDescendantInvalidated(View, View)} instead.
86      */
87     @Deprecated
invalidateChild(View child, Rect r)88     public void invalidateChild(View child, Rect r);
89 
90     /**
91      * All or part of a child is dirty and needs to be redrawn.
92      *
93      * <p>The location array is an array of two int values which respectively
94      * define the left and the top position of the dirty child.</p>
95      *
96      * <p>This method must return the parent of this ViewParent if the specified
97      * rectangle must be invalidated in the parent. If the specified rectangle
98      * does not require invalidation in the parent or if the parent does not
99      * exist, this method must return null.</p>
100      *
101      * <p>When this method returns a non-null value, the location array must
102      * have been updated with the left and top coordinates of this ViewParent.</p>
103      *
104      * @param location An array of 2 ints containing the left and top
105      *        coordinates of the child to invalidate
106      * @param r The area within the child that is invalid
107      *
108      * @return the parent of this ViewParent or null
109      *
110      * @deprecated Use {@link #onDescendantInvalidated(View, View)} instead.
111      */
112     @Deprecated
invalidateChildInParent(int[] location, Rect r)113     public ViewParent invalidateChildInParent(int[] location, Rect r);
114 
115     /**
116      * Returns the parent if it exists, or null.
117      *
118      * @return a ViewParent or null if this ViewParent does not have a parent
119      */
getParent()120     public ViewParent getParent();
121 
122     /**
123      * Called when a child of this parent wants focus
124      *
125      * @param child The child of this ViewParent that wants focus. This view
126      *        will contain the focused view. It is not necessarily the view that
127      *        actually has focus.
128      * @param focused The view that is a descendant of child that actually has
129      *        focus
130      */
requestChildFocus(View child, View focused)131     public void requestChildFocus(View child, View focused);
132 
133     /**
134      * Tell view hierarchy that the global view attributes need to be
135      * re-evaluated.
136      *
137      * @param child View whose attributes have changed.
138      */
recomputeViewAttributes(View child)139     public void recomputeViewAttributes(View child);
140 
141     /**
142      * Called when a child of this parent is giving up focus
143      *
144      * @param child The view that is giving up focus
145      */
clearChildFocus(View child)146     public void clearChildFocus(View child);
147 
148     /**
149      * Compute the visible part of a rectangular region defined in terms of a child view's
150      * coordinates.
151      *
152      * <p>Returns the clipped visible part of the rectangle <code>r</code>, defined in the
153      * <code>child</code>'s local coordinate system. <code>r</code> is modified by this method to
154      * contain the result, expressed in the global (root) coordinate system.</p>
155      *
156      * <p>The resulting rectangle is always axis aligned. If a rotation is applied to a node in the
157      * View hierarchy, the result is the axis-aligned bounding box of the visible rectangle.</p>
158      *
159      * @param child A child View, whose rectangular visible region we want to compute
160      * @param r The input rectangle, defined in the child coordinate system. Will be overwritten to
161      * contain the resulting visible rectangle, expressed in global (root) coordinates
162      * @param offset The input coordinates of a point, defined in the child coordinate system.
163      * As with the <code>r</code> parameter, this will be overwritten to contain the global (root)
164      * coordinates of that point.
165      * A <code>null</code> value is valid (in case you are not interested in this result)
166      * @return true if the resulting rectangle is not empty, false otherwise
167      */
getChildVisibleRect(View child, Rect r, android.graphics.Point offset)168     public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset);
169 
170     /**
171      * Find the nearest view in the specified direction that wants to take focus
172      *
173      * @param v The view that currently has focus
174      * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
175      */
focusSearch(View v, int direction)176     public View focusSearch(View v, int direction);
177 
178     /**
179      * Find the nearest keyboard navigation cluster in the specified direction.
180      * This does not actually give focus to that cluster.
181      *
182      * @param currentCluster The starting point of the search. Null means the current cluster is not
183      *                       found yet
184      * @param direction Direction to look
185      *
186      * @return The nearest keyboard navigation cluster in the specified direction, or null if none
187      *         can be found
188      */
keyboardNavigationClusterSearch(View currentCluster, int direction)189     View keyboardNavigationClusterSearch(View currentCluster, int direction);
190 
191     /**
192      * Change the z order of the child so it's on top of all other children.
193      * This ordering change may affect layout, if this container
194      * uses an order-dependent layout scheme (e.g., LinearLayout). Prior
195      * to {@link android.os.Build.VERSION_CODES#KITKAT} this
196      * method should be followed by calls to {@link #requestLayout()} and
197      * {@link View#invalidate()} on this parent to force the parent to redraw
198      * with the new child ordering.
199      *
200      * @param child The child to bring to the top of the z order
201      */
bringChildToFront(View child)202     public void bringChildToFront(View child);
203 
204     /**
205      * Tells the parent that a new focusable view has become available. This is
206      * to handle transitions from the case where there are no focusable views to
207      * the case where the first focusable view appears.
208      *
209      * @param v The view that has become newly focusable
210      */
focusableViewAvailable(View v)211     public void focusableViewAvailable(View v);
212 
213     /**
214      * Shows the context menu for the specified view or its ancestors.
215      * <p>
216      * In most cases, a subclass does not need to override this. However, if
217      * the subclass is added directly to the window manager (for example,
218      * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
219      * then it should override this and show the context menu.
220      *
221      * @param originalView the source view where the context menu was first
222      *                     invoked
223      * @return {@code true} if the context menu was shown, {@code false}
224      *         otherwise
225      * @see #showContextMenuForChild(View, float, float)
226      */
showContextMenuForChild(View originalView)227     public boolean showContextMenuForChild(View originalView);
228 
229     /**
230      * Shows the context menu for the specified view or its ancestors anchored
231      * to the specified view-relative coordinate.
232      * <p>
233      * In most cases, a subclass does not need to override this. However, if
234      * the subclass is added directly to the window manager (for example,
235      * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
236      * then it should override this and show the context menu.
237      * <p>
238      * If a subclass overrides this method it should also override
239      * {@link #showContextMenuForChild(View)}.
240      *
241      * @param originalView the source view where the context menu was first
242      *                     invoked
243      * @param x the X coordinate in pixels relative to the original view to
244      *          which the menu should be anchored, or {@link Float#NaN} to
245      *          disable anchoring
246      * @param y the Y coordinate in pixels relative to the original view to
247      *          which the menu should be anchored, or {@link Float#NaN} to
248      *          disable anchoring
249      * @return {@code true} if the context menu was shown, {@code false}
250      *         otherwise
251      */
showContextMenuForChild(View originalView, float x, float y)252     boolean showContextMenuForChild(View originalView, float x, float y);
253 
254     /**
255      * Have the parent populate the specified context menu if it has anything to
256      * add (and then recurse on its parent).
257      *
258      * @param menu The menu to populate
259      */
createContextMenu(ContextMenu menu)260     public void createContextMenu(ContextMenu menu);
261 
262     /**
263      * Start an action mode for the specified view with the default type
264      * {@link ActionMode#TYPE_PRIMARY}.
265      *
266      * <p>In most cases, a subclass does not need to override this. However, if the
267      * subclass is added directly to the window manager (for example,
268      * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
269      * then it should override this and start the action mode.</p>
270      *
271      * @param originalView The source view where the action mode was first invoked
272      * @param callback The callback that will handle lifecycle events for the action mode
273      * @return The new action mode if it was started, null otherwise
274      *
275      * @see #startActionModeForChild(View, android.view.ActionMode.Callback, int)
276      */
startActionModeForChild(View originalView, ActionMode.Callback callback)277     public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback);
278 
279     /**
280      * Start an action mode of a specific type for the specified view.
281      *
282      * <p>In most cases, a subclass does not need to override this. However, if the
283      * subclass is added directly to the window manager (for example,
284      * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
285      * then it should override this and start the action mode.</p>
286      *
287      * @param originalView The source view where the action mode was first invoked
288      * @param callback The callback that will handle lifecycle events for the action mode
289      * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
290      * @return The new action mode if it was started, null otherwise
291      */
startActionModeForChild( View originalView, ActionMode.Callback callback, int type)292     public ActionMode startActionModeForChild(
293             View originalView, ActionMode.Callback callback, int type);
294 
295     /**
296      * This method is called on the parent when a child's drawable state
297      * has changed.
298      *
299      * @param child The child whose drawable state has changed.
300      */
childDrawableStateChanged(View child)301     public void childDrawableStateChanged(View child);
302 
303     /**
304      * Called when a child does not want this parent and its ancestors to
305      * intercept touch events with
306      * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
307      *
308      * <p>This parent should pass this call onto its parents. This parent must obey
309      * this request for the duration of the touch (that is, only clear the flag
310      * after this parent has received an up or a cancel.</p>
311      *
312      * @param disallowIntercept True if the child does not want the parent to
313      *            intercept touch events.
314      */
requestDisallowInterceptTouchEvent(boolean disallowIntercept)315     public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);
316 
317     /**
318      * Called when a child of this group wants a particular rectangle to be
319      * positioned onto the screen.  {@link ViewGroup}s overriding this can trust
320      * that:
321      * <ul>
322      *   <li>child will be a direct child of this group</li>
323      *   <li>rectangle will be in the child's content coordinates</li>
324      * </ul>
325      *
326      * <p>{@link ViewGroup}s overriding this should uphold the contract:</p>
327      * <ul>
328      *   <li>nothing will change if the rectangle is already visible</li>
329      *   <li>the view port will be scrolled only just enough to make the
330      *       rectangle visible</li>
331      * <ul>
332      *
333      * @param child The direct child making the request.
334      * @param rectangle The rectangle in the child's coordinates the child
335      *        wishes to be on the screen.
336      * @param immediate True to forbid animated or delayed scrolling,
337      *        false otherwise
338      * @return Whether the group scrolled to handle the operation
339      */
requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)340     public boolean requestChildRectangleOnScreen(View child, Rect rectangle,
341             boolean immediate);
342 
343     /**
344      * Called by a child to request from its parent to send an {@link AccessibilityEvent}.
345      * The child has already populated a record for itself in the event and is delegating
346      * to its parent to send the event. The parent can optionally add a record for itself.
347      * <p>
348      * Note: An accessibility event is fired by an individual view which populates the
349      *       event with a record for its state and requests from its parent to perform
350      *       the sending. The parent can optionally add a record for itself before
351      *       dispatching the request to its parent. A parent can also choose not to
352      *       respect the request for sending the event. The accessibility event is sent
353      *       by the topmost view in the view tree.</p>
354      *
355      * @param child The child which requests sending the event.
356      * @param event The event to be sent.
357      * @return True if the event was sent.
358      */
requestSendAccessibilityEvent(View child, AccessibilityEvent event)359     public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event);
360 
361     /**
362      * Called when a child view now has or no longer is tracking transient state.
363      *
364      * <p>"Transient state" is any state that a View might hold that is not expected to
365      * be reflected in the data model that the View currently presents. This state only
366      * affects the presentation to the user within the View itself, such as the current
367      * state of animations in progress or the state of a text selection operation.</p>
368      *
369      * <p>Transient state is useful for hinting to other components of the View system
370      * that a particular view is tracking something complex but encapsulated.
371      * A <code>ListView</code> for example may acknowledge that list item Views
372      * with transient state should be preserved within their position or stable item ID
373      * instead of treating that view as trivially replaceable by the backing adapter.
374      * This allows adapter implementations to be simpler instead of needing to track
375      * the state of item view animations in progress such that they could be restored
376      * in the event of an unexpected recycling and rebinding of attached item views.</p>
377      *
378      * <p>This method is called on a parent view when a child view or a view within
379      * its subtree begins or ends tracking of internal transient state.</p>
380      *
381      * @param child Child view whose state has changed
382      * @param hasTransientState true if this child has transient state
383      */
childHasTransientStateChanged(View child, boolean hasTransientState)384     public void childHasTransientStateChanged(View child, boolean hasTransientState);
385 
386     /**
387      * Ask that a new dispatch of {@link View#fitSystemWindows(Rect)
388      * View.fitSystemWindows(Rect)} be performed.
389      */
requestFitSystemWindows()390     public void requestFitSystemWindows();
391 
392     /**
393      * Gets the parent of a given View for accessibility. Since some Views are not
394      * exposed to the accessibility layer the parent for accessibility is not
395      * necessarily the direct parent of the View, rather it is a predecessor.
396      *
397      * @return The parent or <code>null</code> if no such is found.
398      */
getParentForAccessibility()399     public ViewParent getParentForAccessibility();
400 
401     /**
402      * Notifies a view parent that the accessibility state of one of its
403      * descendants has changed and that the structure of the subtree is
404      * different.
405      * @param child The direct child whose subtree has changed.
406      * @param source The descendant view that changed. May not be {@code null}.
407      * @param changeType A bit mask of the types of changes that occurred. One
408      *            or more of:
409      *            <ul>
410      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
411      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_STATE_DESCRIPTION}
412      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_SUBTREE}
413      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_TEXT}
414      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_UNDEFINED}
415      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_DRAG_STARTED}
416      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_DRAG_CANCELLED}
417      *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_DRAG_DROPPED}
418      *            </ul>
419      */
notifySubtreeAccessibilityStateChanged( View child, @NonNull View source, int changeType)420     public void notifySubtreeAccessibilityStateChanged(
421             View child, @NonNull View source, int changeType);
422 
423     /**
424      * Tells if this view parent can resolve the layout direction.
425      * See {@link View#setLayoutDirection(int)}
426      *
427      * @return True if this view parent can resolve the layout direction.
428      */
canResolveLayoutDirection()429     public boolean canResolveLayoutDirection();
430 
431     /**
432      * Tells if this view parent layout direction is resolved.
433      * See {@link View#setLayoutDirection(int)}
434      *
435      * @return True if this view parent layout direction is resolved.
436      */
isLayoutDirectionResolved()437     public boolean isLayoutDirectionResolved();
438 
439     /**
440      * Return this view parent layout direction. See {@link View#getLayoutDirection()}
441      *
442      * @return {@link View#LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns
443      * {@link View#LAYOUT_DIRECTION_LTR} if the layout direction is not RTL.
444      */
getLayoutDirection()445     public int getLayoutDirection();
446 
447     /**
448      * Tells if this view parent can resolve the text direction.
449      * See {@link View#setTextDirection(int)}
450      *
451      * @return True if this view parent can resolve the text direction.
452      */
canResolveTextDirection()453     public boolean canResolveTextDirection();
454 
455     /**
456      * Tells if this view parent text direction is resolved.
457      * See {@link View#setTextDirection(int)}
458      *
459      * @return True if this view parent text direction is resolved.
460      */
isTextDirectionResolved()461     public boolean isTextDirectionResolved();
462 
463     /**
464      * Return this view parent text direction. See {@link View#getTextDirection()}
465      *
466      * @return the resolved text direction. Returns one of:
467      *
468      * {@link View#TEXT_DIRECTION_FIRST_STRONG}
469      * {@link View#TEXT_DIRECTION_ANY_RTL},
470      * {@link View#TEXT_DIRECTION_LTR},
471      * {@link View#TEXT_DIRECTION_RTL},
472      * {@link View#TEXT_DIRECTION_LOCALE}
473      */
getTextDirection()474     public int getTextDirection();
475 
476     /**
477      * Tells if this view parent can resolve the text alignment.
478      * See {@link View#setTextAlignment(int)}
479      *
480      * @return True if this view parent can resolve the text alignment.
481      */
canResolveTextAlignment()482     public boolean canResolveTextAlignment();
483 
484     /**
485      * Tells if this view parent text alignment is resolved.
486      * See {@link View#setTextAlignment(int)}
487      *
488      * @return True if this view parent text alignment is resolved.
489      */
isTextAlignmentResolved()490     public boolean isTextAlignmentResolved();
491 
492     /**
493      * Return this view parent text alignment. See {@link android.view.View#getTextAlignment()}
494      *
495      * @return the resolved text alignment. Returns one of:
496      *
497      * {@link View#TEXT_ALIGNMENT_GRAVITY},
498      * {@link View#TEXT_ALIGNMENT_CENTER},
499      * {@link View#TEXT_ALIGNMENT_TEXT_START},
500      * {@link View#TEXT_ALIGNMENT_TEXT_END},
501      * {@link View#TEXT_ALIGNMENT_VIEW_START},
502      * {@link View#TEXT_ALIGNMENT_VIEW_END}
503      */
getTextAlignment()504     public int getTextAlignment();
505 
506     /**
507      * React to a descendant view initiating a nestable scroll operation, claiming the
508      * nested scroll operation if appropriate.
509      *
510      * <p>This method will be called in response to a descendant view invoking
511      * {@link View#startNestedScroll(int)}. Each parent up the view hierarchy will be
512      * given an opportunity to respond and claim the nested scrolling operation by returning
513      * <code>true</code>.</p>
514      *
515      * <p>This method may be overridden by ViewParent implementations to indicate when the view
516      * is willing to support a nested scrolling operation that is about to begin. If it returns
517      * true, this ViewParent will become the target view's nested scrolling parent for the duration
518      * of the scroll operation in progress. When the nested scroll is finished this ViewParent
519      * will receive a call to {@link #onStopNestedScroll(View)}.
520      * </p>
521      *
522      * @param child Direct child of this ViewParent containing target
523      * @param target View that initiated the nested scroll
524      * @param nestedScrollAxes Flags consisting of {@link View#SCROLL_AXIS_HORIZONTAL},
525      *                         {@link View#SCROLL_AXIS_VERTICAL} or both
526      * @return true if this ViewParent accepts the nested scroll operation
527      */
onStartNestedScroll(View child, View target, int nestedScrollAxes)528     public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes);
529 
530     /**
531      * React to the successful claiming of a nested scroll operation.
532      *
533      * <p>This method will be called after
534      * {@link #onStartNestedScroll(View, View, int) onStartNestedScroll} returns true. It offers
535      * an opportunity for the view and its superclasses to perform initial configuration
536      * for the nested scroll. Implementations of this method should always call their superclass's
537      * implementation of this method if one is present.</p>
538      *
539      * @param child Direct child of this ViewParent containing target
540      * @param target View that initiated the nested scroll
541      * @param nestedScrollAxes Flags consisting of {@link View#SCROLL_AXIS_HORIZONTAL},
542      *                         {@link View#SCROLL_AXIS_VERTICAL} or both
543      * @see #onStartNestedScroll(View, View, int)
544      * @see #onStopNestedScroll(View)
545      */
onNestedScrollAccepted(View child, View target, int nestedScrollAxes)546     public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes);
547 
548     /**
549      * React to a nested scroll operation ending.
550      *
551      * <p>Perform cleanup after a nested scrolling operation.
552      * This method will be called when a nested scroll stops, for example when a nested touch
553      * scroll ends with a {@link MotionEvent#ACTION_UP} or {@link MotionEvent#ACTION_CANCEL} event.
554      * Implementations of this method should always call their superclass's implementation of this
555      * method if one is present.</p>
556      *
557      * @param target View that initiated the nested scroll
558      */
onStopNestedScroll(View target)559     public void onStopNestedScroll(View target);
560 
561     /**
562      * React to a nested scroll in progress.
563      *
564      * <p>This method will be called when the ViewParent's current nested scrolling child view
565      * dispatches a nested scroll event. To receive calls to this method the ViewParent must have
566      * previously returned <code>true</code> for a call to
567      * {@link #onStartNestedScroll(View, View, int)}.</p>
568      *
569      * <p>Both the consumed and unconsumed portions of the scroll distance are reported to the
570      * ViewParent. An implementation may choose to use the consumed portion to match or chase scroll
571      * position of multiple child elements, for example. The unconsumed portion may be used to
572      * allow continuous dragging of multiple scrolling or draggable elements, such as scrolling
573      * a list within a vertical drawer where the drawer begins dragging once the edge of inner
574      * scrolling content is reached.</p>
575      *
576      * @param target The descendent view controlling the nested scroll
577      * @param dxConsumed Horizontal scroll distance in pixels already consumed by target
578      * @param dyConsumed Vertical scroll distance in pixels already consumed by target
579      * @param dxUnconsumed Horizontal scroll distance in pixels not consumed by target
580      * @param dyUnconsumed Vertical scroll distance in pixels not consumed by target
581      */
onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)582     public void onNestedScroll(View target, int dxConsumed, int dyConsumed,
583             int dxUnconsumed, int dyUnconsumed);
584 
585     /**
586      * React to a nested scroll in progress before the target view consumes a portion of the scroll.
587      *
588      * <p>When working with nested scrolling often the parent view may want an opportunity
589      * to consume the scroll before the nested scrolling child does. An example of this is a
590      * drawer that contains a scrollable list. The user will want to be able to scroll the list
591      * fully into view before the list itself begins scrolling.</p>
592      *
593      * <p><code>onNestedPreScroll</code> is called when a nested scrolling child invokes
594      * {@link View#dispatchNestedPreScroll(int, int, int[], int[])}. The implementation should
595      * report how any pixels of the scroll reported by dx, dy were consumed in the
596      * <code>consumed</code> array. Index 0 corresponds to dx and index 1 corresponds to dy.
597      * This parameter will never be null. Initial values for consumed[0] and consumed[1]
598      * will always be 0.</p>
599      *
600      * @param target View that initiated the nested scroll
601      * @param dx Horizontal scroll distance in pixels
602      * @param dy Vertical scroll distance in pixels
603      * @param consumed Output. The horizontal and vertical scroll distance consumed by this parent
604      */
onNestedPreScroll(View target, int dx, int dy, int[] consumed)605     public void onNestedPreScroll(View target, int dx, int dy, int[] consumed);
606 
607     /**
608      * Request a fling from a nested scroll.
609      *
610      * <p>This method signifies that a nested scrolling child has detected suitable conditions
611      * for a fling. Generally this means that a touch scroll has ended with a
612      * {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds
613      * the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity}
614      * along a scrollable axis.</p>
615      *
616      * <p>If a nested scrolling child view would normally fling but it is at the edge of
617      * its own content, it can use this method to delegate the fling to its nested scrolling
618      * parent instead. The parent may optionally consume the fling or observe a child fling.</p>
619      *
620      * @param target View that initiated the nested scroll
621      * @param velocityX Horizontal velocity in pixels per second
622      * @param velocityY Vertical velocity in pixels per second
623      * @param consumed true if the child consumed the fling, false otherwise
624      * @return true if this parent consumed or otherwise reacted to the fling
625      */
onNestedFling(View target, float velocityX, float velocityY, boolean consumed)626     public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed);
627 
628     /**
629      * React to a nested fling before the target view consumes it.
630      *
631      * <p>This method siginfies that a nested scrolling child has detected a fling with the given
632      * velocity along each axis. Generally this means that a touch scroll has ended with a
633      * {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds
634      * the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity}
635      * along a scrollable axis.</p>
636      *
637      * <p>If a nested scrolling parent is consuming motion as part of a
638      * {@link #onNestedPreScroll(View, int, int, int[]) pre-scroll}, it may be appropriate for
639      * it to also consume the pre-fling to complete that same motion. By returning
640      * <code>true</code> from this method, the parent indicates that the child should not
641      * fling its own internal content as well.</p>
642      *
643      * @param target View that initiated the nested scroll
644      * @param velocityX Horizontal velocity in pixels per second
645      * @param velocityY Vertical velocity in pixels per second
646      * @return true if this parent consumed the fling ahead of the target view
647      */
onNestedPreFling(View target, float velocityX, float velocityY)648     public boolean onNestedPreFling(View target, float velocityX, float velocityY);
649 
650     /**
651      * React to an accessibility action delegated by a target descendant view before the target
652      * processes it.
653      *
654      * <p>This method may be called by a target descendant view if the target wishes to give
655      * a view in its parent chain a chance to react to the event before normal processing occurs.
656      * Most commonly this will be a scroll event such as
657      * {@link android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_FORWARD}.
658      * A ViewParent that supports acting as a nested scrolling parent should override this
659      * method and act accordingly to implement scrolling via accesibility systems.</p>
660      *
661      * @param target The target view dispatching this action
662      * @param action Action being performed; see
663      *               {@link android.view.accessibility.AccessibilityNodeInfo}
664      * @param arguments Optional action arguments
665      * @return true if the action was consumed by this ViewParent
666      */
onNestedPrePerformAccessibilityAction(View target, int action, Bundle arguments)667     public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle arguments);
668 
669     /**
670      * Given a touchable region of a child, this method reduces region by the bounds of all views on
671      * top of the child for which {@link View#canReceivePointerEvents} returns {@code true}. This
672      * applies recursively for all views in the view hierarchy on top of this one.
673      *
674      * @param touchableRegion The touchable region we want to modify.
675      * @param view A child view of this ViewGroup which indicates the z-order of the touchable
676      *             region.
677      * @hide
678      */
subtractObscuredTouchableRegion(Region touchableRegion, View view)679     default void subtractObscuredTouchableRegion(Region touchableRegion, View view) {
680     }
681 
682     /**
683      * Unbuffered dispatch has been requested by a child of this view parent.
684      * This method is called by the View hierarchy to signal ancestors that a View needs to
685      * request unbuffered dispatch.
686      *
687      * @see View#requestUnbufferedDispatch(int)
688      * @hide
689      */
onDescendantUnbufferedRequested()690     default void onDescendantUnbufferedRequested() {
691         if (getParent() != null) {
692             getParent().onDescendantUnbufferedRequested();
693         }
694     }
695 }
696