public class ByWindowSelector


A ByWindowSelector specifies criteria for matching UI windows during a call to findWindow.

Summary

Public methods

@NonNull ByWindowSelector
active(boolean isActive)

Sets the search criteria to match windows that are active or inactive.

@NonNull ByWindowSelector
@RequiresApi(value = 30)
displayId(int displayId)

Adds a display ID selector criteria for matching.

@NonNull ByWindowSelector
focused(boolean isFocused)

Sets the search criteria to match windows that are focused or not.

@NonNull ByWindowSelector
id(int id)

Sets the id criteria for matching.

@NonNull ByWindowSelector
layer(@IntRange(from = 0) int exactLayer)

Sets the layer (Z-order) criteria for matching.

@NonNull ByWindowSelector
layerAbove(@IntRange(from = 0) int referenceLayer)

Sets the layer (Z-order) criteria for finding windows that are layered above the specified reference layer.

@NonNull ByWindowSelector
layerBelow(@IntRange(from = 1) int referenceLayer)

Sets the layer (Z-order) criteria for finding windows that are layered below the specified reference layer.

@NonNull ByWindowSelector
pkg(@NonNull Pattern packageName)

Sets the package name criteria for window matching.

@NonNull ByWindowSelector
pkg(@NonNull String packageName)

Sets the package name criteria for window matching.

@NonNull ByWindowSelector

Sets the title criteria for matching.

@NonNull ByWindowSelector

Sets the title criteria for matching.

@NonNull ByWindowSelector

Sets the title criteria for matching.

@NonNull ByWindowSelector

Sets the title criteria for matching.

@NonNull ByWindowSelector

Sets the title criteria for matching.

@NonNull String

Returns a String representation of this ByWindowSelector.

@NonNull ByWindowSelector
type(int type)

Sets the type criteria for window matching.

Public methods

active

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector active(boolean isActive)

Sets the search criteria to match windows that are active or inactive.

Parameters
boolean isActive

Whether to match windows that are active or inactive.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

displayId

Added in 2.4.0-alpha06
@RequiresApi(value = 30)
public @NonNull ByWindowSelector displayId(int displayId)

Adds a display ID selector criteria for matching. A UI element will be considered a match if it is within the display with the ID of displayId and all other criteria for this selector are met.

Parameters
int displayId

The display ID to match. Use Display#getDisplayId() to get the ID.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

focused

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector focused(boolean isFocused)

Sets the search criteria to match windows that are focused or not.

Parameters
boolean isFocused

Whether to match windows that are focused or not.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

id

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector id(int id)

Sets the id criteria for matching. A UI window will be considered a match if its id matches the id parameter and all other criteria for this selector are met.

Parameters
int id

The id to match.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

layer

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector layer(@IntRange(from = 0) int exactLayer)

Sets the layer (Z-order) criteria for matching. A UI window will be considered a match if its layer matches the layer parameter and all other criteria for this selector are met.

Parameters
@IntRange(from = 0) int exactLayer

The layer to match.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

layerAbove

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector layerAbove(@IntRange(from = 0) int referenceLayer)

Sets the layer (Z-order) criteria for finding windows that are layered above the specified reference layer.

Parameters
@IntRange(from = 0) int referenceLayer

The layer which matching windows must be above.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

layerBelow

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector layerBelow(@IntRange(from = 1) int referenceLayer)

Sets the layer (Z-order) criteria for finding windows that are layered below the specified reference layer.

Parameters
@IntRange(from = 1) int referenceLayer

The layer which matching windows must be below. must be positive.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

pkg

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector pkg(@NonNull Pattern packageName)

Sets the package name criteria for window matching. A UI window will be considered a match if its package name exactly matches the packageName and all other criteria for this selector are met.

Parameters
@NonNull Pattern packageName

The Pattern to be used for window matching.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

pkg

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector pkg(@NonNull String packageName)

Sets the package name criteria for window matching. A UI window will be considered a match if its package name exactly matches the packageName and all other criteria for this selector are met.

Parameters
@NonNull String packageName

The exact package name to match (case-sensitive). e.g. "com.example .android"

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

title

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector title(@NonNull Pattern title)

Sets the title criteria for matching. A UI window will be considered a match if its title matches the titlePattern and all other criteria for this selector are met.

Parameters
@NonNull Pattern title

The Pattern to be used for window matching.

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

title

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector title(@NonNull String title)

Sets the title criteria for matching. A UI window will be considered a match if its title exactly matches the title parameter and all other criteria for this selector are met.

Parameters
@NonNull String title

The exact value to match (case-sensitive).

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

titleContains

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector titleContains(@NonNull String substring)

Sets the title criteria for matching. A UI window will be considered a match if its title contains the substring and all other criteria for this selector are met.

Parameters
@NonNull String substring

The substring to match (case-sensitive).

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

titleEndsWith

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector titleEndsWith(@NonNull String suffix)

Sets the title criteria for matching. A UI window will be considered a match if its title ends with the suffix and all other criteria for this selector are met.

Parameters
@NonNull String suffix

The suffix to match (case-sensitive).

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

titleStartsWith

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector titleStartsWith(@NonNull String prefix)

Sets the title criteria for matching. A UI window will be considered a match if its title starts with the prefix and all other criteria for this selector are met.

Parameters
@NonNull String prefix

The prefix to match (case-sensitive).

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.

toString

public @NonNull String toString()

Returns a String representation of this ByWindowSelector. The format is "ByWindowSelector [='', ... ]". Each criteria is listed as a key-value pair where the key is the name of the criteria expressed in all caps (e.g. TYPE, TITLE, etc).

type

Added in 2.4.0-alpha06
public @NonNull ByWindowSelector type(int type)

Sets the type criteria for window matching. A UI window will be considered a match if its type exactly matches the type and all other criteria for this selector are met.

Parameters
int type

The exact type to match (e.g. TYPE_APPLICATION).

Returns
@NonNull ByWindowSelector

A reference to this ByWindowSelector.