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:

  1. Obtain the AutofillId of the node. For virtual views, use ContentCaptureSession.newAutofillId(AutofillId,long).
  2. Set the desired properties on an instance of this class (e.g., setText(CharSequence), setBounds(int, int, int, int)).
  3. Pass the ID and this properties instance to ContentCaptureSession.notifyNodeAppearedOrChanged(AutofillId,ContentCaptureNodeProperties).
  4. 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 Rect.

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

ContentCaptureNodeProperties

Added in API level 10000
public ContentCaptureNodeProperties ()

Public methods

clear

Added in API level 10000
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

Added in API level 10000
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

Added in API level 10000
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

Added in API level 10000
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

Added in API level 10000
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

Added in API level 10000
public boolean hasBounds ()

Checks if the bounds have been explicitly set.

Returns
boolean true if the bounds were modified, false otherwise.

hasContentDescription

Added in API level 10000
public boolean hasContentDescription ()

Checks if the content description has been explicitly set.

Returns
boolean true if the content description was modified, false otherwise.

hasParentId

Added in API level 10000
public boolean hasParentId ()

Checks if the parent ID has been explicitly set.

Returns
boolean true if the parent ID was modified, false otherwise.

hasText

Added in API level 10000
public boolean hasText ()

Checks if the text has been explicitly set.

Returns
boolean true if the text was modified, false otherwise.

setBounds

Added in API level 10000
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

Added in API level 10000
public void setContentDescription (CharSequence contentDescription)

Sets the content description for this node.

Parameters
contentDescription CharSequence: The content description to set, or null.

setParentId

Added in API level 10000
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

Added in API level 10000
public void setText (CharSequence text)

Sets the text for this node.

Parameters
text CharSequence: The text to set, or null to remove current text.