ContentCaptureNodeProperties


open class ContentCaptureNodeProperties
kotlin.Any
   ↳ 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

Public methods
open Unit

Clears the entire properties object for reuse.

open Unit
getBounds(outBounds: Rect)

Copies the relative boundaries of this node into the provided Rect.

open CharSequence?

Gets the content description of the node.

open AutofillId?

Gets the parent ID of the node.

open CharSequence?

Gets the text of the node.

open Boolean

Checks if the bounds have been explicitly set.

open Boolean

Checks if the content description has been explicitly set.

open Boolean

Checks if the parent ID has been explicitly set.

open Boolean

Checks if the text has been explicitly set.

open Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)

Sets the boundaries for this node relative to the parent node.

open Unit
setContentDescription(contentDescription: CharSequence?)

Sets the content description for this node.

open Unit
setParentId(parentId: AutofillId?)

Sets the parent ID for this node.

open Unit

Sets the text for this node.

Public constructors

ContentCaptureNodeProperties

ContentCaptureNodeProperties()

Public methods

clear

open fun clear(): Unit

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

open fun getBounds(outBounds: Rect): Unit

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.
Exceptions
java.lang.IllegalStateException if hasBounds() is false.

getContentDescription

open fun getContentDescription(): CharSequence?

Gets the content description of the node.

Return
CharSequence? the content description of the node, or null if explicitly set to null.
Exceptions
java.lang.IllegalStateException if hasContentDescription() is false.

getParentId

open fun getParentId(): AutofillId?

Gets the parent ID of the node.

Return
AutofillId? The parent ID of the node, or null if explicitly set to null.
Exceptions
java.lang.IllegalStateException if hasParentId() is false.

getText

open fun getText(): CharSequence?

Gets the text of the node.

Return
CharSequence? the text of the node, or null if explicitly set to null.
Exceptions
java.lang.IllegalStateException if hasText() is false.

hasBounds

open fun hasBounds(): Boolean

Checks if the bounds have been explicitly set.

Return
Boolean true if the bounds were modified, false otherwise.

hasContentDescription

open fun hasContentDescription(): Boolean

Checks if the content description has been explicitly set.

Return
Boolean true if the content description was modified, false otherwise.

hasParentId

open fun hasParentId(): Boolean

Checks if the parent ID has been explicitly set.

Return
Boolean true if the parent ID was modified, false otherwise.

hasText

open fun hasText(): Boolean

Checks if the text has been explicitly set.

Return
Boolean true if the text was modified, false otherwise.

setBounds

open fun setBounds(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

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

open fun setContentDescription(contentDescription: CharSequence?): Unit

Sets the content description for this node.

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

setParentId

open fun setParentId(parentId: AutofillId?): Unit

Sets the parent ID for this node.

Parameters
parentId AutofillId?: The parent ID to set, or null if the node has no parent.

setText

open fun setText(text: CharSequence?): Unit

Sets the text for this node.

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