Class ViewRoot
- All Implemented Interfaces:
ViewParent
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Markerfinal Choreographerfinal Handlerprotected final Objectprotected static final intprotected booleanprotected View -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyPointerIcon(int pointerType) protected abstract CanvasbeginDrawLocked(int width, int height) voidbringChildToFront(View child) Change the z order of the child, so it's on top of all other children.voidcancelInvalidate(View view) booleanTells if this view parent can resolve the layout direction.booleanTells if this view parent can resolve the text alignment.booleanTells if this view parent can resolve the text direction.voidchildDrawableStateChanged(View child) This method is called on the parent when a child's drawable state has changed.voidchildHasTransientStateChanged(View child, boolean hasTransientState) Called when a child view now has or no longer is tracking transient state.voidclearChildFocus(View child) Called when a child of this parent is giving up focusvoidcreateContextMenu(ContextMenu menu) Have the parent populate the specified context menu if it has anything to add (and then recurse on its parent).voiddispatchInvalidateDelayed(View view, long delayMilliseconds) voidprotected booleandispatchTouchEvent(MotionEvent event) protected voidprotected abstract voidendDrawLocked(Canvas canvas) voidenqueueInputEvent(InputEvent event) voidTells the parent that a new focusable view has become available.focusSearch(View focused, int direction) Find the nearest view in the specified direction that wants to take focusbooleangetChildVisibleRect(View child, Rect r, Point offset) Compute the visible part of a rectangular region defined in terms of a child view's coordinates.intReturn this view parent layout direction.intReturn the current axes of nested scrolling for this NestedScrollingParent.Returns the parent of this ViewParent.intReturn this view parent text alignment.intReturn this view parent text direction.getView()protected booleanhandleMessage(Message msg) voidinvalidateChild(View child, Rect dirty) All or part of a child is dirty and needs to be redrawn.invalidateChildInParent(int[] location, Rect dirty) All or part of a child is dirty and needs to be redrawn.booleanTells if this view parent layout direction is resolved.booleanIndicates whether layout was requested on this view parent.booleanTells if this view parent text alignment is resolved.booleanTells if this view parent text direction is resolved.static booleanisViewDescendantOf(View child, View parent) Return true if child is an ancestor of parent, (or equal to the parent).keyboardNavigationClusterSearch(View currentCluster, int direction) Find the nearest keyboard navigation cluster in the specified direction.voidloadSystemProperties(BooleanSupplier debugLayoutSupplier) protected voidonKeyEvent(KeyEvent event) booleanonNestedFling(View target, float velocityX, float velocityY, boolean consumed) Request a fling from a nested scroll.booleanonNestedPreFling(View target, float velocityX, float velocityY) React to a nested fling before the target view consumes it.voidonNestedPreScroll(View target, int dx, int dy, int[] consumed, int type) React to a nested scroll in progress before the target view consumes a portion of the scroll.voidonNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, int[] consumed) React to a nested scroll in progress.voidonNestedScrollAccepted(View child, View target, int axes, int type) React to the successful claiming of a nested scroll operation.booleanonStartNestedScroll(View child, View target, int axes, int type) React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.voidonStopNestedScroll(View target, int type) React to a nested scroll operation ending.protected voidonTouchEvent(MotionEvent event) booleanperformHapticFeedback(int effectId, boolean always) voidplaySoundEffect(int effectId) voidrequestChildFocus(View child, View focused) Called when a child of this parent wants focusbooleanrequestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) Called when a child of this group wants a particular rectangle to be positioned onto the screen.voidrequestDisallowInterceptTouchEvent(boolean disallowIntercept) Called when a child does not want this parent and its ancestors to intercept touch events withViewGroup.onInterceptTouchEvent(MotionEvent).voidRequest layout all views with layout mark in layout passvoidrequestTransitionStart(LayoutTransition transition) Add LayoutTransition to the list of transitions to be started in the next traversal.protected voidvoidsetFrame(int width, int height) voidbooleanshowContextMenuForChild(View originalView, float x, float y) Shows the context menu for the specified view or its ancestors anchored to the specified view-relative coordinate.startActionModeForChild(View originalView, ActionMode.Callback callback, int type) Start an action mode of a specific type for the specified view.protected void
-
Field Details
-
MARKER
protected static final org.slf4j.Marker MARKER -
MSG_PROCESS_INPUT_EVENTS
protected static final int MSG_PROCESS_INPUT_EVENTS- See Also:
-
mTraversalScheduled
protected boolean mTraversalScheduled -
mRenderLock
-
mView
-
mHandler
-
mChoreographer
-
-
Constructor Details
-
ViewRoot
protected ViewRoot()
-
-
Method Details
-
handleMessage
-
setView
-
setFrame
public void setFrame(int width, int height) -
getView
-
requestChildRectangleOnScreen
Description copied from interface:ViewParentCalled when a child of this group wants a particular rectangle to be positioned onto the screen.ViewGroups overriding this can trust that:- child will be a direct child of this group
- rectangle will be in the child's content coordinates
ViewGroups overriding this should uphold the contract:- nothing will change if the rectangle is already visible
- the view port will be scrolled only just enough to make the rectangle visible
- Specified by:
requestChildRectangleOnScreenin interfaceViewParent- Parameters:
child- The direct child making the request.rectangle- The rectangle in the child's coordinates the child wishes to be on the screen.immediate- True to forbid animated or delayed scrolling, false otherwise- Returns:
- Whether the group scrolled to handle the operation
-
scheduleTraversals
-
unscheduleTraversals
-
doTraversal
-
beginDrawLocked
-
endDrawLocked
-
enqueueInputEvent
-
dispatchTouchEvent
-
onTouchEvent
-
onKeyEvent
-
loadSystemProperties
-
invalidateChild
Description copied from interface:ViewParentAll or part of a child is dirty and needs to be redrawn.- Specified by:
invalidateChildin interfaceViewParent- Parameters:
child- The child which is dirtydirty- The area within the child that is invalid
-
invalidateChildInParent
Description copied from interface:ViewParentAll or part of a child is dirty and needs to be redrawn.The location array is an array of two int values which respectively define the left and the top position of the dirty child.
This method must return the parent of this ViewParent if the specified rectangle must be invalidated in the parent. If the specified rectangle does not require invalidation in the parent or if the parent does not exist, this method must return null.
When this method returns a non-null value, the location array must have been updated with the left and top coordinates of this ViewParent.
- Specified by:
invalidateChildInParentin interfaceViewParent- Parameters:
location- An array of 2 ints containing the left and top coordinates of the child to invalidatedirty- The area within the child that is invalid- Returns:
- the parent of this ViewParent or null
-
dispatchInvalidateDelayed
-
dispatchInvalidateOnAnimation
-
cancelInvalidate
-
applyPointerIcon
protected void applyPointerIcon(int pointerType) -
isViewDescendantOf
Return true if child is an ancestor of parent, (or equal to the parent). -
getParent
Description copied from interface:ViewParentReturns the parent of this ViewParent.- Specified by:
getParentin interfaceViewParent- Returns:
- the parent or
nullif the parent is not available
-
getChildVisibleRect
Description copied from interface:ViewParentCompute the visible part of a rectangular region defined in terms of a child view's coordinates.Returns the clipped visible part of the rectangle
r, defined in thechild's local coordinate system.ris modified by this method to contain the result, expressed in the global (root) coordinate system.The resulting rectangle is always axis aligned. If a rotation is applied to a node in the View hierarchy, the result is the axis-aligned bounding box of the visible rectangle.
- Specified by:
getChildVisibleRectin interfaceViewParent- Parameters:
child- A child View, whose rectangular visible region we want to computer- The input rectangle, defined in the child coordinate system. Will be overwritten to contain the resulting visible rectangle, expressed in global (root) coordinatesoffset- The input coordinates of a point, defined in the child coordinate system. As with therparameter, this will be overwritten to contain the global (root) coordinates of that point. Anullvalue is valid (in case you are not interested in this result)- Returns:
- true if the resulting rectangle is not empty, false otherwise
-
requestLayout
public void requestLayout()Request layout all views with layout mark in layout pass- Specified by:
requestLayoutin interfaceViewParent- See Also:
-
isLayoutRequested
public boolean isLayoutRequested()Description copied from interface:ViewParentIndicates whether layout was requested on this view parent.- Specified by:
isLayoutRequestedin interfaceViewParent- Returns:
- true if layout was requested, false otherwise
-
requestChildFocus
Description copied from interface:ViewParentCalled when a child of this parent wants focus- Specified by:
requestChildFocusin interfaceViewParent- Parameters:
child- The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus.focused- The view that is a descendant of child that actually has focus
-
clearChildFocus
Description copied from interface:ViewParentCalled when a child of this parent is giving up focus- Specified by:
clearChildFocusin interfaceViewParent- Parameters:
child- The view that is giving up focus
-
focusSearch
Find the nearest view in the specified direction that wants to take focus- Specified by:
focusSearchin interfaceViewParent- Parameters:
focused- The view that currently has focusdirection- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
-
childHasTransientStateChanged
Description copied from interface:ViewParentCalled when a child view now has or no longer is tracking transient state."Transient state" is any state that a View might hold that is not expected to be reflected in the data model that the View currently presents. This state only affects the presentation to the user within the View itself, such as the current state of animations in progress or the state of a text selection operation.
Transient state is useful for hinting to other components of the View system that a particular view is tracking something complex but encapsulated. A
ListViewfor example may acknowledge that list item Views with transient state should be preserved within their position or stable item ID instead of treating that view as trivially replaceable by the backing adapter. This allows adapter implementations to be simpler instead of needing to track the state of item view animations in progress such that they could be restored in the event of an unexpected recycling and rebinding of attached item views.This method is called on a parent view when a child view or a view within its subtree begins or ends tracking of internal transient state.
- Specified by:
childHasTransientStateChangedin interfaceViewParent- Parameters:
child- Child view whose state has changedhasTransientState- true if this child has transient state
-
bringChildToFront
Description copied from interface:ViewParentChange the z order of the child, so it's on top of all other children. This ordering change may affect layout, if this container uses an order-dependent layout scheme (e.g., LinearLayout).- Specified by:
bringChildToFrontin interfaceViewParent- Parameters:
child- The child to bring to the top of the z order
-
focusableViewAvailable
Description copied from interface:ViewParentTells the parent that a new focusable view has become available. This is to handle transitions from the case where there are no focusable views to the case where the first focusable view appears.- Specified by:
focusableViewAvailablein interfaceViewParent- Parameters:
v- The view that has become newly focusable
-
canResolveLayoutDirection
public boolean canResolveLayoutDirection()Description copied from interface:ViewParentTells if this view parent can resolve the layout direction. SeeView.setLayoutDirection(int)- Specified by:
canResolveLayoutDirectionin interfaceViewParent- Returns:
- True if this view parent can resolve the layout direction.
-
isLayoutDirectionResolved
public boolean isLayoutDirectionResolved()Description copied from interface:ViewParentTells if this view parent layout direction is resolved. SeeView.setLayoutDirection(int)- Specified by:
isLayoutDirectionResolvedin interfaceViewParent- Returns:
- True if this view parent layout direction is resolved.
-
getLayoutDirection
public int getLayoutDirection()Description copied from interface:ViewParentReturn this view parent layout direction. SeeView.getLayoutDirection()- Specified by:
getLayoutDirectionin interfaceViewParent- Returns:
View.LAYOUT_DIRECTION_RTLif the layout direction is RTL or returnsView.LAYOUT_DIRECTION_LTRif the layout direction is not RTL.
-
canResolveTextDirection
public boolean canResolveTextDirection()Description copied from interface:ViewParentTells if this view parent can resolve the text direction. SeeView.setTextDirection(int)- Specified by:
canResolveTextDirectionin interfaceViewParent- Returns:
- True if this view parent can resolve the text direction.
-
isTextDirectionResolved
public boolean isTextDirectionResolved()Description copied from interface:ViewParentTells if this view parent text direction is resolved. SeeView.setTextDirection(int)- Specified by:
isTextDirectionResolvedin interfaceViewParent- Returns:
- True if this view parent text direction is resolved.
-
getTextDirection
public int getTextDirection()Description copied from interface:ViewParentReturn this view parent text direction. SeeView.getTextDirection()- Specified by:
getTextDirectionin interfaceViewParent- Returns:
- the resolved text direction. Returns one of:
View.TEXT_DIRECTION_FIRST_STRONGView.TEXT_DIRECTION_ANY_RTL,View.TEXT_DIRECTION_LTR,View.TEXT_DIRECTION_RTL,View.TEXT_DIRECTION_LOCALE
-
canResolveTextAlignment
public boolean canResolveTextAlignment()Description copied from interface:ViewParentTells if this view parent can resolve the text alignment. SeeView.setTextAlignment(int)- Specified by:
canResolveTextAlignmentin interfaceViewParent- Returns:
- True if this view parent can resolve the text alignment.
-
isTextAlignmentResolved
public boolean isTextAlignmentResolved()Description copied from interface:ViewParentTells if this view parent text alignment is resolved. SeeView.setTextAlignment(int)- Specified by:
isTextAlignmentResolvedin interfaceViewParent- Returns:
- True if this view parent text alignment is resolved.
-
getTextAlignment
public int getTextAlignment()Description copied from interface:ViewParentReturn this view parent text alignment. SeeView.getTextAlignment()- Specified by:
getTextAlignmentin interfaceViewParent- Returns:
- the resolved text alignment. Returns one of:
View.TEXT_ALIGNMENT_GRAVITY,View.TEXT_ALIGNMENT_CENTER,View.TEXT_ALIGNMENT_TEXT_START,View.TEXT_ALIGNMENT_TEXT_END,View.TEXT_ALIGNMENT_VIEW_START,View.TEXT_ALIGNMENT_VIEW_END
-
showContextMenuForChild
Description copied from interface:ViewParentShows the context menu for the specified view or its ancestors anchored to the specified view-relative coordinate.In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example,
ViewManager.addView(View, ViewGroup.LayoutParams)) then it should override this and show the context menu.- Specified by:
showContextMenuForChildin interfaceViewParent- Parameters:
originalView- the source view where the context menu was first invokedx- the X coordinate in pixels relative to the original view to which the menu should be anchored, orFloat.NaNto disable anchoringy- the Y coordinate in pixels relative to the original view to which the menu should be anchored, orFloat.NaNto disable anchoring- Returns:
trueif the context menu was shown,falseotherwise
-
startActionModeForChild
public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, int type) Description copied from interface:ViewParentStart an action mode of a specific type for the specified view.In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example,
ViewManager.addView(View, ViewGroup.LayoutParams)) then it should override this and start the action mode.- Specified by:
startActionModeForChildin interfaceViewParent- Parameters:
originalView- The source view where the action mode was first invokedcallback- The callback that will handle lifecycle events for the action modetype- One ofActionMode.TYPE_PRIMARYorActionMode.TYPE_FLOATING.- Returns:
- The new action mode if it was started, null otherwise
-
createContextMenu
Description copied from interface:ViewParentHave the parent populate the specified context menu if it has anything to add (and then recurse on its parent).- Specified by:
createContextMenuin interfaceViewParent- Parameters:
menu- The menu to populate
-
childDrawableStateChanged
Description copied from interface:ViewParentThis method is called on the parent when a child's drawable state has changed.- Specified by:
childDrawableStateChangedin interfaceViewParent- Parameters:
child- The child whose drawable state has changed.
-
requestDisallowInterceptTouchEvent
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) Description copied from interface:ViewParentCalled when a child does not want this parent and its ancestors to intercept touch events withViewGroup.onInterceptTouchEvent(MotionEvent).This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
- Specified by:
requestDisallowInterceptTouchEventin interfaceViewParent- Parameters:
disallowIntercept- True if the child does not want the parent to intercept touch events.
-
onStartNestedScroll
Description copied from interface:ViewParentReact to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.This method will be called in response to a descendant view invoking
View.startNestedScroll(int, int). Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returningtrue.This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to
ViewParent.onStopNestedScroll(View, int).- Specified by:
onStartNestedScrollin interfaceViewParent- Parameters:
child- Direct child of this ViewParent containing targettarget- View that initiated the nested scrollaxes- Flags consisting ofView.SCROLL_AXIS_HORIZONTAL,View.SCROLL_AXIS_VERTICALor bothtype- the type of input which cause this scroll event- Returns:
- true if this ViewParent accepts the nested scroll operation
-
onNestedScrollAccepted
Description copied from interface:ViewParentReact to the successful claiming of a nested scroll operation.This method will be called after
onStartNestedScrollreturns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclasses' implementation of this method if one is present.- Specified by:
onNestedScrollAcceptedin interfaceViewParent- Parameters:
child- Direct child of this ViewParent containing targettarget- View that initiated the nested scrollaxes- Flags consisting ofView.SCROLL_AXIS_HORIZONTAL,View.SCROLL_AXIS_VERTICALor bothtype- the type of input which cause this scroll event- See Also:
-
onStopNestedScroll
Description copied from interface:ViewParentReact to a nested scroll operation ending.Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a
MotionEvent.ACTION_UPorMotionEvent.ACTION_CANCELevent. Implementations of this method should always call their superclasses' implementation of this method if one is present.- Specified by:
onStopNestedScrollin interfaceViewParent- Parameters:
target- View that initiated the nested scrolltype- the type of input which cause this scroll event
-
onNestedScroll
public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, @NonNull int[] consumed) Description copied from interface:ViewParentReact to a nested scroll in progress.This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned
truefor a call toViewParent.onStartNestedScroll(View, View, int, int).Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
This method is called when a nested scrolling child invokes
View.dispatchNestedScroll(int, int, int, int, int[], int, int[])} or one of methods it overloads.An implementation must report how many pixels of the x and y scroll distances were consumed by this nested scrolling parent by adding the consumed distances to the
consumedparameter.consumedshould also be passed up to it's nested scrolling parent so that the parent may also add any scroll distance it consumes. Index 0 corresponds to dx and index 1 corresponds to dy.- Specified by:
onNestedScrollin interfaceViewParent- Parameters:
target- The descendant view controlling the nested scrolldxConsumed- Horizontal scroll distance in pixels already consumed by targetdyConsumed- Vertical scroll distance in pixels already consumed by targetdxUnconsumed- Horizontal scroll distance in pixels not consumed by targetdyUnconsumed- Vertical scroll distance in pixels not consumed by targettype- the type of input which cause this scroll eventconsumed- Output. Upon this method returning, will contain the scroll distances consumed by this nested scrolling parent and the scroll distances consumed by any other parent up the view hierarchy- See Also:
-
onNestedPreScroll
public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) Description copied from interface:ViewParentReact to a nested scroll in progress before the target view consumes a portion of the scroll.When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.
onNestedPreScrollis called when a nested scrolling child invokesView.dispatchNestedPreScroll(int, int, int[], int[], int). The implementation should report how any pixels of the scroll reported by dx, dy were consumed in theconsumedarray. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.- Specified by:
onNestedPreScrollin interfaceViewParent- Parameters:
target- View that initiated the nested scrolldx- Horizontal scroll distance in pixelsdy- Vertical scroll distance in pixelsconsumed- Output. The horizontal and vertical scroll distance consumed by this parenttype- the type of input which cause this scroll event
-
onNestedFling
public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) Description copied from interface:ViewParentRequest a fling from a nested scroll.This method signifies that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a
velocityin the direction of scrolling that meets or exceeds theminimum fling velocityalong a scrollable axis.If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.
- Specified by:
onNestedFlingin interfaceViewParent- Parameters:
target- View that initiated the nested scrollvelocityX- Horizontal velocity in pixels per secondvelocityY- Vertical velocity in pixels per secondconsumed- true if the child consumed the fling, false otherwise- Returns:
- true if this parent consumed or otherwise reacted to the fling
-
onNestedPreFling
Description copied from interface:ViewParentReact to a nested fling before the target view consumes it.This method signifies that a nested scrolling child has detected a fling with the given velocity along each axis. Generally this means that a touch scroll has ended with a
velocityin the direction of scrolling that meets or exceeds theminimum fling velocityalong a scrollable axis.If a nested scrolling parent is consuming motion as part of a
pre-scroll, it may be appropriate for it to also consume the pre-fling to complete that same motion. By returningtruefrom this method, the parent indicates that the child should not fling its own internal content as well.- Specified by:
onNestedPreFlingin interfaceViewParent- Parameters:
target- View that initiated the nested scrollvelocityX- Horizontal velocity in pixels per secondvelocityY- Vertical velocity in pixels per second- Returns:
- true if this parent consumed the fling ahead of the target view
-
getNestedScrollAxes
public int getNestedScrollAxes()Description copied from interface:ViewParentReturn the current axes of nested scrolling for this NestedScrollingParent.A NestedScrollingParent returning something other than
View.SCROLL_AXIS_NONEis currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.- Specified by:
getNestedScrollAxesin interfaceViewParent- Returns:
- Flags indicating the current axes of nested scrolling
- See Also:
-
requestTransitionStart
Add LayoutTransition to the list of transitions to be started in the next traversal. This list will be cleared after the transitions on the list are start()'ed. These transitionsa re added by LayoutTransition itself when it sets up animations. The setup happens during the layout phase of traversal, which we want to complete before any of the animations are started (because those animations may side-effect properties that layout depends upon, like the bounding rectangles of the affected views). So we add the transition to the list and it is started just prior to starting the drawing phase of traversal.- Parameters:
transition- The LayoutTransition to be started on the next traversal.
-
playSoundEffect
void playSoundEffect(int effectId) -
performHapticFeedback
boolean performHapticFeedback(int effectId, boolean always)
-