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