ContentCaptureNodeProperties
public
class
ContentCaptureNodeProperties
extends Object
| java.lang.Object | |
| ↳ | android.view.contentcapture.ContentCaptureNodeProperties |
Properties of a Node for Content Capture.
Used to provide changes from a UI node (e.g. a View or a virtual view) to the Content Capture System efficiently. An instance of this class should be reused during view tree traversal to minimize memory allocations.
To use this class:
- Obtain the
AutofillIdof the node. For virtual views, useContentCaptureSession.newAutofillId(AutofillId,long). - Set the desired properties on an instance of this class (e.g.,
setText(CharSequence),setBounds(int, int, int, int)). - Pass the ID and this properties instance to
ContentCaptureSession.notifyNodeAppearedOrChanged(AutofillId,ContentCaptureNodeProperties). - Call
clear()to reset the properties before reusing the instance for the next node.
To track which properties have been modified explicitly this class offers methods like
hasBounds(), hasText() that will return true only if the corresponding
property was explicitly set. Calling clear() removes all set fields and brings back this
class to its initial state to be reused.
Calling a getter method when the corresponding property has not been set (i.e. when
has*() returns false) will throw an IllegalStateException. Callers should
check has*() prior to calling the getter.
Summary
Public constructors | |
|---|---|
ContentCaptureNodeProperties()
|
|
Public methods | |
|---|---|
void
|
clear()
Clears the entire properties object for reuse. |
void
|
getBounds(Rect outBounds)
Copies the relative boundaries of this node into the provided |
CharSequence
|
getContentDescription()
Gets the content description of the node. |
AutofillId
|
getParentId()
Gets the parent ID of the node. |
CharSequence
|
getText()
Gets the text of the node. |
boolean
|
hasBounds()
Checks if the bounds have been explicitly set. |
boolean
|
hasContentDescription()
Checks if the content description has been explicitly set. |
boolean
|
hasParentId()
Checks if the parent ID has been explicitly set. |
boolean
|
hasText()
Checks if the text has been explicitly set. |
void
|
setBounds(int left, int top, int right, int bottom)
Sets the boundaries for this node relative to the parent node. |
void
|
setContentDescription(CharSequence contentDescription)
Sets the content description for this node. |
void
|
setParentId(AutofillId parentId)
Sets the parent ID for this node. |
void
|
setText(CharSequence text)
Sets the text for this node. |
Inherited methods | |
|---|---|
Public constructors
Public methods
clear
public void clear ()
Clears the entire properties object for reuse. This resets all properties to their default unspecified state, meaning all "has*" methods will subsequently return false.
getBounds
public void getBounds (Rect outBounds)
Copies the relative boundaries of this node into the provided Rect.
| Parameters | |
|---|---|
outBounds |
Rect: The mutable Rect to receive the bounds. Must not be null. |
| Throws | |
|---|---|
IllegalStateException |
if hasBounds() is false. |
getContentDescription
public CharSequence getContentDescription ()
Gets the content description of the node.
| Returns | |
|---|---|
CharSequence |
the content description of the node, or null if explicitly set to
null. |
| Throws | |
|---|---|
IllegalStateException |
if hasContentDescription() is false. |
getParentId
public AutofillId getParentId ()
Gets the parent ID of the node.
| Returns | |
|---|---|
AutofillId |
The parent ID of the node, or null if explicitly set to null. |
| Throws | |
|---|---|
IllegalStateException |
if hasParentId() is false. |
getText
public CharSequence getText ()
Gets the text of the node.
| Returns | |
|---|---|
CharSequence |
the text of the node, or null if explicitly set to null. |
| Throws | |
|---|---|
IllegalStateException |
if hasText() is false. |
hasBounds
public boolean hasBounds ()
Checks if the bounds have been explicitly set.
| Returns | |
|---|---|
boolean |
true if the bounds were modified, false otherwise. |
hasContentDescription
public boolean hasContentDescription ()
Checks if the content description has been explicitly set.
| Returns | |
|---|---|
boolean |
true if the content description was modified, false otherwise. |
hasParentId
public boolean hasParentId ()
Checks if the parent ID has been explicitly set.
| Returns | |
|---|---|
boolean |
true if the parent ID was modified, false otherwise. |
hasText
public boolean hasText ()
Checks if the text has been explicitly set.
| Returns | |
|---|---|
boolean |
true if the text was modified, false otherwise. |
setBounds
public void setBounds (int left,
int top,
int right,
int bottom)Sets the boundaries for this node relative to the parent node.
| Parameters | |
|---|---|
left |
int: left bound |
top |
int: top bound |
right |
int: right bound |
bottom |
int: bottom bound |
setContentDescription
public void setContentDescription (CharSequence contentDescription)
Sets the content description for this node.
| Parameters | |
|---|---|
contentDescription |
CharSequence: The content description to set, or null. |
setParentId
public void setParentId (AutofillId parentId)
Sets the parent ID for this node.
| Parameters | |
|---|---|
parentId |
AutofillId: The parent ID to set, or null if the node has no parent. |
setText
public void setText (CharSequence text)
Sets the text for this node.
| Parameters | |
|---|---|
text |
CharSequence: The text to set, or null to remove current text. |